]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
selftests/bpf: Cover skb metadata access after change_head/tail helper
authorJakub Sitnicki <jakub@cloudflare.com>
Wed, 5 Nov 2025 20:19:52 +0000 (21:19 +0100)
committerMartin KaFai Lau <martin.lau@kernel.org>
Mon, 10 Nov 2025 18:52:33 +0000 (10:52 -0800)
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: Jakub Sitnicki <jakub@cloudflare.com>
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
Link: https://patch.msgid.link/20251105-skb-meta-rx-path-v4-15-5ceb08a9b37b@cloudflare.com
tools/testing/selftests/bpf/prog_tests/xdp_context_test_run.c
tools/testing/selftests/bpf/progs/test_xdp_meta.c

index a3b82cf2f9e9b40b92782779e2cdc325204c9756..65735a134abb85c8a7b363a3853175592053da36 100644 (file)
@@ -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);
 }
index 6edc84d8dc52cf416f4c0772a2d78137e04a6364..e0b2e8ed0cc5108e5818f042367d35f75ae03d22 100644 (file)
@@ -611,4 +611,38 @@ out:
        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";