bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jiayuan Chen <jiayuan.chen@linux.dev>
To: sashiko-reviews@lists.linux.dev
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf v3 2/2] selftests/bpf: add xdp_shrink_frags
Date: Sat, 12 Sep 2026 10:34:13 +0800	[thread overview]
Message-ID: <649ddc23-81b1-40e0-87aa-ff0821a33c34@linux.dev> (raw)
In-Reply-To: <20260911144631.A7A4C1F000FF@smtp.kernel.org>


On 9/11/26 10:46 PM, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> - [Medium] Type punning a byte array into a struct pointer violates strict aliasing rules.
> --
>
> commit 7d6829eaaf619b188a1baf1e3f7bf91fc5a0a765
> Author: Jiayuan Chen <jiayuan.chen@linux.dev>
>
> selftests/bpf: add xdp_shrink_frags
>
> This commit adds a BPF selftest for XDP that shrinks fragments and
> triggers a page_pool leak on a generic XDP path. The test exercises
> test_tun, test_veth, and test_veth_tx to cover different data path
> behaviors on 4K pages.
>
>> diff --git a/tools/testing/selftests/bpf/prog_tests/xdp_shrink_frags.c b/tools/testing/selftests/bpf/prog_tests/xdp_shrink_frags.c
>> new file mode 100644
>> index 0000000000000..ee8f9034a2684
>> --- /dev/null
>> +++ b/tools/testing/selftests/bpf/prog_tests/xdp_shrink_frags.c
> [ ... ]
>> +static void test_tun(struct xdp_shrink_frags *skel)
>> +{
>> +	__u8 head[74], frag1[2048], frag2[2048];
>> +	struct ethhdr *eth = (void *)head;
>> +	int tap_fd = -1, ifindex, err;
>> +	struct netns_obj *ns = NULL;
>> +	struct iovec iov[3];
>> +	ssize_t n;
> [ ... ]
>> +	memset(head, 0, sizeof(head));
>> +	memset(frag1, 0x41, sizeof(frag1));
>> +	memset(frag2, 0x42, sizeof(frag2));
>> +	eth->h_proto = htons(ETH_P_IP);
> [Severity: Medium]
> Does this code violate strict aliasing rules by type-punning a byte array
> into a struct pointer?
>
> When test_tun() executes, it accesses an object declared as an array of
> characters (__u8) through an unrelated larger struct pointer (struct ethhdr *).


I don't think there is anything wrong with

     struct foo *ptr = (struct foo *)binary


it's a pretty normal thing to do, and other tests in the same directory 
do exactly the same:

     prog_tests/xdp_context_test_run.c

     __u8 pkt[...];

     struct ethhdr *eth = (void *)pkt;

     struct ipv6hdr *ip6 = (void *)(eth + 1);

     ....


Not sure why the AI complains about this one.


> Since this code is located in a test program running in user space (under
> tools/), standard -fstrict-aliasing rules apply.
>
> Could the compiler assume that eth does not alias head, leading it to reorder
> or drop the write to eth->h_proto entirely during optimization?
>
>> +
>> +	iov[0].iov_base = head;  iov[0].iov_len = sizeof(head);
>> +	iov[1].iov_base = frag1; iov[1].iov_len = sizeof(frag1);
>> +	iov[2].iov_base = frag2; iov[2].iov_len = sizeof(frag2);
> [ ... ]
>

      reply	other threads:[~2026-09-12  2:34 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-11 13:56 [PATCH bpf v3 0/2] net: xdp: fix bpf_xdp_shrink_data() page handling on generic XDP and veth Jiayuan Chen
2026-09-11 13:56 ` [PATCH bpf v3 1/2] bpf, veth: xdp: fix page_pool page leak on skb-backed XDP Jiayuan Chen
2026-09-11 14:36   ` sashiko-bot
2026-09-12  2:28     ` Jiayuan Chen
2026-09-13 13:05   ` Lorenzo Bianconi
2026-09-14  8:46     ` Jiayuan Chen
2026-09-11 13:56 ` [PATCH bpf v3 2/2] selftests/bpf: add xdp_shrink_frags Jiayuan Chen
2026-09-11 14:46   ` sashiko-bot
2026-09-12  2:34     ` Jiayuan Chen [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=649ddc23-81b1-40e0-87aa-ff0821a33c34@linux.dev \
    --to=jiayuan.chen@linux.dev \
    --cc=bpf@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).