Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shut down forked PAM handle #520

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

Xyene
Copy link

@Xyene Xyene commented Sep 28, 2024

Shutting down the forked PAM handle must be done as per the Linux-PAM documentation, specifically after setuid.

https://fossies.org/linux/Linux-PAM-docs/doc/adg/html/adg-interface-by-app-expected.html#adg-pam_end

This is not a new requirement, but until recently (~2021) there was no consequence to not doing so.

pam_cap now requires the handle to be shut down correctly in order to configure ambient capabilities for the session. Importantly, these must be configured after setuid, as setuid clears the ambient capability vector.

See this comment (and thread) for more details: shadow-maint/shadow#408 (comment)

@Xyene Xyene force-pushed the pam-cleanup branch 2 times, most recently from e79ed86 to 2975c2a Compare September 29, 2024 01:31

#ifdef PAM_DATA_SILENT
/* macOS PAM doesn't support PAM_DATA_SILENT. */
pam_end(sshpam_handle, PAM_SUCCESS | PAM_DATA_SILENT);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pam_end(sshpam_handle, PAM_SUCCESS | PAM_DATA_SILENT);
pam_end(sshpam_handle, sshpam_err | PAM_DATA_SILENT);

Shouldn't be still be ended even outside pam-linux?

Copy link
Author

@Xyene Xyene Sep 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure it's safe to do so without PAM_DATA_SILENT, otherwise pam_end may result in modules in the forked child trying to perform cleanup work meant for the parent (deleting directories, logging, etc.)

A real example, from the pam_krb5 module: shadow-maint/shadow#408 (comment) / rra/pam-krb5#21

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the forked process is going to be run, I would expect sshpam_err to always be PAM_SUCCESS. When one of the pam_authenticate() etc calls fail to return PAM_SUCCESS, I would have expected this fork to not have happened.

+1 to @Xyene - this does not change the need for the parent to call pam_end(sshpam_err) and that call should not have PAM_DATA_SILENT or'd in.

@Xyene Xyene force-pushed the pam-cleanup branch 3 times, most recently from 0825cd0 to 07bd8b8 Compare November 19, 2024 18:39
Shutting down the forked PAM handle must be done as per the Linux-PAM
documentation, specifically after setuid.

This is not a new requirement, but until recently (~2021) there was no
consequence to not doing so.

`pam_cap` now requires the handle to be shut down correctly in order to
configure ambient capabilities for the session. Importantly, these must
be configured after setuid, as setuid clears the ambient capability
vector.

Signed-off-by: Tudor Brindus <[email protected]>
@Xyene
Copy link
Author

Xyene commented Nov 19, 2024

I moved the cleanup to after do_setup_env, since its original position before broke pam_env.so setting environment variables.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants