]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
bpf: Enforce write checks for BTF pointer helper access
authorNuoqi Gui <gnq25@mails.tsinghua.edu.cn>
Tue, 9 Jun 2026 14:43:50 +0000 (22:43 +0800)
committerKumar Kartikeya Dwivedi <memxor@gmail.com>
Tue, 9 Jun 2026 15:39:46 +0000 (17:39 +0200)
check_mem_reg() verifies both read and write access for global subprogram
memory arguments. When the caller register is PTR_TO_BTF_ID,
check_helper_mem_access() currently forwards the access to
check_ptr_to_btf_access() as BPF_READ regardless of the requested access
type.

This lets a BTF-backed kernel object field pointer pass the caller-side
writable memory check for a global subprogram argument. The callee is then
validated with a generic writable PTR_TO_MEM argument and can store through
it, even though an equivalent direct BTF field store is rejected with "only
read is supported".

Forward the requested access type to check_ptr_to_btf_access().
This enforces existing BTF write restrictions for global subprogram memory
arguments as well.

Fixes: 3e30be4288b3 ("bpf: Allow helpers access trusted PTR_TO_BTF_ID.")
Signed-off-by: Nuoqi Gui <gnq25@mails.tsinghua.edu.cn>
Link: https://lore.kernel.org/bpf/20260609-f01-04-btf-writable-arg-v1-1-f449cd970669@mails.tsinghua.edu.cn
Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
kernel/bpf/verifier.c

index ed7ba0e6a9ce0ec071e8a088a1595891b6043e3a..cdff3e6eb96e7b765bf41ea8528fe28a2c592c06 100644 (file)
@@ -6777,7 +6777,7 @@ static int check_helper_mem_access(struct bpf_verifier_env *env, struct bpf_reg_
                                zero_size_allowed, access_type, meta);
        case PTR_TO_BTF_ID:
                return check_ptr_to_btf_access(env, regs, reg, argno, 0,
-                                              access_size, BPF_READ, -1);
+                                              access_size, access_type, -1);
        case PTR_TO_CTX:
                /* Only permit reading or writing syscall context using helper calls. */
                if (is_var_ctx_off_allowed(env->prog)) {