]> git.ipfire.org Git - thirdparty/systemd.git/commit
core: add RestrictFileSystemAccess= BPF LSM for dm-verity execution enforcement
authorChristian Brauner <brauner@kernel.org>
Fri, 8 May 2026 08:45:23 +0000 (10:45 +0200)
committerChristian Brauner <brauner@kernel.org>
Wed, 13 May 2026 08:36:12 +0000 (10:36 +0200)
commit68fe7fa4d62cf777a4be1df00761e27b21754b1b
tree98423c3bbbaa598e6fb35c2d091263b9d2107431
parent408d474dfa1a320cfa650b7624f9efdf55f639f2
core: add RestrictFileSystemAccess= BPF LSM for dm-verity execution enforcement

Add a new RestrictFileSystemAccess= boolean setting in the [Manager] section of
system.conf that enforces execution only from signed dm-verity block
devices and the initramfs during early boot.

When RestrictFileSystemAccess=yes is set, PID1 loads a BPF LSM program early in boot
that:

Integrity tracking (self-populating, no userspace involvement):
 - bdev_setintegrity: records dm-verity signature status in a BPF hash
   map when the kernel signals device integrity via
   security_bdev_setintegrity()
 - bdev_free_security: removes devices from the map on teardown

Execution enforcement (deny-default policy):
 - bprm_check_security: blocks execve() from untrusted sources
 - mmap_file: blocks PROT_EXEC mmap (shared libs, anonymous exec memory)
 - file_mprotect: blocks W->X transitions (JIT, libffi, etc.)

Trust anchors:
 - Signed dm-verity volumes (sig_valid flag in the BPF map)
 - Initramfs (s_dev captured at load time, cleared after switch_root)
 - Everything else is denied (tmpfs, procfs, sysfs, anonymous PROT_EXEC)

PID1 requires dm-verity require_signatures=1 to be enabled and refuses
to load the BPF program otherwise, ensuring the kernel enforces that all
dm-verity devices carry valid signatures.

After attach, PID1 extracts owned FDs from the skeleton (link FDs +
.bss map FD) and lets the skeleton be destroyed. The dup'd link FDs
keep programs attached via the kernel reference chain (link FD ->
bpf_link -> bpf_prog -> bpf_map). Destroying the skeleton unmaps the
.bss page from PID1's address space so no BPF state is readable via
/proc/1/mem. The .bss map FD is retained for targeted writes (clearing
initramfs_s_dev after switch_root via mmap).

Signed-off-by: Christian Brauner <brauner@kernel.org>
15 files changed:
man/kernel-command-line.xml
man/systemd-system.conf.xml
src/bpf/meson.build
src/bpf/restrict-fsaccess.bpf.c [new file with mode: 0644]
src/core/bpf-restrict-fs.c
src/core/bpf-restrict-fsaccess.c [new file with mode: 0644]
src/core/bpf-restrict-fsaccess.h [new file with mode: 0644]
src/core/core-forward.h
src/core/main.c
src/core/manager.c
src/core/manager.h
src/core/meson.build
src/core/system.conf.in
src/shared/bpf-link.c
src/shared/bpf-link.h