Skip to content

Commit 6e1046a

Browse files
theihorKernel Patches Daemon
authored and
Kernel Patches Daemon
committed
selftests/bpf: add cmp_map_pointer_with_const test
Add a test for CONST_PTR_TO_MAP comparison with a non-0 constant. A BPF program with this code must not pass verification in unpriv. Signed-off-by: Ihor Solodrai <[email protected]>
1 parent 481aee6 commit 6e1046a

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,23 @@ l0_%=: r0 = 0; \
634634
: __clobber_all);
635635
}
636636

637+
SEC("socket")
638+
__description("unpriv: cmp map pointer with const")
639+
__success __failure_unpriv __msg_unpriv("R1 pointer comparison prohibited")
640+
__retval(0)
641+
__naked void cmp_map_pointer_with_const(void)
642+
{
643+
asm volatile (" \
644+
r1 = 0; \
645+
r1 = %[map_hash_8b] ll; \
646+
if r1 == 0xdeadbeef goto l0_%=; \
647+
l0_%=: r0 = 0; \
648+
exit; \
649+
" :
650+
: __imm_addr(map_hash_8b)
651+
: __clobber_all);
652+
}
653+
637654
SEC("socket")
638655
__description("unpriv: write into frame pointer")
639656
__failure __msg("frame pointer is read only")

0 commit comments

Comments
 (0)