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

selftests/bpf: Test changing packet data from kfunc

bpf_xdp_pull_data() is the first kfunc that changes packet data. Make
sure the verifier clear all packet pointers after calling packet data
changing kfunc.

Signed-off-by: Amery Hung <ameryhung@gmail.com>
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
Link: https://patch.msgid.link/20250926164142.1850176-1-ameryhung@gmail.com

authored by

Amery Hung and committed by
Martin KaFai Lau
991e555e d43029ff

+14
+14
tools/testing/selftests/bpf/progs/verifier_sock.c
··· 1096 1096 return XDP_PASS; 1097 1097 } 1098 1098 1099 + /* XDP packet changing kfunc calls invalidate packet pointers */ 1100 + SEC("xdp") 1101 + __failure __msg("invalid mem access") 1102 + int invalidate_xdp_pkt_pointers(struct xdp_md *x) 1103 + { 1104 + int *p = (void *)(long)x->data; 1105 + 1106 + if ((void *)(p + 1) > (void *)(long)x->data_end) 1107 + return XDP_DROP; 1108 + bpf_xdp_pull_data(x, 0); 1109 + *p = 42; /* this is unsafe */ 1110 + return XDP_PASS; 1111 + } 1112 + 1099 1113 __noinline 1100 1114 int tail_call(struct __sk_buff *sk) 1101 1115 {