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

PAM: Warn about issue with systemd-user service #13025

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions contrib/pam_zfs_key/pam_zfs_key.c
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,35 @@ zfs_key_config_modify_session_counter(pam_handle_t *pamh,
return (counter_value);
}

/*
* This module only works if every opened session is later closed. There are
* known and common service(s) which violate this norm; warn if they are
* detected.
*
* Specifically, these <services> include "systemd-user".
*
* Workaround:
* session [success=1 default=ignore] pam_succeed_if.so service in <services>
* session optional pam_zfs_key.so
*/
static int
session_roundtrip_check(pam_handle_t *pamh)
{
const char *service;
int ret = pam_get_item(pamh, PAM_SERVICE, (const void **)&service);
if (ret != PAM_SUCCESS) {
pam_syslog(pamh, LOG_NOTICE, "Unable to identify PAM service");
return (-1);
}
if (strcmp("systemd-user", service) == 0) {
pam_syslog(pamh, LOG_WARNING,
"Key may not be unloaded because of "
"https://github.com/systemd/systemd/issues/8598");
return (1);
}
return (0);
}

__attribute__((visibility("default")))
PAM_EXTERN int
pam_sm_authenticate(pam_handle_t *pamh, int flags,
Expand Down Expand Up @@ -749,6 +778,7 @@ pam_sm_open_session(pam_handle_t *pamh, int flags,
"Cannot zfs_mount when not being root.");
return (PAM_SUCCESS);
}
(void) session_roundtrip_check(pamh);
Copy link
Contributor

@nabijaczleweli nabijaczleweli Mar 8, 2022

Choose a reason for hiding this comment

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

What's the point of returning a tristate if the only user just void-casts it? The documentation says warn, and it just warns, so why not just warn?

static void
session_roundtrip_warn(pam_handle_t *pamh)
{
	const char *service;
	if (pam_get_item(pamh, PAM_SERVICE, (const void **)&service)
	    != PAM_SUCCESS)
		pam_syslog(pamh, LOG_NOTICE, "Unable to identify PAM service");
	else if (strcmp("systemd-user", service) == 0)
		pam_syslog(pamh, LOG_WARNING,
		    "Key may not be unloaded because of "
		    "https://github.com/systemd/systemd/issues/8598");
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I hoped to build on this change and add functionality based around the return value. However, I think those changes could generate a more vibrant discussion. Since this function provides value even in isolation, I decided to submit it separately.

Regardless, it doesn't seem to matter; both forms compile to the same binary on my system.

zfs_key_config_t config;
zfs_key_config_load(pamh, &config, argc, argv);
if (config.uid < 1000) {
Expand Down