History

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.

Jann Horn committed 6 years ago

Commit 8ff35711 parent 6e7e63c1 file · +1 −1Browse files

Unified · Split

kernel/bpf/verifier.c+1−1
@@ -3099,7 +3099,7 @@ static int check_ptr_to_btf_access(struct bpf_verifier_env *env, · 3098 unmodified lines
3099 if (ret < 0)3099 if (ret < 0)
3100 return ret;3100 return ret;
3101 3101
3102 if (atype == BPF_READ) {3102 if (atype == BPF_READ && value_regno >= 0) {
3103 if (ret == SCALAR_VALUE) {3103 if (ret == SCALAR_VALUE) {
3104 mark_reg_unknown(env, regs, value_regno);3104 mark_reg_unknown(env, regs, value_regno);
3105 return 0;3105 return 0;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t