]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
bpf: Fix NULL deref in map_kptr_match_type for scalar regs
authorMykyta Yatsenko <yatsenko@meta.com>
Thu, 16 Apr 2026 18:08:07 +0000 (11:08 -0700)
committerAlexei Starovoitov <ast@kernel.org>
Thu, 16 Apr 2026 22:20:26 +0000 (15:20 -0700)
commit4d0a375887ab4d49e4da1ff10f9606cab8f7c3ad
treecba7dc3dcf30499d60dd71a758cef007de7af618
parente5f635edd393aeaa7cad9e42831d397e6e2e1eed
bpf: Fix NULL deref in map_kptr_match_type for scalar regs

Commit ab6c637ad027 ("bpf: Fix a bpf_kptr_xchg() issue with local
kptr") refactored map_kptr_match_type() to branch on btf_is_kernel()
before checking base_type(). A scalar register stored into a kptr
slot has no btf, so the btf_is_kernel(reg->btf) call dereferences
NULL.

Move the base_type() != PTR_TO_BTF_ID guard before any reg->btf
access.

Fixes: ab6c637ad027 ("bpf: Fix a bpf_kptr_xchg() issue with local kptr")
Reported-by: Hiker Cl <clhiker365@gmail.com>
Closes: https://bugzilla.kernel.org/show_bug.cgi?id=221372
Signed-off-by: Mykyta Yatsenko <yatsenko@meta.com>
Acked-by: Paul Chaignon <paul.chaignon@gmail.com>
Link: https://lore.kernel.org/r/20260416-kptr_crash-v1-1-5589356584b4@meta.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
kernel/bpf/verifier.c