Skip to content

Commit b0db1ac

Browse files
Qi TangAlexei Starovoitov
authored andcommitted
bpf: reject direct access to nullable PTR_TO_BUF pointers
check_mem_access() matches PTR_TO_BUF via base_type() which strips PTR_MAYBE_NULL, allowing direct dereference without a null check. Map iterator ctx->key and ctx->value are PTR_TO_BUF | PTR_MAYBE_NULL. On stop callbacks these are NULL, causing a kernel NULL dereference. Add a type_may_be_null() guard to the PTR_TO_BUF branch, matching the existing PTR_TO_BTF_ID pattern. Fixes: 20b2aff ("bpf: Introduce MEM_RDONLY flag") Signed-off-by: Qi Tang <tpluszz77@gmail.com> Acked-by: Kumar Kartikeya Dwivedi <memxor@gmail.com> Link: https://lore.kernel.org/r/20260402092923.38357-2-tpluszz77@gmail.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
1 parent ad8391d commit b0db1ac

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

kernel/bpf/verifier.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7905,7 +7905,8 @@ static int check_mem_access(struct bpf_verifier_env *env, int insn_idx, u32 regn
79057905
} else if (reg->type == CONST_PTR_TO_MAP) {
79067906
err = check_ptr_to_map_access(env, regs, regno, off, size, t,
79077907
value_regno);
7908-
} else if (base_type(reg->type) == PTR_TO_BUF) {
7908+
} else if (base_type(reg->type) == PTR_TO_BUF &&
7909+
!type_may_be_null(reg->type)) {
79097910
bool rdonly_mem = type_is_rdonly_mem(reg->type);
79107911
u32 *max_access;
79117912

0 commit comments

Comments
 (0)