diff options
author | Daan De Meyer <daan.j.demeyer@gmail.com> | 2024-08-29 17:10:46 +0200 |
---|---|---|
committer | Ryan Wilson <ryantimwilson@meta.com> | 2024-11-05 14:32:02 +0100 |
commit | 406f1775017a5631bc91a1f53ac5e50f4fbfac0c (patch) | |
tree | a47f9ee6d0b9e1b036300949e2d803d676497946 /src/shared | |
parent | exec-invoke: Add debug logging for setup_private_users() (diff) | |
download | systemd-406f1775017a5631bc91a1f53ac5e50f4fbfac0c.tar.xz systemd-406f1775017a5631bc91a1f53ac5e50f4fbfac0c.zip |
core: Introduce PrivatePIDs=
This new setting allows unsharing the pid namespace in a unit. Because
you have to fork to get a process into a pid namespace, we fork in
systemd-executor to get into the new pid namespace. The parent then
sends the pid of the child process back to the manager and exits while
the child process continues on with the rest of exec_invoke() and then
executes the actual payload.
Communicating the child pid is done via a new pidref socket pair that is
set up on manager startup.
We unshare the PID namespace right before the mount namespace so we
mount procfs correctly. Note PrivatePIDs=yes always implies MountAPIVFS=yes
to mount procfs.
When running unprivileged in a user session, user namespace is set up first
to allow for PID namespace to be unshared. However, when running in
privileged mode, we unshare the user namespace last to ensure the user
namespace does not own the PID namespace and cannot break out of the sandbox.
Note we disallow Type=forking services from using PrivatePIDs=yes since the
init proess inside the PID namespace must not exit for other processes in
the namespace to exist.
Note Daan De Meyer did the original work for this commit with Ryan Wilson
addressing follow-ups.
Co-authored-by: Daan De Meyer <daan.j.demeyer@gmail.com>
Diffstat (limited to 'src/shared')
-rw-r--r-- | src/shared/bus-unit-util.c | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/src/shared/bus-unit-util.c b/src/shared/bus-unit-util.c index 90b6f233e2..06bfb90c8f 100644 --- a/src/shared/bus-unit-util.c +++ b/src/shared/bus-unit-util.c @@ -1061,7 +1061,8 @@ static int bus_append_execute_property(sd_bus_message *m, const char *field, con "LogNamespace", "RootImagePolicy", "MountImagePolicy", - "ExtensionImagePolicy")) + "ExtensionImagePolicy", + "PrivatePIDs")) return bus_append_string(m, field, eq); if (STR_IN_SET(field, "IgnoreSIGPIPE", |