Skip to content

Commit f513c36

Browse files
kkdwivediAlexei Starovoitov
authored and
Alexei Starovoitov
committed
selftests/bpf: Add test for reading from STACK_INVALID slots
Ensure that when CAP_PERFMON is dropped, and the verifier sees allow_ptr_leaks as false, we are not permitted to read from a STACK_INVALID slot. Without the fix, the test will report unexpected success in loading. Signed-off-by: Kumar Kartikeya Dwivedi <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent adfdd9c commit f513c36

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

tools/testing/selftests/bpf/progs/verifier_spill_fill.c

+18
Original file line numberDiff line numberDiff line change
@@ -1244,4 +1244,22 @@ __naked void old_stack_misc_vs_cur_ctx_ptr(void)
12441244
: __clobber_all);
12451245
}
12461246

1247+
SEC("socket")
1248+
__description("stack_noperfmon: reject read of invalid slots")
1249+
__success
1250+
__caps_unpriv(CAP_BPF)
1251+
__failure_unpriv __msg_unpriv("invalid read from stack off -8+1 size 8")
1252+
__naked void stack_noperfmon_reject_invalid_read(void)
1253+
{
1254+
asm volatile (" \
1255+
r2 = 1; \
1256+
r6 = r10; \
1257+
r6 += -8; \
1258+
*(u8 *)(r6 + 0) = r2; \
1259+
r2 = *(u64 *)(r6 + 0); \
1260+
r0 = 0; \
1261+
exit; \
1262+
" ::: __clobber_all);
1263+
}
1264+
12471265
char _license[] SEC("license") = "GPL";

0 commit comments

Comments
 (0)