From: Alexei Starovoitov <ast@kernel.org> mainline inclusion from mainline-v7.4-rc5 commit 2c517088d2ef5f9b17fcb2e44a296e36c5a91843 category: bugfix bugzilla: https://atomgit.com/openeuler/kernel/issues/10194 Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?i... -------------------------------- ___neigh_create() calls the tracepoint before it tests the result of neigh_alloc(). It is NULL when the table is full. The verifier takes it for a trusted pointer, and a load through it oopses: BUG: kernel NULL pointer dereference, address: 000000000000013c RIP: 0010:bpf_prog_56e3384dcafb1b5b_on_create+0x61/0xc4 Mark it untrusted, loads through it are probed then. PTR_MAYBE_NULL would refuse programs like bpftune, which pass &n->parms to bpf_probe_read_kernel() without a check. The pointer cannot be passed as memory or as a trusted argument any more. Fixes: 838a10bd2ebf ("bpf: Augment raw_tp arguments with PTR_MAYBE_NULL") Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://patch.msgid.link/20261125032938.670542-12-alexei.starovoitov@gmail.c... Conflicts: kernel/bpf/btf.c [ctx conflicts] Signed-off-by: Pu Lehui <pulehui@huawei.com> --- kernel/bpf/btf.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c index 4ba4dcb4e80b..ebdf230fbf41 100644 --- a/kernel/bpf/btf.c +++ b/kernel/bpf/btf.c @@ -6255,6 +6255,7 @@ static const struct bpf_raw_tp_null_args raw_tp_null_args[] = { /* iptfs */ { "iptfs_ingress_postq_event", 0x1000 }, /* neigh */ + { "neigh_create", 0x4000 }, { "neigh_update", 0x10 }, /* snd_firewire_lib */ { "amdtp_packet", 0x100 }, @@ -6462,6 +6463,9 @@ bool btf_ctx_access(int off, int size, enum bpf_access_type type, /* Is the current arg IS_ERR? */ if (raw_tp_null_args[i].mask & (0x2 << (arg * 4))) ptr_err_raw_tp = true; + /* It can be NULL, and programs that do not check it have to load */ + if (raw_tp_null_args[i].mask & (0x4ULL << (arg * 4))) + info->reg_type = PTR_TO_BTF_ID | PTR_UNTRUSTED; break; } /* If we don't know NULL-ness specification and the tracepoint -- 2.34.1