From: Jiayuan Chen <jiayuan.chen@linux.dev>
To: sashiko-reviews@lists.linux.dev
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf v3 1/2] bpf, veth: xdp: fix page_pool page leak on skb-backed XDP
Date: Sat, 12 Sep 2026 10:28:11 +0800 [thread overview]
Message-ID: <c8069a81-d9f1-4f0a-a0e0-58300080557a@linux.dev> (raw)
In-Reply-To: <20260911143643.402B51F000FF@smtp.kernel.org>
On 9/11/26 10:36 PM, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
>
> Pre-existing issues:
> - [High] veth_xdp_rcv_one() overwrites shared per-queue rq->xdp_rxq.mem.type state, corrupting subsequent SKB processing in the same NAPI poll and causing kernel panics.
> --
>
> commit 6d121019cfea2f329267400ac7c2525a49f34f53
> Author: Jiayuan Chen <jiayuan.chen@linux.dev>
>
> bpf, veth: xdp: fix page_pool page leak on skb-backed XDP
>
> bpf_xdp_shrink_data() frees a released frag via __xdp_return() using
> xdp->rxq->mem.type, but that type is wrong for skb-backed XDP: the skb is
> cow'd into page_pool memory while the rxq still says MEM_TYPE_PAGE_SHARED.
> This fixes the resulting page pool panics by recording the memory type in
> the xdp_buff flags instead.
>
>> diff --git a/drivers/net/veth.c b/drivers/net/veth.c
>> index 6ed3ee81153fb..a3fdf1959b76c 100644
>> --- a/drivers/net/veth.c
>> +++ b/drivers/net/veth.c
>> @@ -775,6 +775,12 @@ static int veth_convert_skb_to_xdp_buff(struct veth_rq *rq,
>> if (skb_shinfo(skb)->nr_frags) {
>> skb_shinfo(skb)->xdp_frags_size = skb->data_len;
>> xdp_buff_set_frags_flag(xdp);
>> + /*
>> + * A nonlinear skb was cow'd into rq->page_pool above, so the
>> + * frags must be freed to that pool, not via the rxq's
>> + * MEM_TYPE_PAGE_SHARED.
>> + */
>> + xdp_buff_set_frag_pp(xdp);
>> } else {
>> xdp_buff_clear_frags_flag(xdp);
>> }
> [Severity: High]
> This isn't a bug introduced by this patch, but can the shared per-queue memory
> type state be clobbered during a mixed batch?
>
> In veth_xdp_rcv_one(), the shared rq->xdp_rxq.mem.type state is overwritten
> with the incoming frame's type without being restored:
>
> veth_xdp_rcv_one() {
> ...
> case XDP_REDIRECT:
> orig_frame = *frame;
> xdp->rxq->mem.type = frame->mem_type;
> ...
> }
>
> If a single NAPI poll (veth_xdp_rcv) processes a batch containing a native
> xdp_frame (e.g. MEM_TYPE_XSK_BUFF_POOL) followed by a standard sk_buff, the
The premise doesn't hold here: frame->mem_type is never
MEM_TYPE_XSK_BUFF_POOL.
A zc buff gets copied out before it can ever become a frame.
xdp_convert_buff_to_frame() sends
every XSK buff to xdp_convert_zc_to_xdp_frame(), and that one does:
xdpf->mem_type = MEM_TYPE_PAGE_ORDER0;
xsk_buff_free(xdp);
so the plain "xdp_frame->mem_type = xdp->rxq->mem.type" further down
only ever sees non-XSK types.
I grepped the tree and the only things that ever end up in a frame's
mem_type are PAGE_SHARED,
PAGE_POOL and PAGE_ORDER0. So "xdp->rxq->mem.type = frame->mem_type" in
veth_xdp_rcv_one() can't put
XSK in there, and the XSK branch in bpf_xdp_shrink_data() is simply not
reachable from veth.
> next packet will be processed with the clobbered rxq->mem.type.
>
> When veth_xdp_rcv_skb() processes the subsequent sk_buff, the BPF program
> is executed with this clobbered state:
>
> veth_xdp_rcv_skb() {
> ...
> act = bpf_prog_run_xdp(xdp_prog, xdp);
> ...
> }
>
> If this clobbered memory type is read by helpers like bpf_xdp_shrink_data(),
> could it lead to a kernel panic? For instance, if clobbered to XSK_BUFF_POOL,
> it would erroneously call xsk_buff_free() on a standard xdp_buff, resulting
> in a garbage dereference.
>
next prev parent reply other threads:[~2026-09-12 2:28 UTC|newest]
Thread overview: 8+ 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 [this message]
2026-09-13 13:05 ` Lorenzo Bianconi
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
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=c8069a81-d9f1-4f0a-a0e0-58300080557a@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