Skip to content

Commit dfc0131

Browse files
committed
bpf: Fix crash due to out of bounds access into reg2btf_ids.
jira VULN-72 jira VULN-7854 cve 2021-4204 cve 2022-48929 commit-author Kumar Kartikeya Dwivedi <[email protected]> commit 45ce4b4 upstream-diff Part of this upstream change was already backported, but because commit 3363bd0 ("bpf: Extend kfunc with PTR_TO_CTX, PTR_TO_MEM argument support") had not been backported at that time, the out of bound access it introduced was not fixed in that backport. Since we have now backported 3363bd0, we need to backport the remaining change from the upstream fix When commit e6ac245 ("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 c25b2ae ("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: c25b2ae ("bpf: Replace PTR_TO_XXX_OR_NULL with PTR_TO_XXX | PTR_MAYBE_NULL") Signed-off-by: Kumar Kartikeya Dwivedi <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]> Link: https://lore.kernel.org/bpf/[email protected] (cherry picked from commit 45ce4b4) Signed-off-by: Brett Mastbergen <[email protected]>
1 parent 1697b91 commit dfc0131

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

kernel/bpf/btf.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -5496,7 +5496,8 @@ static int btf_check_func_arg_match(struct bpf_verifier_env *env,
54965496
}
54975497
if (check_ptr_off_reg(env, reg, regno))
54985498
return -EINVAL;
5499-
} else if (is_kfunc && (reg->type == PTR_TO_BTF_ID || reg2btf_ids[reg->type])) {
5499+
} else if (is_kfunc && (reg->type == PTR_TO_BTF_ID ||
5500+
(reg2btf_ids[base_type(reg->type)] && !type_flag(reg->type)))) {
55005501
const struct btf_type *reg_ref_t;
55015502
const struct btf *reg_btf;
55025503
const char *reg_ref_tname;

0 commit comments

Comments
 (0)