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

(RHEL-28048) pam: add call to pam_umask #435

Merged
merged 2 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
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
9 changes: 7 additions & 2 deletions man/systemd.exec.xml
Original file line number Diff line number Diff line change
Expand Up @@ -590,8 +590,13 @@ CapabilityBoundingSet=~CAP_B CAP_C</programlisting>
<term><varname>UMask=</varname></term>

<listitem><para>Controls the file mode creation mask. Takes an access mode in octal notation. See
<citerefentry><refentrytitle>umask</refentrytitle><manvolnum>2</manvolnum></citerefentry> for details. Defaults
to 0022.</para></listitem>
<citerefentry><refentrytitle>umask</refentrytitle><manvolnum>2</manvolnum></citerefentry> for
details. Defaults to 0022 for system units. For units of the user service manager the default value
is inherited from the user instance (whose default is inherited from the system service manager, and
thus also is 0022). Hence changing the default value of a user instance, either via
<varname>UMask=</varname> or via a PAM module, will affect the user instance itself and all user
units started by the user instance unless a user unit has specified its own
<varname>UMask=</varname>.</para></listitem>
</varlistentry>

<varlistentry>
Expand Down
17 changes: 17 additions & 0 deletions src/basic/process-util.c
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,23 @@ int get_process_ppid(pid_t pid, pid_t *ret) {
return 0;
}

int get_process_umask(pid_t pid, mode_t *umask) {
_cleanup_free_ char *m = NULL;
const char *p;
int r;

assert(umask);
assert(pid >= 0);

p = procfs_file_alloca(pid, "status");

r = get_proc_field(p, "Umask", WHITESPACE, &m);
if (r == -ENOENT)
return -ESRCH;

return parse_mode(m, umask);
}

int wait_for_terminate(pid_t pid, siginfo_t *status) {
siginfo_t dummy;

Expand Down
1 change: 1 addition & 0 deletions src/basic/process-util.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ int get_process_cwd(pid_t pid, char **cwd);
int get_process_root(pid_t pid, char **root);
int get_process_environ(pid_t pid, char **environ);
int get_process_ppid(pid_t pid, pid_t *ppid);
int get_process_umask(pid_t pid, mode_t *umask);

int wait_for_terminate(pid_t pid, siginfo_t *status);

Expand Down
12 changes: 10 additions & 2 deletions src/core/unit.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,16 @@ static void unit_init(Unit *u) {
if (ec) {
exec_context_init(ec);

ec->keyring_mode = MANAGER_IS_SYSTEM(u->manager) ?
EXEC_KEYRING_SHARED : EXEC_KEYRING_INHERIT;
if (MANAGER_IS_SYSTEM(u->manager))
ec->keyring_mode = EXEC_KEYRING_SHARED;
else {
ec->keyring_mode = EXEC_KEYRING_INHERIT;

/* User manager might have its umask redefined by PAM or UMask=. In this
* case let the units it manages inherit this value by default. They can
* still tune this value through their own unit file */
(void) get_process_umask(getpid_cached(), &ec->umask);
}
}

kc = unit_get_kill_context(u);
Expand Down
1 change: 1 addition & 0 deletions src/login/systemd-user.m4
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ session required pam_selinux.so nottys open
session required pam_loginuid.so
session optional pam_keyinit.so force revoke
session required pam_namespace.so
session optional pam_umask.so silent
session optional pam_systemd.so
Loading