Skip to content

Commit 13c6a37

Browse files
kkdwivediAlexei Starovoitov
authored and
Alexei Starovoitov
committed
selftests/bpf: Add test for reg2btf_ids out of bounds access
This test tries to pass a PTR_TO_BTF_ID_OR_NULL to the release function, which would trigger a out of bounds access without the fix in commit 45ce4b4 ("bpf: Fix crash due to out of bounds access into reg2btf_ids.") but after the fix, it should only index using base_type(reg->type), which should be less than __BPF_REG_TYPE_MAX, and also not permit any type flags to be set for the reg->type. Signed-off-by: Kumar Kartikeya Dwivedi <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent b03e194 commit 13c6a37

File tree

1 file changed

+19
-0
lines changed
  • tools/testing/selftests/bpf/verifier

1 file changed

+19
-0
lines changed

tools/testing/selftests/bpf/verifier/calls.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,25 @@
9696
{ "bpf_kfunc_call_test_mem_len_fail1", 2 },
9797
},
9898
},
99+
{
100+
"calls: trigger reg2btf_ids[reg->type] for reg->type > __BPF_REG_TYPE_MAX",
101+
.insns = {
102+
BPF_MOV64_REG(BPF_REG_1, BPF_REG_10),
103+
BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, -8),
104+
BPF_ST_MEM(BPF_DW, BPF_REG_1, 0, 0),
105+
BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, BPF_PSEUDO_KFUNC_CALL, 0, 0),
106+
BPF_MOV64_REG(BPF_REG_1, BPF_REG_0),
107+
BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, BPF_PSEUDO_KFUNC_CALL, 0, 0),
108+
BPF_EXIT_INSN(),
109+
},
110+
.prog_type = BPF_PROG_TYPE_SCHED_CLS,
111+
.result = REJECT,
112+
.errstr = "arg#0 pointer type STRUCT prog_test_ref_kfunc must point",
113+
.fixup_kfunc_btf_id = {
114+
{ "bpf_kfunc_call_test_acquire", 3 },
115+
{ "bpf_kfunc_call_test_release", 5 },
116+
},
117+
},
99118
{
100119
"calls: basic sanity",
101120
.insns = {

0 commit comments

Comments
 (0)