Skip to content

Commit 33772ff

Browse files
SunHao-0borkmann
authored andcommitted
selftests/bpf: Add test for alu on PTR_TO_FLOW_KEYS
Add a test case for PTR_TO_FLOW_KEYS alu. Testing if alu with variable offset on flow_keys is rejected. For the fixed offset success case, we already have C code coverage to verify (e.g. via bpf_flow.c). Signed-off-by: Hao Sun <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Acked-by: Yonghong Song <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 22c7fa1 commit 33772ff

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,4 +146,23 @@ l0_%=: exit; \
146146
: __clobber_all);
147147
}
148148

149+
SEC("flow_dissector")
150+
__description("flow_keys illegal alu op with variable offset")
151+
__failure __msg("R7 pointer arithmetic on flow_keys prohibited")
152+
__naked void flow_keys_illegal_variable_offset_alu(void)
153+
{
154+
asm volatile(" \
155+
r6 = r1; \
156+
r7 = *(u64*)(r6 + %[flow_keys_off]); \
157+
r8 = 8; \
158+
r8 /= 1; \
159+
r8 &= 8; \
160+
r7 += r8; \
161+
r0 = *(u64*)(r7 + 0); \
162+
exit; \
163+
" :
164+
: __imm_const(flow_keys_off, offsetof(struct __sk_buff, flow_keys))
165+
: __clobber_all);
166+
}
167+
149168
char _license[] SEC("license") = "GPL";

0 commit comments

Comments
 (0)