Netdev List
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: bjorn@kernel.org
Cc: magnus.karlsson@intel.com, maciej.fijalkowski@intel.com,
	aleksander.lobakin@intel.com, ast@kernel.org,
	daniel@iogearbox.net, hawk@kernel.org, john.fastabend@gmail.com,
	andrii@kernel.org, eddyz87@gmail.com, memxor@gmail.com,
	davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
	pabeni@redhat.com, willemb@google.com, netdev@vger.kernel.org,
	bpf@vger.kernel.org, horms@kernel.org, sdf@fomichev.me,
	martin.lau@linux.dev, song@kernel.org, yonghong.song@linux.dev,
	jolsa@kernel.org, emil@etsalapatis.com, ihor.solodrai@linux.dev,
	anthony.l.nguyen@intel.com, przemyslaw.kitszel@intel.com,
	intel-wired-lan@lists.osuosl.org, clecigne@google.com
Subject: Re: [PATCH net v2 2/4] xdp: Size zero-copy skbs from the data, not the frame size
Date: Tue, 01 Dec 2026 12:39:16 +0000	[thread overview]
Message-ID: <179612875635.3146.8031227810272631513@kernel.org> (raw)
In-Reply-To: <20261130123737.125432-3-bjorn@kernel.org>

Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 0

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [Medium] The commit message makes the overflow fixed by this patch look
  narrower than it is.

--

xdp: Size zero-copy skbs from the data, not the frame size

This commit changes xdp_build_skb_from_zc() to size the skb head from the
data instead of the XSk frame size, so long packets no longer overwrite
the skb shared info. It also stops rounding the head and fragment copies
up with LARGEST_ALIGN(). Heads that do not fit in a page now get a
kmalloc'd head from __netdev_alloc_skb().

Link: https://lore.kernel.org/bpf/20260629072300.1664622-1-clecigne@google.com/

> xdp_build_skb_from_zc() gives the skb head the frame size of the XSk
> buffer, and the skb shared info takes the end of it. A device may fill
> a single-buffer XSk frame to its end, so a long packet overwrites the
> shared info of the new skb with packet data. For example, with 4K
> chunks, MTU 3800, an xdp.frags program that returns XDP_PASS and a
> socket bound without XDP_USE_SG, a 3814 byte frame needs 256 + 3814 +
> 320 = 4390 bytes and gets 4096. The last patch of this series lets
> multi-buffer pools and bpf_xdp_adjust_tail() reach the end of the
> frame as well.

[ ... ]

> Reported by Clément Lecigne, and found again by an AI code review
> agent. Reproduced only with out-of-tree code: a test module, and the
> AF_XDP page-pool RFC on fbnic in QEMU.

[Severity: Medium]
Does this description make the overflow look harder to hit than it is?

The example needs 4K chunks, MTU 3800, an xdp.frags program and a non-SG
socket. In the baseline tree, the old xdp_build_skb_from_zc() also seems
to overflow with a common setup:

  - 2K chunks
  - no UMEM headroom
  - the default 1500 MTU
  - any XDP program that returns XDP_PASS on a zero-copy queue

No frags program is needed.

In-tree drivers reach this function on every XDP_PASS:

  ice_clean_rx_irq_zc()->xdp_build_skb_from_zc()
  __libeth_xsk_run_pass()->xdp_build_skb_from_zc()   (idpf via libeth)
  gve_rx_xsk_dqo()->xdp_build_skb_from_zc()

The pool sizes for that setup come from here:

net/xdp/xsk_buff_pool.c:xp_create_and_assign_umem() {
    ...
    pool->frame_len = umem->chunk_size - umem->headroom -
        XDP_PACKET_HEADROOM;
    ...
    xskb->xdp.frame_sz = umem->chunk_size - umem->headroom;
    ...
}

This gives frame_sz = 2048 and frame_len = 1792.

