Skip to content

Commit

Permalink
selftests/bpf: Add test for alu on PTR_TO_FLOW_KEYS
Browse files Browse the repository at this point in the history
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 <sunhao.th@gmail.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Yonghong Song <yonghong.song@linux.dev>
Link: https://lore.kernel.org/bpf/20240115082028.9992-2-sunhao.th@gmail.com
  • Loading branch information
SunHao-0 authored and borkmann committed Jan 16, 2024
1 parent 22c7fa1 commit 33772ff
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tools/testing/selftests/bpf/progs/verifier_value_illegal_alu.c
Expand Up @@ -146,4 +146,23 @@ l0_%=: exit; \
: __clobber_all);
}

SEC("flow_dissector")
__description("flow_keys illegal alu op with variable offset")
__failure __msg("R7 pointer arithmetic on flow_keys prohibited")
__naked void flow_keys_illegal_variable_offset_alu(void)
{
asm volatile(" \
r6 = r1; \
r7 = *(u64*)(r6 + %[flow_keys_off]); \
r8 = 8; \
r8 /= 1; \
r8 &= 8; \
r7 += r8; \
r0 = *(u64*)(r7 + 0); \
exit; \
" :
: __imm_const(flow_keys_off, offsetof(struct __sk_buff, flow_keys))
: __clobber_all);
}

char _license[] SEC("license") = "GPL";

0 comments on commit 33772ff

Please sign in to comment.