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>
This commit is contained in:
@@ -50,6 +50,7 @@ DLSYM_PROTOTYPE(bpf_program__attach) = NULL;
|
||||
DLSYM_PROTOTYPE(bpf_program__attach_cgroup) = NULL;
|
||||
DLSYM_PROTOTYPE(bpf_program__attach_lsm) = NULL;
|
||||
DLSYM_PROTOTYPE(bpf_program__name) = NULL;
|
||||
DLSYM_PROTOTYPE(bpf_program__set_autoload) = NULL;
|
||||
DLSYM_PROTOTYPE(libbpf_set_print) = NULL;
|
||||
DLSYM_PROTOTYPE(ring_buffer__epoll_fd) = NULL;
|
||||
DLSYM_PROTOTYPE(ring_buffer__free) = NULL;
|
||||
@@ -174,6 +175,7 @@ int dlopen_bpf(int log_level) {
|
||||
DLSYM_ARG_FORCE(bpf_program__attach_lsm),
|
||||
#endif
|
||||
DLSYM_ARG(bpf_program__name),
|
||||
DLSYM_ARG(bpf_program__set_autoload),
|
||||
DLSYM_ARG(libbpf_get_error),
|
||||
DLSYM_ARG(libbpf_set_print),
|
||||
DLSYM_ARG(ring_buffer__epoll_fd),
|
||||
|
||||
@@ -39,6 +39,7 @@ extern DLSYM_PROTOTYPE(bpf_program__attach);
|
||||
extern DLSYM_PROTOTYPE(bpf_program__attach_cgroup);
|
||||
extern DLSYM_PROTOTYPE(bpf_program__attach_lsm);
|
||||
extern DLSYM_PROTOTYPE(bpf_program__name);
|
||||
extern DLSYM_PROTOTYPE(bpf_program__set_autoload);
|
||||
extern DLSYM_PROTOTYPE(libbpf_set_print);
|
||||
extern DLSYM_PROTOTYPE(ring_buffer__epoll_fd);
|
||||
extern DLSYM_PROTOTYPE(ring_buffer__free);
|
||||
|
||||
Reference in New Issue
Block a user