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

Configure Feed

Select the types of activity you want to include in your feed.

selftests/bpf: Test changing packet data from global functions with a kfunc

The verifier should invalidate all packet pointers after a packet data
changing kfunc is called. So, similar to commit 3f23ee5590d9
("selftests/bpf: test for changing packet data from global functions"),
test changing packet data from global functions to make sure packet
pointers are indeed invalidated.

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

authored by

Amery Hung and committed by
Martin KaFai Lau
1193c46c bc8712f2

+29 -1
+29 -1
tools/testing/selftests/bpf/progs/verifier_sock.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 /* Converted from tools/testing/selftests/bpf/verifier/sock.c */ 3 3 4 - #include <linux/bpf.h> 4 + #include "vmlinux.h" 5 5 #include <bpf/bpf_helpers.h> 6 6 #include "bpf_misc.h" 7 7 ··· 1066 1066 skb_pull_data1(sk, 0); 1067 1067 *p = 42; /* this is unsafe */ 1068 1068 return TCX_PASS; 1069 + } 1070 + 1071 + __noinline 1072 + long xdp_pull_data2(struct xdp_md *x, __u32 len) 1073 + { 1074 + return bpf_xdp_pull_data(x, len); 1075 + } 1076 + 1077 + __noinline 1078 + long xdp_pull_data1(struct xdp_md *x, __u32 len) 1079 + { 1080 + return xdp_pull_data2(x, len); 1081 + } 1082 + 1083 + /* global function calls bpf_xdp_pull_data(), which invalidates packet 1084 + * pointers established before global function call. 1085 + */ 1086 + SEC("xdp") 1087 + __failure __msg("invalid mem access") 1088 + int invalidate_xdp_pkt_pointers_from_global_func(struct xdp_md *x) 1089 + { 1090 + int *p = (void *)(long)x->data; 1091 + 1092 + if ((void *)(p + 1) > (void *)(long)x->data_end) 1093 + return XDP_DROP; 1094 + xdp_pull_data1(x, 0); 1095 + *p = 42; /* this is unsafe */ 1096 + return XDP_PASS; 1069 1097 } 1070 1098 1071 1099 __noinline