bpf: Check for NULL return from bpf_get_btf_vmlinux
authorKumar Kartikeya Dwivedi <memxor@gmail.com>
Sun, 20 Mar 2022 14:30:03 +0000 (20:00 +0530)
committerAlexei Starovoitov <ast@kernel.org>
Mon, 21 Mar 2022 02:21:38 +0000 (19:21 -0700)
commit7ada3787e91c89b0aa7abf47682e8e587b855c13
treee85380b9690ec176cbff5a327a1156424250ee71
parente1cc1f39981b06ba22a0c92e800e9fd8ba59d2d3
bpf: Check for NULL return from bpf_get_btf_vmlinux

When CONFIG_DEBUG_INFO_BTF is disabled, bpf_get_btf_vmlinux can return a
NULL pointer. Check for it in btf_get_module_btf to prevent a NULL pointer
dereference.

While kernel test robot only complained about this specific case, let's
also check for NULL in other call sites of bpf_get_btf_vmlinux.

Fixes: 9492450fd287 ("bpf: Always raise reference in btf_get_module_btf")
Reported-by: kernel test robot <oliver.sang@intel.com>
Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20220320143003.589540-1-memxor@gmail.com
kernel/bpf/btf.c
net/core/bpf_sk_storage.c