Skip to contentSkip to conversation

selftests/bpf: Test changing packet data from kfunc

PATCH Applied Amery Hung 2 participants 2 messages Sep 26, 2025

Subsystems (5)
lore
Share & tools
lore

Amery Hung

author
#0 lore raw

PATCH 1/1 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.

---
 tools/testing/selftests/bpf/progs/verifier_sock.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
tools/testing/selftests/bpf/progs/verifier_sock.c +14 -0
index b4d31f10a976..2b4610b53382 100644
@@ -1096,6 +1096,20 @@ int invalidate_xdp_pkt_pointers_from_global_func(struct xdp_md *x)
 	return XDP_PASS;
 }
 
+/* XDP packet changing kfunc calls invalidate packet pointers */
+SEC("xdp")
+__failure __msg("invalid mem access")
+int invalidate_xdp_pkt_pointers(struct xdp_md *x)
+{
+	int *p = (void *)(long)x->data;
+
+	if ((void *)(p + 1) > (void *)(long)x->data_end)
+		return XDP_DROP;
+	bpf_xdp_pull_data(x, 0);
+	*p = 42; /* this is unsafe */
+	return XDP_PASS;
+}
+
 __noinline
 int tail_call(struct __sk_buff *sk)
 {
Signature · 1 line
2.47.3
#1 lore raw
This patch was applied to bpf/bpf-next.git (master) by Martin KaFai Lau <[email protected]>:

Hello:

This patch was applied to bpf/bpf-next.git (master) by Martin KaFai Lau <[email protected]>:

Quoted 8 lines · On Fri, 26 Sep 2025 09:41:42 -0700 you wrote:

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.

---
 tools/testing/selftests/bpf/progs/verifier_sock.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

Here is the summary with links:
- [bpf-next,1/1] selftests/bpf: Test changing packet data from kfunc

    https://git.kernel.org/bpf/bpf-next/c/991e555efffd

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html