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)

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 <me@tbrindus.ca>

#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.

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