Commit 85d454af authored by Jakub Sitnicki's avatar Jakub Sitnicki Committed by Martin KaFai Lau
Browse files

selftests/bpf: Cover skb metadata access after change_head/tail helper



Add a test to verify that skb metadata remains accessible after calling
bpf_skb_change_head() and bpf_skb_change_tail(), which modify packet
headroom/tailroom and can trigger head reallocation.

Signed-off-by: default avatarJakub Sitnicki <jakub@cloudflare.com>
Signed-off-by: default avatarMartin KaFai Lau <martin.lau@kernel.org>
Link: https://patch.msgid.link/20251105-skb-meta-rx-path-v4-15-5ceb08a9b37b@cloudflare.com
parent 29960e63
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -497,6 +497,11 @@ void test_xdp_context_tuntap(void)
			    skel->progs.helper_skb_adjust_room,
			    NULL, /* tc prio 2 */
			    &skel->bss->test_pass);
	if (test__start_subtest("helper_skb_change_head_tail"))
		test_tuntap(skel->progs.ing_xdp,
			    skel->progs.helper_skb_change_head_tail,
			    NULL, /* tc prio 2 */
			    &skel->bss->test_pass);

	test_xdp_meta__destroy(skel);
}
+34 −0
Original line number Diff line number Diff line
@@ -611,4 +611,38 @@ int helper_skb_adjust_room(struct __sk_buff *ctx)
	return TC_ACT_SHOT;
}

SEC("tc")
int helper_skb_change_head_tail(struct __sk_buff *ctx)
{
	int err;

	/* Reserve 1 extra in the front for packet data */
	err = bpf_skb_change_head(ctx, 1, 0);
	if (err)
		goto out;

	if (!check_skb_metadata(ctx))
		goto out;

	/* Reserve 256 extra bytes in the front to trigger head reallocation */
	err = bpf_skb_change_head(ctx, 256, 0);
	if (err)
		goto out;

	if (!check_skb_metadata(ctx))
		goto out;

	/* Reserve 4k extra bytes in the back to trigger head reallocation */
	err = bpf_skb_change_tail(ctx, ctx->len + 4096, 0);
	if (err)
		goto out;

	if (!check_skb_metadata(ctx))
		goto out;

	test_pass = true;
out:
	return TC_ACT_SHOT;
}

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