For a pool without XDP_UMEM_SG_FLAG, xsk_pool_get_rx_frame_size() reserves
no tailroom. It returns ALIGN_DOWN(1792, 128) = 1792, and libeth gives
that to the device as fq->buf_len.

The old code then did:

    u32 truesize = xdp->frame_sz;
    ...
    skb = napi_build_skb(data, truesize);
    ...
    skb_reserve(skb, xdp->data_meta - xdp->data_hard_start);
    memcpy(__skb_put(skb, len), xdp->data_meta, LARGEST_ALIGN(len));

The system page pool returns a 2048-byte fragment. Then
napi_build_skb()->__finalize_skb_around() puts skb->end at
2048 - 320 = 1728.

skb_reserve(256) plus __skb_put(1514) moves tail to 1770. The memcpy() of
LARGEST_ALIGN(1514) = 1520 bytes then writes up to offset 1776.

That overwrites 48 bytes of the skb_shared_info that was just initialised
(nr_frags, frag_list, gso_*, dataref, destructor_arg). The sender of any
full-size 1500 MTU frame controls those bytes.

The new code handles this case: size = 1770, SKB_HEAD_ALIGN(1770) = 2112,
and end = 1792. The concern is only with the changelog.

Could the commit message describe the 2K chunk / standard MTU case on
in-tree drivers and the remote memory corruption impact? It currently
says "Reproduced only with out-of-tree code". The fuller description
would help stable and CVE triage judge how urgent the fix is.

The changelogs of the later patches in the series, "intel: Copy the exact
length of XSk packets to skbs" and "xsk: Keep the shared info of zero-copy
buffers in kernel memory", don't seem to cover this case either.

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261130123737.125432-1-bjorn%40kernel.org

  parent reply	other threads:[~2026-12-01 12:39 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30 12:37 [PATCH net v2 0/4] xsk: Keep the shared info of zero-copy buffers in kernel memory Björn Töpel
2026-11-30 12:37 ` [PATCH net v2 1/4] libeth: xsk: Count each XDP_TX buffer on its own Björn Töpel
2026-11-30 16:41   ` Alexander Lobakin
2026-12-01 12:39   ` netdev-bot+sashiko
2026-11-30 12:37 ` [PATCH net v2 2/4] xdp: Size zero-copy skbs from the data, not the frame size Björn Töpel
2026-11-30 16:54   ` Alexander Lobakin
2026-12-01  7:12     ` Björn Töpel
2026-12-01 12:39   ` netdev-bot+sashiko [this message]
2026-11-30 12:37 ` [PATCH net v2 3/4] intel: Copy the exact length of XSk packets to skbs Björn Töpel
2026-11-30 16:56   ` Alexander Lobakin
2026-11-30 12:37 ` [PATCH net v2 4/4] xsk: Keep the shared info of zero-copy buffers in kernel memory Björn Töpel
2026-12-01 12:39   ` netdev-bot+sashiko

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=179612875635.3146.8031227810272631513@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=aleksander.lobakin@intel.com \
    --cc=andrii@kernel.org \
    --cc=anthony.l.nguyen@intel.com \
    --cc=ast@kernel.org \
    --cc=bjorn@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=clecigne@google.com \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=eddyz87@gmail.com \
    --cc=edumazet@kernel.org \
    --cc=emil@etsalapatis.com \
    --cc=hawk@kernel.org \
    --cc=horms@kernel.org \
    --cc=ihor.solodrai@linux.dev \
    --cc=intel-wired-lan@lists.osuosl.org \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kuba@kernel.org \
    --cc=maciej.fijalkowski@intel.com \
    --cc=magnus.karlsson@intel.com \
    --cc=martin.lau@linux.dev \
    --cc=memxor@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=przemyslaw.kitszel@intel.com \
    --cc=sdf@fomichev.me \
    --cc=song@kernel.org \
    --cc=willemb@google.com \
    --cc=yonghong.song@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