Skip to content

Commit c7f0c4b

Browse files
jsitnickiKernel Patches Daemon
authored andcommitted
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: Jakub Sitnicki <[email protected]>
1 parent fbac966 commit c7f0c4b

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

tools/testing/selftests/bpf/prog_tests/xdp_context_test_run.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,11 @@ void test_xdp_context_tuntap(void)
497497
skel->progs.helper_skb_adjust_room,
498498
NULL, /* tc prio 2 */
499499
&skel->bss->test_pass);
500+
if (test__start_subtest("helper_skb_change_head_tail"))
501+
test_tuntap(skel->progs.ing_xdp,
502+
skel->progs.helper_skb_change_head_tail,
503+
NULL, /* tc prio 2 */
504+
&skel->bss->test_pass);
500505

501506
test_xdp_meta__destroy(skel);
502507
}

tools/testing/selftests/bpf/progs/test_xdp_meta.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,4 +611,38 @@ int helper_skb_adjust_room(struct __sk_buff *ctx)
611611
return TC_ACT_SHOT;
612612
}
613613

614+
SEC("tc")
615+
int helper_skb_change_head_tail(struct __sk_buff *ctx)
616+
{
617+
int err;
618+
619+
/* Reserve 1 extra in the front for packet data */
620+
err = bpf_skb_change_head(ctx, 1, 0);
621+
if (err)
622+
goto out;
623+
624+
if (!check_skb_metadata(ctx))
625+
goto out;
626+
627+
/* Reserve 256 extra bytes in the front to trigger head reallocation */
628+
err = bpf_skb_change_head(ctx, 256, 0);
629+
if (err)
630+
goto out;
631+
632+
if (!check_skb_metadata(ctx))
633+
goto out;
634+
635+
/* Reserve 4k extra bytes in the back to trigger head reallocation */
636+
err = bpf_skb_change_tail(ctx, ctx->len + 4096, 0);
637+
if (err)
638+
goto out;
639+
640+
if (!check_skb_metadata(ctx))
641+
goto out;
642+
643+
test_pass = true;
644+
out:
645+
return TC_ACT_SHOT;
646+
}
647+
614648
char _license[] SEC("license") = "GPL";

0 commit comments

Comments
 (0)