]> git.ipfire.org Git - thirdparty/systemd.git/commit
core: preserve RestrictFileSystemAccess= BPF state across daemon-reexec
authorChristian Brauner <brauner@kernel.org>
Fri, 8 May 2026 08:48:12 +0000 (10:48 +0200)
committerChristian Brauner <brauner@kernel.org>
Wed, 13 May 2026 08:36:12 +0000 (10:36 +0200)
commit6c0f509587eb90f9d586d097500a66c2f33078d3
tree0a194ce4836c7debf9c423ea3c036432278fd94f
parent68fe7fa4d62cf777a4be1df00761e27b21754b1b
core: preserve RestrictFileSystemAccess= BPF state across daemon-reexec

The BPF link and .bss map FDs must survive PID1 re-execution
(daemon-reexec, switch_root, soft-reboot). Without serialization,
manager_free() closes them before execv, programs detach, and the
verity_devices map is freed. After exec a fresh skeleton would have
an empty map — but existing dm-verity devices have already called
bdev_setintegrity and won't call it again. The result would be a
deny-default policy with an empty map, i.e., all execution denied
and the system bricked.

Add serialize/deserialize support using systemd's existing
serialize_fd / fdset_cloexec / deserialize_fd infrastructure:

Before exec (in manager_serialize via bpf_restrict_fsaccess_serialize):
  - Dup each link FD and the .bss map FD into the FDSet
  - fdset_cloexec(fds, false) + execv() preserves them across exec

After exec (in manager_deserialize + bpf_restrict_fsaccess_setup):
  - Deserialize the link FDs and .bss map FD into the Manager struct
  - bpf_restrict_fsaccess_setup() detects the deserialized FDs and skips
    skeleton re-creation entirely — the programs are already attached
  - If no longer in initrd, clear initramfs_s_dev in the kernel map

No bpffs pinning is needed. This avoids a bpffs mount dependency and
eliminates the external attack surface that pinned objects would create
(discoverable/manipulable via unlink or BPF_OBJ_GET). The FDs remain
private to PID1.

Signed-off-by: Christian Brauner <brauner@kernel.org>
src/core/bpf-restrict-fsaccess.c
src/core/bpf-restrict-fsaccess.h
src/core/manager-serialize.c
src/shared/bpf-dlopen.c
src/shared/bpf-dlopen.h