Skip to content

Commit 8ff3571

Browse files
thejhAlexei Starovoitov
authored andcommitted
bpf: Fix handling of XADD on BTF memory
check_xadd() can cause check_ptr_to_btf_access() to be executed with atype==BPF_READ and value_regno==-1 (meaning "just check whether the access is okay, don't tell me what type it will result in"). Handle that case properly and skip writing type information, instead of indexing into the registers at index -1 and writing into out-of-bounds memory. Note that at least at the moment, you can't actually write through a BTF pointer, so check_xadd() will reject the program after calling check_ptr_to_btf_access with atype==BPF_WRITE; but that's after the verifier has already corrupted memory. This patch assumes that BTF pointers are not available in unprivileged programs. Fixes: 9e15db6 ("bpf: Implement accurate raw_tp context access via BTF") Signed-off-by: Jann Horn <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 6e7e63c commit 8ff3571

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

kernel/bpf/verifier.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3099,7 +3099,7 @@ static int check_ptr_to_btf_access(struct bpf_verifier_env *env,
30993099
if (ret < 0)
31003100
return ret;
31013101

3102-
if (atype == BPF_READ) {
3102+
if (atype == BPF_READ && value_regno >= 0) {
31033103
if (ret == SCALAR_VALUE) {
31043104
mark_reg_unknown(env, regs, value_regno);
31053105
return 0;

0 commit comments

Comments
 (0)