]> git.baikalelectronics.ru Git - kernel.git/commit
bpf: Fix crash due to out of bounds access into reg2btf_ids.
authorKumar Kartikeya Dwivedi <memxor@gmail.com>
Wed, 16 Feb 2022 20:19:43 +0000 (01:49 +0530)
committerAlexei Starovoitov <ast@kernel.org>
Wed, 16 Feb 2022 20:46:51 +0000 (12:46 -0800)
commit8ed079df20044e3787de1825d2b9ce0a1bc0b3d6
tree806a5cc566416b243fb0fabc7a7adbf7ab97efea
parentfd547fd0663f0da832ac088d52ba8f2faafedf8c
bpf: Fix crash due to out of bounds access into reg2btf_ids.

When commit fc84fd6c867f ("bpf: Support bpf program calling kernel function") added
kfunc support, it defined reg2btf_ids as a cheap way to translate the verifier
reg type to the appropriate btf_vmlinux BTF ID, however
commit 4884a023683c ("bpf: Replace PTR_TO_XXX_OR_NULL with PTR_TO_XXX | PTR_MAYBE_NULL")
moved the __BPF_REG_TYPE_MAX from the last member of bpf_reg_type enum to after
the base register types, and defined other variants using type flag
composition. However, now, the direct usage of reg->type to index into
reg2btf_ids may no longer fall into __BPF_REG_TYPE_MAX range, and hence lead to
out of bounds access and kernel crash on dereference of bad pointer.

Fixes: 4884a023683c ("bpf: Replace PTR_TO_XXX_OR_NULL with PTR_TO_XXX | PTR_MAYBE_NULL")
Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20220216201943.624869-1-memxor@gmail.com
kernel/bpf/btf.c