Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <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

authored by

Hao Sun and committed by
Daniel Borkmann
33772ff3 22c7fa17

+19
+19
tools/testing/selftests/bpf/progs/verifier_value_illegal_alu.c
··· 146 146 : __clobber_all); 147 147 } 148 148 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 + 149 168 char _license[] SEC("license") = "GPL";