Summary: | Please use sd_uid_get_state() to make security decisions, not sd_pid_get_session() | ||
---|---|---|---|
Product: | PolicyKit | Reporter: | Lennart Poettering <lennart> |
Component: | daemon | Assignee: | David Zeuthen (not reading bugmail) <zeuthen> |
Status: | RESOLVED FIXED | QA Contact: | David Zeuthen (not reading bugmail) <zeuthen> |
Severity: | normal | ||
Priority: | medium | CC: | bugzilla, walters |
Version: | unspecified | ||
Hardware: | Other | ||
OS: | All | ||
Whiteboard: | |||
i915 platform: | i915 features: | ||
Attachments: |
sessionmonitor-systemd: Use sd_uid_get_state() to check session activity
sessionmonitor-systemd: Use sd_uid_get_state() to check session activity |
Description
Lennart Poettering
2014-03-19 13:50:14 UTC
This is still a nice-to-have after https://bugs.freedesktop.org/show_bug.cgi?id=78905 right? But not strictly necessary since we're falling back to looking at the primary session? See also Bug #67728. Created attachment 116248 [details] [review] sessionmonitor-systemd: Use sd_uid_get_state() to check session activity Instead of using sd_pid_get_session() then sd_session_is_active() to determine whether the user is active, use sd_uid_get_state() directly. This gets the maximum of the states of all the user’s sessions, rather than the state of the session containing the subject process. Since the user is the security boundary, this is fine. This change is necessary for `systemd --user` sessions, where most user code will be forked off user@.service, rather than running inside the logind session (whether that be a foreground/active or background/online session). Policy-wise, the change is from checking whether the subject process is in an active session; to checking whether the subject process is owned by a user with at least one active session. Comment on attachment 116248 [details] [review] sessionmonitor-systemd: Use sd_uid_get_state() to check session activity Review of attachment 116248 [details] [review]: ----------------------------------------------------------------- Two minor things. Want to trade for review of http://lists.freedesktop.org/archives/polkit-devel/2015-May/000421.html ? I can file as a bug if it's easier. ::: src/polkitbackend/polkitbackendsessionmonitor-systemd.c @@ +399,5 @@ > + g_debug ("Checking whether session %s is active.", session_id); > + > + /* Check whether *any* of the user's current sessions are active. */ > + if (sd_session_get_uid (session_id, &uid) < 0) > + goto fallback; polkit is GNU, 2 space indents please. @@ +404,5 @@ > + > + g_debug ("Session %s has UID %u.", session_id, uid); > + > + if (sd_uid_get_state (uid, &state) < 0) > + goto fallback; In this case we leak `state` Created attachment 116266 [details] [review] sessionmonitor-systemd: Use sd_uid_get_state() to check session activity Instead of using sd_pid_get_session() then sd_session_is_active() to determine whether the user is active, use sd_uid_get_state() directly. This gets the maximum of the states of all the user’s sessions, rather than the state of the session containing the subject process. Since the user is the security boundary, this is fine. This change is necessary for `systemd --user` sessions, where most user code will be forked off user@.service, rather than running inside the logind session (whether that be a foreground/active or background/online session). Policy-wise, the change is from checking whether the subject process is in an active session; to checking whether the subject process is owned by a user with at least one active session. --- Updated patch to fix the style issue. > @@ +404,5 @@ > > + > > + g_debug ("Session %s has UID %u.", session_id, uid); > > + > > + if (sd_uid_get_state (uid, &state) < 0) > > + goto fallback; > > In this case we leak `state` Nope, sd_uid_get_state() does not return a state on failure (returning < 0). |
Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.