]> git.ipfire.org Git - thirdparty/systemd.git/commit
core: Introduce PrivatePIDs= 34940/head
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Thu, 29 Aug 2024 15:10:46 +0000 (17:10 +0200)
committerRyan Wilson <ryantimwilson@meta.com>
Tue, 5 Nov 2024 13:32:02 +0000 (05:32 -0800)
commit406f1775017a5631bc91a1f53ac5e50f4fbfac0c
treea47f9ee6d0b9e1b036300949e2d803d676497946
parent89fdca71686779f04ce354f2b7103ffdb2a14f97
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>
23 files changed:
NEWS
man/org.freedesktop.systemd1.xml
man/systemd.exec.xml
src/basic/process-util.c
src/basic/process-util.h
src/core/dbus-execute.c
src/core/exec-invoke.c
src/core/execute-serialize.c
src/core/execute.c
src/core/execute.h
src/core/load-fragment-gperf.gperf.in
src/core/load-fragment.c
src/core/load-fragment.h
src/core/manager.c
src/core/manager.h
src/core/namespace.c
src/core/namespace.h
src/core/service.c
src/core/unit.c
src/core/unit.h
src/shared/bus-unit-util.c
test/TEST-07-PID1/test.sh
test/units/TEST-07-PID1.private-pids.sh [new file with mode: 0755]