Commit 8709c168 authored by KaFai Wan's avatar KaFai Wan Committed by Alexei Starovoitov
Browse files

selftests/bpf: Add test for BPF_NEG alu on CONST_PTR_TO_MAP



Add a test case for BPF_NEG operation on CONST_PTR_TO_MAP. Tests if
BPF_NEG operation on map_ptr is rejected in unprivileged mode and is a
scalar value and do not trigger Oops in privileged mode.

Signed-off-by: default avatarKaFai Wan <kafai.wan@linux.dev>
Signed-off-by: default avatarBrahmajit Das <listout@listout.xyz>
Acked-by: default avatarEduard Zingerman <eddyz87@gmail.com>
Link: https://lore.kernel.org/r/20251001191739.2323644-3-listout@listout.xyz


Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
parent 34904582
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -146,6 +146,24 @@ l0_%=: exit; \
	: __clobber_all);
}

SEC("socket")
__description("map_ptr illegal alu op, map_ptr = -map_ptr")
__failure __msg("R0 invalid mem access 'scalar'")
__failure_unpriv __msg_unpriv("R0 pointer arithmetic prohibited")
__flag(BPF_F_ANY_ALIGNMENT)
__naked void map_ptr_illegal_alu_op(void)
{
	asm volatile ("					\
	r0 = %[map_hash_48b] ll;			\
	r0 = -r0;					\
	r1 = 22;					\
	*(u64*)(r0 + 0) = r1;				\
	exit;						\
"	:
	: __imm_addr(map_hash_48b)
	: __clobber_all);
}

SEC("flow_dissector")
__description("flow_keys illegal alu op with variable offset")
__failure __msg("R7 pointer arithmetic on flow_keys prohibited")