]> git.ipfire.org Git - thirdparty/systemd.git/commit
core: work around btf_ctx_access() rejection of const void * in BPF LSM
authorChristian Brauner <brauner@kernel.org>
Fri, 8 May 2026 08:53:16 +0000 (10:53 +0200)
committerChristian Brauner <brauner@kernel.org>
Wed, 13 May 2026 08:36:13 +0000 (10:36 +0200)
commit4684df8f9700ccb9b5f744e50fb565eaa25993c5
treece1ede8abae6bcf84d49e8884c05af7265f429c5
parent5439911f59db2aa32799b4c88e5a2c34a61367f6
core: work around btf_ctx_access() rejection of const void * in BPF LSM

Kernels before v6.16 (missing commit 1271a40eeafa "bpf: Allow access to
const void pointer arguments in tracing programs") have a bug in
btf_ctx_access() where const void * parameters in LSM hook signatures
are not recognized as void pointers. The function checks t->type == 0
to detect void *, but for const void * the BTF chain is PTR -> CONST ->
void, so t->type points to the CONST node rather than directly to
type_id 0. This causes the verifier to reject any BPF program that
reads the const void *value argument of bdev_setintegrity:

  func 'bpf_lsm_bdev_setintegrity' arg2 type UNKNOWN is not a struct
  invalid bpf_context access off=16 size=8

Work around this by providing a compat variant of the
bdev_setintegrity BPF program that avoids reading the const void *value
argument entirely. Instead it reads the size argument (a scalar integer)
directly from the raw BPF context (ctx[3]), which is not subject to the
broken type check. This is safe because dm-verity guarantees that value
and size are always in lockstep: both NULL/0 for unsigned devices, both
non-zero for signed devices.

The loader tries the full version first (which reads both value and size
for defense-in-depth) and falls back to the compat variant if loading
fails. bpf_program__set_autoload(false) disables whichever variant is
not needed so the verifier never sees it.

This compat logic can be removed once the minimum kernel baseline
includes the 1271a40eeafa fix.

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