Netdev List
 help / color / mirror / Atom feed
* [PATCH net v2 0/4] xsk: Keep the shared info of zero-copy buffers in kernel memory
@ 2026-11-30 12:37 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
                   ` (3 more replies)
  0 siblings, 4 replies; 16+ messages in thread
From: Björn Töpel @ 2026-11-30 12:37 UTC (permalink / raw)
  To: Magnus Karlsson, Maciej Fijalkowski, Alexander Lobakin,
	Alexei Starovoitov, Daniel Borkmann, Jesper Dangaard Brouer,
	John Fastabend, Andrii Nakryiko, Eduard Zingerman,
	Kumar Kartikeya Dwivedi, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Willem de Bruijn, netdev, bpf
  Cc: Björn Töpel, Simon Horman, Stanislav Fomichev,
	Martin KaFai Lau, Song Liu, Yonghong Song, Jiri Olsa,
	Emil Tsalapatis, Ihor Solodrai, Tony Nguyen, Przemek Kitszel,
	intel-wired-lan, Clément Lecigne

A packet that AF_XDP receives in zero-copy mode over several buffers
keeps its shared info, the fragment list and its count, in the UMEM,
which userspace can write while the kernel uses it. A rewritten list
or count makes the kernel read and write out of bounds.

Patch 4 moves the shared info into the buffer pool and lets the device
write up to the end of each chunk. Patch 1 makes libeth count XSk
XDP_TX buffers one by one, as it read the shared info at a later bulk
flush. Patches 2 and 3 fix skb builders that relied on the old
tailroom: the generic one sized the skb head from the frame size, and
i40e, igb, igc and ixgbe read past the data.

Sashiko found the shared info issue in its review of the AF_XDP device
buffer layout series [1], and the issues fixed by patches 2 and 3 in
its review of v1. Clément reported the issue of patch 2 earlier [2].
Patch 3 was reproduced on igb in QEMU; the others were not triggered
at runtime.

I tested this on mlx5 hardware, and on igb, virtio-net and veth in
QEMU. None of them receives multi-buffer packets in zero copy or uses
the generic skb builder, so i40e, ice, idpf and gve are only
build-tested. Intel folks, could you run your multi-buffer zero-copy
tests on them?

Also for Intel, found while auditing the drivers and not touched here:
ice no longer sizes its zero-copy RX buffers from the XSK pool. Commit
3a4f419f7509 ("ice: drop page splitting and recycling") programmed a
fixed 3072 bytes, and 93f53db9f9dc ("ice: switch to Page Pool")
changed ice_setup_rx_ctx() to use ring->rx_buf_len, which only the
page pool path sets. An XSK ring gets the length of its last page pool
setup, 3456 bytes on 4K pages, or 0 if it never had one. With 2K
chunks the device can write past the chunk into the next one. I found
this by reading the code and did not test it.

Changes in v2:
- Patch 1: fix the kernel-doc of struct libeth_sqe (Sashiko)
- New patch 2: size zero-copy skbs from the data, and copy the exact
  length (Sashiko, Clément)
- New patch 3: copy the exact length in i40e, igb, igc and ixgbe
  (Sashiko)
- Patch 4: set the flag on every buffer when the pool is created, and
  again in xp_alloc() and xsk_buff_set_size(), as virtio_net clears
  the flags of some buffers (Sashiko)
- Patch 4: publish the shared info before the buffers point to the
  queue (Sashiko)
- Patch 4: update the comment in bpf_xdp_adjust_tail() (Sashiko)
- Drop the selftest patch, it goes to net-next once net is merged
  (Maciej)
- The libeth XDP_TX completion count that Sashiko found going the
  wrong way is older and unrelated to the shared info; Separate fix

v1: https://lore.kernel.org/netdev/20261127142131.3527737-1-bjorn@kernel.org/

[1] https://lore.kernel.org/netdev/179561567996.3135.9952128421877275714@kernel.org/
[2] https://lore.kernel.org/bpf/20260629072300.1664622-1-clecigne@google.com/

Björn Töpel (4):
  libeth: xsk: Count each XDP_TX buffer on its own
  xdp: Size zero-copy skbs from the data, not the frame size
  intel: Copy the exact length of XSk packets to skbs
  xsk: Keep the shared info of zero-copy buffers in kernel memory

 drivers/net/ethernet/intel/i40e/i40e_xsk.c   |  3 +-
 drivers/net/ethernet/intel/igb/igb_xsk.c     |  3 +-
 drivers/net/ethernet/intel/igc/igc_main.c    |  3 +-
 drivers/net/ethernet/intel/ixgbe/ixgbe_xsk.c |  3 +-
 include/net/libeth/tx.h                      |  8 ++--
 include/net/libeth/xdp.h                     |  9 ++++-
 include/net/libeth/xsk.h                     |  6 ++-
 include/net/xdp.h                            | 32 +++++++++++++---
 include/net/xdp_sock_drv.h                   | 26 +++----------
 include/net/xsk_buff_pool.h                  |  1 +
 net/core/filter.c                            |  2 +-
 net/core/xdp.c                               | 40 ++++++++++++++------
 net/xdp/xdp_umem.c                           |  3 +-
 net/xdp/xsk_buff_pool.c                      | 20 ++++++----
 14 files changed, 96 insertions(+), 63 deletions(-)


base-commit: e2fb9368a41662bc54624f9be87ea8989b109306
-- 
2.56.1


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH net v2 1/4] libeth: xsk: Count each XDP_TX buffer on its own
  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 ` 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
                   ` (2 subsequent siblings)
  3 siblings, 2 replies; 16+ messages in thread
From: Björn Töpel @ 2026-11-30 12:37 UTC (permalink / raw)
  To: Magnus Karlsson, Maciej Fijalkowski, Alexander Lobakin,
	Alexei Starovoitov, Daniel Borkmann, Jesper Dangaard Brouer,
	John Fastabend, Andrii Nakryiko, Eduard Zingerman,
	Kumar Kartikeya Dwivedi, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Willem de Bruijn, netdev, bpf
  Cc: Björn Töpel, Simon Horman, Stanislav Fomichev,
	Martin KaFai Lau, Song Liu, Yonghong Song, Jiri Olsa,
	Emil Tsalapatis, Ihor Solodrai, Tony Nguyen, Przemek Kitszel,
	intel-wired-lan, Clément Lecigne

libeth takes the number of buffers of an XSk XDP_TX frame from its
shared info, and reports that many completed buffers to the driver. It
reads the shared info when it flushes the bulk, not when it queues the
frame. The shared info of a zero-copy buffer lives in the UMEM, which
userspace may write at any time, so a rewritten count makes libeth
report a wrong number. Once the last patch of this series moves the
shared info into the buffer pool, the next multi-buffer frame of the
same poll can overwrite it before the flush.

A wrong number breaks the in-flight count of XDP_TX buffers that idpf
keeps on its XSk queues, and idpf may then complete XDP_TX buffers as
XSk xmit frames.

Make libeth count each buffer on its own SQE. Head and fragments each
count one completed buffer, and the head counts the packet. Stats stay
the same for frames sent in full.

Found by an AI agent while reviewing this code. Not triggered at
runtime.

Fixes: b3ad8450b4dc ("libeth: xsk: add XSk XDP_TX sending helpers")
Signed-off-by: Björn Töpel <bjorn@kernel.org>
---
 include/net/libeth/tx.h  | 8 +++++---
 include/net/libeth/xdp.h | 9 ++++++++-
 include/net/libeth/xsk.h | 6 ++++--
 3 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/include/net/libeth/tx.h b/include/net/libeth/tx.h
index c3db5c6f1641..a8cf03c8be71 100644
--- a/include/net/libeth/tx.h
+++ b/include/net/libeth/tx.h
@@ -22,7 +22,8 @@
  * @LIBETH_SQE_XDP_XMIT: &xdp_frame, unmap and xdp_return_frame_bulk(), stats
  * @LIBETH_SQE_XDP_XMIT_FRAG: &xdp_frame frag, only unmap DMA
  * @LIBETH_SQE_XSK_TX: &libeth_xdp_buff on XSk queue, xsk_buff_free(), stats
- * @LIBETH_SQE_XSK_TX_FRAG: &libeth_xdp_buff frag on XSk queue, xsk_buff_free()
+ * @LIBETH_SQE_XSK_TX_FRAG: &libeth_xdp_buff frag on XSk queue, xsk_buff_free(),
+ *			    stats
  */
 enum libeth_sqe_type {
 	LIBETH_SQE_EMPTY		= 0U,
@@ -50,9 +51,10 @@ enum libeth_sqe_type {
  * @xsk: XSk Rx frame from XDP_TX action
  * @dma: DMA address to unmap
  * @len: length of the mapped region to unmap
- * @nr_frags: number of frags in the frame this buffer belongs to
+ * @nr_frags: number of frags in the frame this buffer belongs to, not for XSk
  * @packets: number of physical packets sent for this frame
- * @bytes: number of physical bytes sent for this frame
+ * @bytes: number of physical bytes sent for this frame, or for this buffer
+ *	   on XSk
  * @priv: driver-private scratchpad
  */
 struct libeth_sqe {
diff --git a/include/net/libeth/xdp.h b/include/net/libeth/xdp.h
index 898723ab62e8..66a3c4ec9967 100644
--- a/include/net/libeth/xdp.h
+++ b/include/net/libeth/xdp.h
@@ -1794,12 +1794,19 @@ __libeth_xdp_complete_tx(struct libeth_sqe *sqe, struct libeth_cq_pp *cp,
 	switch (type) {
 	case LIBETH_SQE_XDP_TX:
 	case LIBETH_SQE_XDP_XMIT:
-	case LIBETH_SQE_XSK_TX:
 		cp->xdp_tx -= sqe->nr_frags;
 
 		cp->xss->packets++;
 		cp->xss->bytes += sqe->bytes;
 		break;
+	case LIBETH_SQE_XSK_TX:
+		cp->xss->packets++;
+		fallthrough;
+	case LIBETH_SQE_XSK_TX_FRAG:
+		/* One buffer per SQE, see libeth_xsk_tx_fill_buf() */
+		cp->xdp_tx--;
+		cp->xss->bytes += sqe->bytes;
+		break;
 	default:
 		break;
 	}
diff --git a/include/net/libeth/xsk.h b/include/net/libeth/xsk.h
index 249b1c740788..2cd4252a3445 100644
--- a/include/net/libeth/xsk.h
+++ b/include/net/libeth/xsk.h
@@ -129,6 +129,10 @@ libeth_xsk_tx_fill_buf(struct libeth_xdp_tx_frame frm, u32 i,
 
 	sqe = &sq->sqes[i];
 	sqe->xsk = xdp;
+	/* Count each buffer on its own SQE. The shared info of the frame
+	 * may change before the bulk is flushed.
+	 */
+	sqe->bytes = desc.len;
 
 	if (!(desc.flags & LIBETH_XDP_TX_FIRST)) {
 		sqe->type = LIBETH_SQE_XSK_TX_FRAG;
@@ -136,8 +140,6 @@ libeth_xsk_tx_fill_buf(struct libeth_xdp_tx_frame frm, u32 i,
 	}
 
 	sqe->type = LIBETH_SQE_XSK_TX;
-	libeth_xdp_tx_fill_stats(sqe, &desc,
-				 xdp_get_shared_info_from_buff(&xdp->base));
 
 	return desc;
 }
-- 
2.56.1


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH net v2 2/4] xdp: Size zero-copy skbs from the data, not the frame size
  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 12:37 ` Björn Töpel
  2026-11-30 16:54   ` Alexander Lobakin
  2026-12-01 12:39   ` netdev-bot+sashiko
  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 12:37 ` [PATCH net v2 4/4] xsk: Keep the shared info of zero-copy buffers in kernel memory Björn Töpel
  3 siblings, 2 replies; 16+ messages in thread
From: Björn Töpel @ 2026-11-30 12:37 UTC (permalink / raw)
  To: Magnus Karlsson, Maciej Fijalkowski, Alexander Lobakin,
	Alexei Starovoitov, Daniel Borkmann, Jesper Dangaard Brouer,
	John Fastabend, Andrii Nakryiko, Eduard Zingerman,
	Kumar Kartikeya Dwivedi, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Willem de Bruijn, netdev, bpf
  Cc: Björn Töpel, Simon Horman, Stanislav Fomichev,
	Martin KaFai Lau, Song Liu, Yonghong Song, Jiri Olsa,
	Emil Tsalapatis, Ihor Solodrai, Tony Nguyen, Przemek Kitszel,
	intel-wired-lan, Clément Lecigne

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.

The copies of the head and of the fragments also round the length up
to 16 bytes, and read and write past the end of the data.

Size the head from the data, and copy the exact length. A head that
does not fit into a page of the system page pool, such as one that
fills a whole 4K chunk, gets a kmalloc'd head from
__netdev_alloc_skb() instead.

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.

Reported-by: Clément Lecigne <clecigne@google.com>
Link: https://lore.kernel.org/bpf/20260629072300.1664622-1-clecigne@google.com/
Fixes: 560d958c6c68 ("xsk: add generic XSk &xdp_buff -> skb conversion")
Signed-off-by: Björn Töpel <bjorn@kernel.org>
---
 net/core/xdp.c | 40 ++++++++++++++++++++++++++++------------
 1 file changed, 28 insertions(+), 12 deletions(-)

diff --git a/net/core/xdp.c b/net/core/xdp.c
index 1d679e8fd649..33a6740b411f 100644
--- a/net/core/xdp.c
+++ b/net/core/xdp.c
@@ -709,7 +709,7 @@ static noinline bool xdp_copy_frags_from_zc(struct sk_buff *skb,
 		}
 
 		memcpy(page_address(page) + offset, skb_frag_address(frag),
-		       LARGEST_ALIGN(len));
+		       len);
 		__skb_fill_page_desc_noacc(sinfo, i, page, offset, len);
 
 		tsize += truesize;
@@ -723,6 +723,27 @@ static noinline bool xdp_copy_frags_from_zc(struct sk_buff *skb,
 	return true;
 }
 
+static struct sk_buff *xdp_zc_alloc_head(struct page_pool *pp,
+					 struct net_device *dev, u32 size)
+{
+	u32 truesize = SKB_HEAD_ALIGN(size);
+	struct sk_buff *skb;
+	void *data;
+
+	if (truesize > PAGE_SIZE)
+		return __netdev_alloc_skb(dev, size, GFP_ATOMIC | __GFP_NOWARN);
+
+	data = page_pool_dev_alloc_va(pp, &truesize);
+	if (unlikely(!data))
+		return NULL;
+
+	skb = napi_build_skb(data, truesize);
+	if (unlikely(!skb))
+		page_pool_free_va(pp, data, true);
+
+	return skb;
+}
+
 /**
  * xdp_build_skb_from_zc - create an skb from XSk &xdp_buff
  * @xdp: source XSk buff
@@ -730,7 +751,8 @@ static noinline bool xdp_copy_frags_from_zc(struct sk_buff *skb,
  * Similar to xdp_build_skb_from_buff(), but for XSk frames. Allocate an skb
  * head, new buffer for the head, copy the data and initialize the skb fields.
  * If there are frags, allocate new buffers for them and copy.
- * Buffers are allocated from the system percpu pools to try recycling them.
+ * Buffers are allocated from the system percpu pools to try recycling them,
+ * except a head that does not fit into a page.
  * If new skb was built successfully, @xdp is returned to XSk pool's freelist.
  * On error, it remains untouched and the caller must take care of this.
  *
@@ -738,33 +760,27 @@ static noinline bool xdp_copy_frags_from_zc(struct sk_buff *skb,
  */
 struct sk_buff *xdp_build_skb_from_zc(struct xdp_buff *xdp)
 {
+	u32 size = xdp->data_end - xdp->data_hard_start;
 	const struct xdp_rxq_info *rxq = xdp->rxq;
 	u32 len = xdp->data_end - xdp->data_meta;
-	u32 truesize = xdp->frame_sz;
 	struct sk_buff *skb = NULL;
 	struct page_pool *pp;
 	int metalen;
-	void *data;
 
 	if (!IS_ENABLED(CONFIG_PAGE_POOL))
 		return NULL;
 
 	local_lock_nested_bh(&system_page_pool.bh_lock);
 	pp = this_cpu_read(system_page_pool.pool);
-	data = page_pool_dev_alloc_va(pp, &truesize);
-	if (unlikely(!data))
-		goto out;
 
-	skb = napi_build_skb(data, truesize);
-	if (unlikely(!skb)) {
-		page_pool_free_va(pp, data, true);
+	skb = xdp_zc_alloc_head(pp, rxq->dev, size);
+	if (unlikely(!skb))
 		goto out;
-	}
 
 	skb_mark_for_recycle(skb);
 	skb_reserve(skb, xdp->data_meta - xdp->data_hard_start);
 
-	memcpy(__skb_put(skb, len), xdp->data_meta, LARGEST_ALIGN(len));
+	memcpy(__skb_put(skb, len), xdp->data_meta, len);
 
 	metalen = xdp->data - xdp->data_meta;
 	if (metalen > 0) {
-- 
2.56.1


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH net v2 3/4] intel: Copy the exact length of XSk packets to skbs
  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 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 12:37 ` 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
  3 siblings, 1 reply; 16+ messages in thread
From: Björn Töpel @ 2026-11-30 12:37 UTC (permalink / raw)
  To: Magnus Karlsson, Maciej Fijalkowski, Alexander Lobakin,
	Alexei Starovoitov, Daniel Borkmann, Jesper Dangaard Brouer,
	John Fastabend, Andrii Nakryiko, Eduard Zingerman,
	Kumar Kartikeya Dwivedi, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Willem de Bruijn, netdev, bpf
  Cc: Björn Töpel, Simon Horman, Stanislav Fomichev,
	Martin KaFai Lau, Song Liu, Yonghong Song, Jiri Olsa,
	Emil Tsalapatis, Ihor Solodrai, Tony Nguyen, Przemek Kitszel,
	intel-wired-lan, Clément Lecigne

i40e, igb, igc and ixgbe copy an XSk zero-copy packet that the XDP
program passes into a new skb, and round the length of the copy up to
a multiple of 8 bytes. The copy then reads up to 7 bytes past the end
of the data. When the data ends at the end of the last chunk of the
UMEM, the read hits the guard page after the UMEM mapping and faults.

On i40e the device can already fill a single-buffer chunk to its end.
The last patch of this series lets multi-buffer pools and
bpf_xdp_adjust_tail() reach the end of a chunk on all four.

Copy the exact length.

Found by an AI code review agent in review of this series. Reproduced
on igb in QEMU. An AF_XDP socket in zero copy with 4K chunks and only
the last chunk of the UMEM in the FILL ring, and an XDP program that
adds 4 bytes of metadata, grows the tail to the end of the chunk and
passes the packet:

  BUG: unable to handle page fault for address: ffa0000001048000
  RIP: 0010:memcpy+0xc/0x30
   igb_clean_rx_irq_zc+0x8a7/0x1520
   igb_poll+0x1039/0x4f50

With this patch the same test passes.

Fixes: 6dba29537c0f ("i40e: respect metadata on XSK Rx to skb")
Fixes: f322a620be69 ("ixgbe: respect metadata on XSK Rx to skb")
Fixes: f9e61d365baf ("igc: don't reserve excessive XDP_PACKET_HEADROOM on XSK Rx to skb")
Fixes: 2c6196013f84 ("igb: Add AF_XDP zero-copy Rx support")
Signed-off-by: Björn Töpel <bjorn@kernel.org>
---
 drivers/net/ethernet/intel/i40e/i40e_xsk.c   | 3 +--
 drivers/net/ethernet/intel/igb/igb_xsk.c     | 3 +--
 drivers/net/ethernet/intel/igc/igc_main.c    | 3 +--
 drivers/net/ethernet/intel/ixgbe/ixgbe_xsk.c | 3 +--
 4 files changed, 4 insertions(+), 8 deletions(-)

diff --git a/drivers/net/ethernet/intel/i40e/i40e_xsk.c b/drivers/net/ethernet/intel/i40e/i40e_xsk.c
index 5f5f33b2a097..03dd949a16b5 100644
--- a/drivers/net/ethernet/intel/i40e/i40e_xsk.c
+++ b/drivers/net/ethernet/intel/i40e/i40e_xsk.c
@@ -308,8 +308,7 @@ static struct sk_buff *i40e_construct_skb_zc(struct i40e_ring *rx_ring,
 	if (unlikely(!skb))
 		goto out;
 
-	memcpy(__skb_put(skb, totalsize), xdp->data_meta,
-	       ALIGN(totalsize, sizeof(long)));
+	memcpy(__skb_put(skb, totalsize), xdp->data_meta, totalsize);
 
 	if (metasize) {
 		skb_metadata_set(skb, metasize);
diff --git a/drivers/net/ethernet/intel/igb/igb_xsk.c b/drivers/net/ethernet/intel/igb/igb_xsk.c
index ce4a7b58cad2..aa00c36fe63f 100644
--- a/drivers/net/ethernet/intel/igb/igb_xsk.c
+++ b/drivers/net/ethernet/intel/igb/igb_xsk.c
@@ -280,8 +280,7 @@ static struct sk_buff *igb_construct_skb_zc(struct igb_ring *rx_ring,
 	if (timestamp)
 		skb_hwtstamps(skb)->hwtstamp = timestamp;
 
-	memcpy(__skb_put(skb, totalsize), xdp->data_meta,
-	       ALIGN(totalsize, sizeof(long)));
+	memcpy(__skb_put(skb, totalsize), xdp->data_meta, totalsize);
 
 	if (metasize) {
 		skb_metadata_set(skb, metasize);
diff --git a/drivers/net/ethernet/intel/igc/igc_main.c b/drivers/net/ethernet/intel/igc/igc_main.c
index 1fb5f3cbe93c..a3b153bbb081 100644
--- a/drivers/net/ethernet/intel/igc/igc_main.c
+++ b/drivers/net/ethernet/intel/igc/igc_main.c
@@ -2749,8 +2749,7 @@ static struct sk_buff *igc_construct_skb_zc(struct igc_ring *ring,
 	if (unlikely(!skb))
 		return NULL;
 
-	memcpy(__skb_put(skb, totalsize), xdp->data_meta,
-	       ALIGN(totalsize, sizeof(long)));
+	memcpy(__skb_put(skb, totalsize), xdp->data_meta, totalsize);
 
 	if (metasize) {
 		skb_metadata_set(skb, metasize);
diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_xsk.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_xsk.c
index 89f96c463f02..0d56466956c1 100644
--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_xsk.c
+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_xsk.c
@@ -224,8 +224,7 @@ static struct sk_buff *ixgbe_construct_skb_zc(struct ixgbe_ring *rx_ring,
 	if (unlikely(!skb))
 		return NULL;
 
-	memcpy(__skb_put(skb, totalsize), xdp->data_meta,
-	       ALIGN(totalsize, sizeof(long)));
+	memcpy(__skb_put(skb, totalsize), xdp->data_meta, totalsize);
 
 	if (metasize) {
 		skb_metadata_set(skb, metasize);
-- 
2.56.1


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH net v2 4/4] xsk: Keep the shared info of zero-copy buffers in kernel memory
  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
                   ` (2 preceding siblings ...)
  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 12:37 ` Björn Töpel
  2026-12-01 12:39   ` netdev-bot+sashiko
  3 siblings, 1 reply; 16+ messages in thread
From: Björn Töpel @ 2026-11-30 12:37 UTC (permalink / raw)
  To: Magnus Karlsson, Maciej Fijalkowski, Alexander Lobakin,
	Alexei Starovoitov, Daniel Borkmann, Jesper Dangaard Brouer,
	John Fastabend, Andrii Nakryiko, Eduard Zingerman,
	Kumar Kartikeya Dwivedi, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Willem de Bruijn, netdev, bpf
  Cc: Björn Töpel, Simon Horman, Stanislav Fomichev,
	Martin KaFai Lau, Song Liu, Yonghong Song, Jiri Olsa,
	Emil Tsalapatis, Ihor Solodrai, Tony Nguyen, Przemek Kitszel,
	intel-wired-lan, Clément Lecigne

A packet that a driver receives in zero-copy mode over several buffers
keeps its shared info, the fragment list and its count, in the
tailroom of the UMEM chunk of its head. Userspace may write the UMEM
at any time, also while the kernel walks the fragments, and a
rewritten list or count makes the kernel read and write out of bounds.

Keep the shared info in the buffer pool, which outlives its buffers
and the queues that point to it, and let the device write up to the
end of the chunk. One shared info per pool is enough, as a pool builds
one multi-buffer packet at a time. libeth read it later, at an XDP_TX
bulk flush, which an earlier patch of this series fixes.

Every buffer of a pool carries the flag from the start, and xp_alloc()
and xsk_buff_set_size() set it again, as a driver may clear the flags
of the buffers it receives into.

Multi-buffer pools now give the device the whole chunk, as
single-buffer pools already do. Every UMEM accepts a larger headroom,
also in copy mode, and bpf_xdp_adjust_tail() can grow a zero-copy
packet up to the end of its chunk.

Found by an AI code review agent, in its review of another series. Not
triggered at runtime.

Suggested-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
Fixes: 24ea50127ecf ("xsk: support mbuf on ZC RX")
Signed-off-by: Björn Töpel <bjorn@kernel.org>
---
 include/net/xdp.h           | 32 ++++++++++++++++++++++++++------
 include/net/xdp_sock_drv.h  | 26 ++++++--------------------
 include/net/xsk_buff_pool.h |  1 +
 net/core/filter.c           |  2 +-
 net/xdp/xdp_umem.c          |  3 +--
 net/xdp/xsk_buff_pool.c     | 20 ++++++++++++--------
 6 files changed, 47 insertions(+), 37 deletions(-)

diff --git a/include/net/xdp.h b/include/net/xdp.h
index 07231adfb5f8..052402766988 100644
--- a/include/net/xdp.h
+++ b/include/net/xdp.h
@@ -65,6 +65,10 @@ struct xdp_rxq_info {
 	u32 reg_state;
 	struct xdp_mem_info mem;
 	u32 frag_size;
+	/* Shared info of buffers with %XDP_FLAGS_SINFO_EXT, in the XSk buffer
+	 * pool, set by xsk_pool_set_rxq_info().
+	 */
+	struct skb_shared_info *ext_sinfo;
 } ____cacheline_aligned; /* perf critical, avoid false-sharing */
 
 struct xdp_txq_info {
@@ -81,6 +85,13 @@ enum xdp_buff_flags {
 	 * XDP program is not attached.
 	 */
 	XDP_FLAGS_FRAGS_UNREADABLE	= BIT(2),
+	/* The shared info lives in &xdp_rxq_info.ext_sinfo, not at the end of
+	 * the frame, as userspace may write the frame. The frame reserves no
+	 * tailroom, so the data may reach its end. The pool builds one such
+	 * buffer at a time, so a consumer that uses the shared info later
+	 * must copy what it needs.
+	 */
+	XDP_FLAGS_SINFO_EXT		= BIT(3),
 };
 
 struct xdp_buff {
@@ -178,17 +189,26 @@ xdp_prepare_buff(struct xdp_buff *xdp, unsigned char *hard_start,
 
 /* Reserve memory area at end-of data area.
  *
- * This macro reserves tailroom in the XDP buffer by limiting the
- * XDP/BPF data access to data_hard_end.  Notice same area (and size)
- * is used for XDP_PASS, when constructing the SKB via build_skb().
+ * This reserves tailroom in the XDP buffer by limiting the XDP/BPF data
+ * access to data_hard_end.  Notice same area (and size) is used for
+ * XDP_PASS, when constructing the SKB via build_skb(). Buffers with
+ * %XDP_FLAGS_SINFO_EXT keep the shared info elsewhere and reserve none.
  */
-#define xdp_data_hard_end(xdp)				\
-	((xdp)->data_hard_start + (xdp)->frame_sz -	\
-	 SKB_DATA_ALIGN(sizeof(struct skb_shared_info)))
+static __always_inline void *xdp_data_hard_end(const struct xdp_buff *xdp)
+{
+	u32 tailroom = SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
+
+	if (xdp->flags & XDP_FLAGS_SINFO_EXT)
+		tailroom = 0;
+	return xdp->data_hard_start + xdp->frame_sz - tailroom;
+}
 
 static inline struct skb_shared_info *
 xdp_get_shared_info_from_buff(const struct xdp_buff *xdp)
 {
+	if (xdp->flags & XDP_FLAGS_SINFO_EXT)
+		return READ_ONCE(xdp->rxq)->ext_sinfo;
+
 	return (struct skb_shared_info *)xdp_data_hard_end(xdp);
 }
 
diff --git a/include/net/xdp_sock_drv.h b/include/net/xdp_sock_drv.h
index a40ad3f90f13..ec74bf3ffa51 100644
--- a/include/net/xdp_sock_drv.h
+++ b/include/net/xdp_sock_drv.h
@@ -41,11 +41,6 @@ static inline u32 xsk_pool_get_headroom(struct xsk_buff_pool *pool)
 	return XDP_PACKET_HEADROOM + pool->headroom;
 }
 
-static inline u32 xsk_pool_get_tailroom(bool mbuf)
-{
-	return mbuf ? SKB_DATA_ALIGN(sizeof(struct skb_shared_info)) : 0;
-}
-
 static inline u32 xsk_pool_get_chunk_size(struct xsk_buff_pool *pool)
 {
 	return pool->chunk_size;
@@ -58,18 +53,7 @@ static inline u32 __xsk_pool_get_rx_frame_size(struct xsk_buff_pool *pool)
 
 static inline u32 xsk_pool_get_rx_frame_size(struct xsk_buff_pool *pool)
 {
-	u32 frame_size =  __xsk_pool_get_rx_frame_size(pool);
-	struct xdp_umem *umem = pool->umem;
-	bool mbuf;
-
-	/* Reserve tailroom only for zero-copy pools that opted into
-	 * multi-buffer. The reserved area is used for skb_shared_info,
-	 * matching the XDP core's xdp_data_hard_end() layout.
-	 */
-	mbuf = pool->dev && (umem->flags & XDP_UMEM_SG_FLAG);
-	frame_size -= xsk_pool_get_tailroom(mbuf);
-
-	return ALIGN_DOWN(frame_size, 128);
+	return ALIGN_DOWN(__xsk_pool_get_rx_frame_size(pool), 128);
 }
 
 static inline u32 xsk_pool_get_rx_frag_step(struct xsk_buff_pool *pool)
@@ -152,7 +136,6 @@ static inline void xsk_buff_free(struct xdp_buff *xdp)
 		xp_free(pos);
 	}
 
-	xdp_get_shared_info_from_buff(xdp)->nr_frags = 0;
 	xdp_buff_clear_frags_flag(xdp);
 out:
 	xp_free(xskb);
@@ -226,8 +209,11 @@ static inline void xsk_buff_set_size(struct xdp_buff *xdp, u32 size)
 	xdp->data = xdp->data_hard_start + XDP_PACKET_HEADROOM;
 	xdp->data_meta = xdp->data;
 	xdp->data_end = xdp->data + size;
-	/* Frags flag is cleared when the frags of a head are released */
-	xdp->flags &= XDP_FLAGS_HAS_FRAGS;
+	/* Frags flag is cleared when the frags of a head are released. The
+	 * shared info stays in the pool, see xp_set_rxq_info(), also for a
+	 * buffer whose flags a driver cleared.
+	 */
+	xdp->flags = (xdp->flags & XDP_FLAGS_HAS_FRAGS) | XDP_FLAGS_SINFO_EXT;
 }
 
 static inline dma_addr_t xsk_buff_raw_get_dma(struct xsk_buff_pool *pool,
diff --git a/include/net/xsk_buff_pool.h b/include/net/xsk_buff_pool.h
index 02e89350faf9..3d0e065cc8a7 100644
--- a/include/net/xsk_buff_pool.h
+++ b/include/net/xsk_buff_pool.h
@@ -59,6 +59,7 @@ struct xsk_buff_pool {
 	spinlock_t rx_lock;
 	struct list_head free_list;
 	struct list_head xskb_list;
+	struct skb_shared_info sinfo;
 	u32 heads_cnt;
 	u16 queue_id;
 
diff --git a/net/core/filter.c b/net/core/filter.c
index 53c042b267ab..3820c4edc14d 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -4510,7 +4510,7 @@ BPF_CALL_2(bpf_xdp_adjust_tail, struct xdp_buff *, xdp, int, offset)
 		return bpf_xdp_frags_increase_tail(xdp, offset);
 	}
 
-	/* Notice that xdp_data_hard_end have reserved some tailroom */
+	/* Notice that xdp_data_hard_end may have reserved some tailroom */
 	if (unlikely(data_end > data_hard_end))
 		return -EINVAL;
 
diff --git a/net/xdp/xdp_umem.c b/net/xdp/xdp_umem.c
index cd8643360eb3..e78a43c3c3e9 100644
--- a/net/xdp/xdp_umem.c
+++ b/net/xdp/xdp_umem.c
@@ -203,8 +203,7 @@ static int xdp_umem_reg(struct xdp_umem *umem, struct xdp_umem_reg *mr)
 	if (!unaligned_chunks && chunks_rem)
 		return -EINVAL;
 
-	if (headroom > chunk_size - XDP_PACKET_HEADROOM -
-		       SKB_DATA_ALIGN(sizeof(struct skb_shared_info)) - 128)
+	if (headroom > chunk_size - XDP_PACKET_HEADROOM - 128)
 		return -EINVAL;
 
 	if (mr->flags & XDP_UMEM_TX_METADATA_LEN) {
diff --git a/net/xdp/xsk_buff_pool.c b/net/xdp/xsk_buff_pool.c
index 5ec092f7cb6f..28bdc63551bf 100644
--- a/net/xdp/xsk_buff_pool.c
+++ b/net/xdp/xsk_buff_pool.c
@@ -107,6 +107,7 @@ struct xsk_buff_pool *xp_create_and_assign_umem(struct xdp_sock *xs,
 		xskb = &pool->heads[i];
 		xskb->pool = pool;
 		xskb->xdp.frame_sz = umem->chunk_size - umem->headroom;
+		xskb->xdp.flags = XDP_FLAGS_SINFO_EXT;
 		INIT_LIST_HEAD(&xskb->list_node);
 		if (pool->unaligned)
 			pool->free_heads[i] = xskb;
@@ -125,8 +126,15 @@ void xp_set_rxq_info(struct xsk_buff_pool *pool, struct xdp_rxq_info *rxq)
 {
 	u32 i;
 
+	/* Userspace may write the UMEM. Keep the shared info in the pool,
+	 * and let the device write up to the end of each chunk. A NAPI may
+	 * still run on the buffers, so publish the shared info first.
+	 */
+	rxq->ext_sinfo = &pool->sinfo;
+	/* Pairs with READ_ONCE(xdp->rxq) in xdp_get_shared_info_from_buff() */
+	smp_wmb();
 	for (i = 0; i < pool->heads_cnt; i++)
-		pool->heads[i].xdp.rxq = rxq;
+		WRITE_ONCE(pool->heads[i].xdp.rxq, rxq);
 }
 EXPORT_SYMBOL(xp_set_rxq_info);
 
@@ -229,12 +237,7 @@ int xp_assign_dev(struct xsk_buff_pool *pool,
 		segs = 1;
 	}
 
-	/* open-code xsk_pool_get_rx_frame_size() as pool->dev is not
-	 * set yet at this point; we are before getting down to driver
-	 */
-	frame_size = __xsk_pool_get_rx_frame_size(pool) -
-		     xsk_pool_get_tailroom(mbuf);
-	frame_size = ALIGN_DOWN(frame_size, 128);
+	frame_size = xsk_pool_get_rx_frame_size(pool);
 
 	if (needed > frame_size * segs) {
 		err = -EINVAL;
@@ -629,7 +632,8 @@ struct xdp_buff *xp_alloc(struct xsk_buff_pool *pool)
 
 	xskb->xdp.data = xskb->xdp.data_hard_start + XDP_PACKET_HEADROOM;
 	xskb->xdp.data_meta = xskb->xdp.data;
-	xskb->xdp.flags &= XDP_FLAGS_HAS_FRAGS;
+	xskb->xdp.flags = (xskb->xdp.flags & XDP_FLAGS_HAS_FRAGS) |
+			  XDP_FLAGS_SINFO_EXT;
 
 	if (pool->dev)
 		xp_dma_sync_for_device(pool, xskb->dma, pool->frame_len);
-- 
2.56.1


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [PATCH net v2 1/4] libeth: xsk: Count each XDP_TX buffer on its own
  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
  1 sibling, 0 replies; 16+ messages in thread
From: Alexander Lobakin @ 2026-11-30 16:41 UTC (permalink / raw)
  To: Björn Töpel
  Cc: Magnus Karlsson, Maciej Fijalkowski, Alexei Starovoitov,
	Daniel Borkmann, Jesper Dangaard Brouer, John Fastabend,
	Andrii Nakryiko, Eduard Zingerman, Kumar Kartikeya Dwivedi,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Willem de Bruijn, netdev, bpf, Simon Horman, Stanislav Fomichev,
	Martin KaFai Lau, Song Liu, Yonghong Song, Jiri Olsa,
	Emil Tsalapatis, Ihor Solodrai, Tony Nguyen, Przemek Kitszel,
	intel-wired-lan, Clément Lecigne

From: Björn Töpel <bjorn@kernel.org>
Date: Mon, 30 Nov 2026 13:37:32 +0100

> libeth takes the number of buffers of an XSk XDP_TX frame from its
> shared info, and reports that many completed buffers to the driver. It
> reads the shared info when it flushes the bulk, not when it queues the
> frame. The shared info of a zero-copy buffer lives in the UMEM, which
> userspace may write at any time, so a rewritten count makes libeth
> report a wrong number. Once the last patch of this series moves the
> shared info into the buffer pool, the next multi-buffer frame of the
> same poll can overwrite it before the flush.
> 
> A wrong number breaks the in-flight count of XDP_TX buffers that idpf
> keeps on its XSk queues, and idpf may then complete XDP_TX buffers as
> XSk xmit frames.
> 
> Make libeth count each buffer on its own SQE. Head and fragments each
> count one completed buffer, and the head counts the packet. Stats stay
> the same for frames sent in full.
> 
> Found by an AI agent while reviewing this code. Not triggered at
> runtime.
> 
> Fixes: b3ad8450b4dc ("libeth: xsk: add XSk XDP_TX sending helpers")
> Signed-off-by: Björn Töpel <bjorn@kernel.org>

Acked-by: Alexander Lobakin <aleksander.lobakin@intel.com>

Thanks!
Olek

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH net v2 2/4] xdp: Size zero-copy skbs from the data, not the frame size
  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
  1 sibling, 1 reply; 16+ messages in thread
From: Alexander Lobakin @ 2026-11-30 16:54 UTC (permalink / raw)
  To: Björn Töpel
  Cc: Magnus Karlsson, Maciej Fijalkowski, Alexei Starovoitov,
	Daniel Borkmann, Jesper Dangaard Brouer, John Fastabend,
	Andrii Nakryiko, Eduard Zingerman, Kumar Kartikeya Dwivedi,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Willem de Bruijn, netdev, bpf, Simon Horman, Stanislav Fomichev,
	Martin KaFai Lau, Song Liu, Yonghong Song, Jiri Olsa,
	Emil Tsalapatis, Ihor Solodrai, Tony Nguyen, Przemek Kitszel,
	intel-wired-lan, Clément Lecigne

From: Björn Töpel <bjorn@kernel.org>
Date: Mon, 30 Nov 2026 13:37:33 +0100

> 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.
> 
> The copies of the head and of the fragments also round the length up
> to 16 bytes, and read and write past the end of the data.
> 
> Size the head from the data, and copy the exact length. A head that
> does not fit into a page of the system page pool, such as one that
> fills a whole 4K chunk, gets a kmalloc'd head from
> __netdev_alloc_skb() instead.
> 
> 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.
> 
> Reported-by: Clément Lecigne <clecigne@google.com>
> Link: https://lore.kernel.org/bpf/20260629072300.1664622-1-clecigne@google.com/
> Fixes: 560d958c6c68 ("xsk: add generic XSk &xdp_buff -> skb conversion")
> Signed-off-by: Björn Töpel <bjorn@kernel.org>
> ---
>  net/core/xdp.c | 40 ++++++++++++++++++++++++++++------------
>  1 file changed, 28 insertions(+), 12 deletions(-)
> 
> diff --git a/net/core/xdp.c b/net/core/xdp.c
> index 1d679e8fd649..33a6740b411f 100644
> --- a/net/core/xdp.c
> +++ b/net/core/xdp.c
> @@ -709,7 +709,7 @@ static noinline bool xdp_copy_frags_from_zc(struct sk_buff *skb,
>  		}
>  
>  		memcpy(page_address(page) + offset, skb_frag_address(frag),
> -		       LARGEST_ALIGN(len));
> +		       len);
>  		__skb_fill_page_desc_noacc(sinfo, i, page, offset, len);
>  
>  		tsize += truesize;
> @@ -723,6 +723,27 @@ static noinline bool xdp_copy_frags_from_zc(struct sk_buff *skb,
>  	return true;
>  }
>  
> +static struct sk_buff *xdp_zc_alloc_head(struct page_pool *pp,
> +					 struct net_device *dev, u32 size)
> +{
> +	u32 truesize = SKB_HEAD_ALIGN(size);
> +	struct sk_buff *skb;
> +	void *data;
> +
> +	if (truesize > PAGE_SIZE)
> +		return __netdev_alloc_skb(dev, size, GFP_ATOMIC | __GFP_NOWARN);
> +
> +	data = page_pool_dev_alloc_va(pp, &truesize);
> +	if (unlikely(!data))
> +		return NULL;
> +
> +	skb = napi_build_skb(data, truesize);
> +	if (unlikely(!skb))
> +		page_pool_free_va(pp, data, true);
> +
> +	return skb;
> +}
> +
>  /**
>   * xdp_build_skb_from_zc - create an skb from XSk &xdp_buff
>   * @xdp: source XSk buff
> @@ -730,7 +751,8 @@ static noinline bool xdp_copy_frags_from_zc(struct sk_buff *skb,
>   * Similar to xdp_build_skb_from_buff(), but for XSk frames. Allocate an skb
>   * head, new buffer for the head, copy the data and initialize the skb fields.
>   * If there are frags, allocate new buffers for them and copy.
> - * Buffers are allocated from the system percpu pools to try recycling them.
> + * Buffers are allocated from the system percpu pools to try recycling them,
> + * except a head that does not fit into a page.
>   * If new skb was built successfully, @xdp is returned to XSk pool's freelist.
>   * On error, it remains untouched and the caller must take care of this.
>   *
> @@ -738,33 +760,27 @@ static noinline bool xdp_copy_frags_from_zc(struct sk_buff *skb,
>   */
>  struct sk_buff *xdp_build_skb_from_zc(struct xdp_buff *xdp)
>  {
> +	u32 size = xdp->data_end - xdp->data_hard_start;
>  	const struct xdp_rxq_info *rxq = xdp->rxq;
>  	u32 len = xdp->data_end - xdp->data_meta;
> -	u32 truesize = xdp->frame_sz;
>  	struct sk_buff *skb = NULL;
>  	struct page_pool *pp;
>  	int metalen;
> -	void *data;
>  
>  	if (!IS_ENABLED(CONFIG_PAGE_POOL))
>  		return NULL;
>  
>  	local_lock_nested_bh(&system_page_pool.bh_lock);
>  	pp = this_cpu_read(system_page_pool.pool);
> -	data = page_pool_dev_alloc_va(pp, &truesize);
> -	if (unlikely(!data))
> -		goto out;
>  
> -	skb = napi_build_skb(data, truesize);
> -	if (unlikely(!skb)) {
> -		page_pool_free_va(pp, data, true);
> +	skb = xdp_zc_alloc_head(pp, rxq->dev, size);
> +	if (unlikely(!skb))
>  		goto out;
> -	}
>  
>  	skb_mark_for_recycle(skb);

I'd move this call to the bottom of xdp_zc_alloc_head() -- kmalloc'd
skbs shouldn't be marked for PP recycling.

>  	skb_reserve(skb, xdp->data_meta - xdp->data_hard_start);
>  
> -	memcpy(__skb_put(skb, len), xdp->data_meta, LARGEST_ALIGN(len));
> +	memcpy(__skb_put(skb, len), xdp->data_meta, len);
>  
>  	metalen = xdp->data - xdp->data_meta;
>  	if (metalen > 0) {

Other than that:

Acked-by: Alexander Lobakin <aleksander.lobakin@intel.com>

The idea behind those LARGEST_ALIGN() was that I thought there would
always be some empty room after the frame -- like "who would like to
align chunks to less than 16"...

Thanks,
Olek

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH net v2 3/4] intel: Copy the exact length of XSk packets to skbs
  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
  0 siblings, 0 replies; 16+ messages in thread
From: Alexander Lobakin @ 2026-11-30 16:56 UTC (permalink / raw)
  To: Björn Töpel
  Cc: Magnus Karlsson, Maciej Fijalkowski, Alexei Starovoitov,
	Daniel Borkmann, Jesper Dangaard Brouer, John Fastabend,
	Andrii Nakryiko, Eduard Zingerman, Kumar Kartikeya Dwivedi,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Willem de Bruijn, netdev, bpf, Simon Horman, Stanislav Fomichev,
	Martin KaFai Lau, Song Liu, Yonghong Song, Jiri Olsa,
	Emil Tsalapatis, Ihor Solodrai, Tony Nguyen, Przemek Kitszel,
	intel-wired-lan, Clément Lecigne

From: Björn Töpel <bjorn@kernel.org>
Date: Mon, 30 Nov 2026 13:37:34 +0100

> i40e, igb, igc and ixgbe copy an XSk zero-copy packet that the XDP
> program passes into a new skb, and round the length of the copy up to
> a multiple of 8 bytes. The copy then reads up to 7 bytes past the end
> of the data. When the data ends at the end of the last chunk of the
> UMEM, the read hits the guard page after the UMEM mapping and faults.
> 
> On i40e the device can already fill a single-buffer chunk to its end.
> The last patch of this series lets multi-buffer pools and
> bpf_xdp_adjust_tail() reach the end of a chunk on all four.
> 
> Copy the exact length.
> 
> Found by an AI code review agent in review of this series. Reproduced
> on igb in QEMU. An AF_XDP socket in zero copy with 4K chunks and only
> the last chunk of the UMEM in the FILL ring, and an XDP program that
> adds 4 bytes of metadata, grows the tail to the end of the chunk and
> passes the packet:
> 
>   BUG: unable to handle page fault for address: ffa0000001048000
>   RIP: 0010:memcpy+0xc/0x30
>    igb_clean_rx_irq_zc+0x8a7/0x1520
>    igb_poll+0x1039/0x4f50
> 
> With this patch the same test passes.
> 
> Fixes: 6dba29537c0f ("i40e: respect metadata on XSK Rx to skb")
> Fixes: f322a620be69 ("ixgbe: respect metadata on XSK Rx to skb")
> Fixes: f9e61d365baf ("igc: don't reserve excessive XDP_PACKET_HEADROOM on XSK Rx to skb")
> Fixes: 2c6196013f84 ("igb: Add AF_XDP zero-copy Rx support")
> Signed-off-by: Björn Töpel <bjorn@kernel.org>

Acked-by: Alexander Lobakin <aleksander.lobakin@intel.com>

Thanks,
Olek

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH net v2 2/4] xdp: Size zero-copy skbs from the data, not the frame size
  2026-11-30 16:54   ` Alexander Lobakin
@ 2026-12-01  7:12     ` Björn Töpel
  2026-12-01 14:08       ` Alexander Lobakin
  0 siblings, 1 reply; 16+ messages in thread
From: Björn Töpel @ 2026-12-01  7:12 UTC (permalink / raw)
  To: Alexander Lobakin
  Cc: Magnus Karlsson, Maciej Fijalkowski, Alexei Starovoitov,
	Daniel Borkmann, Jesper Dangaard Brouer, John Fastabend,
	Andrii Nakryiko, Eduard Zingerman, Kumar Kartikeya Dwivedi,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Willem de Bruijn, netdev, bpf, Simon Horman, Stanislav Fomichev,
	Martin KaFai Lau, Song Liu, Yonghong Song, Jiri Olsa,
	Emil Tsalapatis, Ihor Solodrai, Tony Nguyen, Przemek Kitszel,
	intel-wired-lan, Clément Lecigne

Alexander Lobakin <aleksander.lobakin@intel.com> writes:

> From: Björn Töpel <bjorn@kernel.org>
> Date: Mon, 30 Nov 2026 13:37:33 +0100
>> diff --git a/net/core/xdp.c b/net/core/xdp.c
>> index 1d679e8fd649..33a6740b411f 100644
>> --- a/net/core/xdp.c
>> +++ b/net/core/xdp.c
>> @@ -738,33 +760,27 @@ static noinline bool xdp_copy_frags_from_zc(struct sk_buff *skb,
>>   */
>>  struct sk_buff *xdp_build_skb_from_zc(struct xdp_buff *xdp)
>>  {
>> +	u32 size = xdp->data_end - xdp->data_hard_start;
>>  	const struct xdp_rxq_info *rxq = xdp->rxq;
>>  	u32 len = xdp->data_end - xdp->data_meta;
>> -	u32 truesize = xdp->frame_sz;
>>  	struct sk_buff *skb = NULL;
>>  	struct page_pool *pp;
>>  	int metalen;
>> -	void *data;
>>  
>>  	if (!IS_ENABLED(CONFIG_PAGE_POOL))
>>  		return NULL;
>>  
>>  	local_lock_nested_bh(&system_page_pool.bh_lock);
>>  	pp = this_cpu_read(system_page_pool.pool);
>> -	data = page_pool_dev_alloc_va(pp, &truesize);
>> -	if (unlikely(!data))
>> -		goto out;
>>  
>> -	skb = napi_build_skb(data, truesize);
>> -	if (unlikely(!skb)) {
>> -		page_pool_free_va(pp, data, true);
>> +	skb = xdp_zc_alloc_head(pp, rxq->dev, size);
>> +	if (unlikely(!skb))
>>  		goto out;
>> -	}
>>  
>>  	skb_mark_for_recycle(skb);
>
> I'd move this call to the bottom of xdp_zc_alloc_head() -- kmalloc'd
> skbs shouldn't be marked for PP recycling.

Thanks for the acks, Olek!

I think we need to keep the mark here. A head from kmalloc can still
carry pp frags from xdp_copy_frags_from_zc(). pp_recycle applies to
those frags too, so marking only the pp head would make the kmalloc case
bypass the pp release path.

The mark does not change how the head is freed. __alloc_skb() leaves
head_frag clear, so skb_free_head() calls kfree() without checking
pp_recycle.


Björn

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH net v2 1/4] libeth: xsk: Count each XDP_TX buffer on its own
  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-12-01 15:57     ` Björn Töpel
  1 sibling, 1 reply; 16+ messages in thread
From: netdev-bot+sashiko @ 2026-12-01 12:39 UTC (permalink / raw)
  To: bjorn
  Cc: magnus.karlsson, maciej.fijalkowski, aleksander.lobakin, ast,
	daniel, hawk, john.fastabend, andrii, eddyz87, memxor, davem,
	edumazet, kuba, pabeni, willemb, netdev, bpf, horms, sdf,
	martin.lau, song, yonghong.song, jolsa, emil, ihor.solodrai,
	anthony.l.nguyen, przemyslaw.kitszel, intel-wired-lan, clecigne

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

Critical: 0 · High: 1 · Medium: 0 · 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).

- [High] The patch does not repair the idpf in-flight XDP_TX count it
  says it fixes.

--

libeth: xsk: Count each XDP_TX buffer on its own

This patch stops libeth from reading the XSk XDP_TX buffer count from
the frame's shared info at flush time. Each XSk XDP_TX SQE, head or
fragment, now counts as one completed buffer and carries its own byte
count. The head SQE also counts the packet.

> diff --git a/include/net/libeth/xdp.h b/include/net/libeth/xdp.h
> index 898723ab62e81..66a3c4ec9967e 100644
> --- a/include/net/libeth/xdp.h
> +++ b/include/net/libeth/xdp.h
> @@ -1794,12 +1794,19 @@ __libeth_xdp_complete_tx(struct libeth_sqe *sqe, struct libeth_cq_pp *cp,
>  	switch (type) {
>  	case LIBETH_SQE_XDP_TX:
>  	case LIBETH_SQE_XDP_XMIT:
> -	case LIBETH_SQE_XSK_TX:
>  		cp->xdp_tx -= sqe->nr_frags;
>  
>  		cp->xss->packets++;
>  		cp->xss->bytes += sqe->bytes;
>  		break;
> +	case LIBETH_SQE_XSK_TX:
> +		cp->xss->packets++;
> +		fallthrough;
> +	case LIBETH_SQE_XSK_TX_FRAG:
> +		/* One buffer per SQE, see libeth_xsk_tx_fill_buf() */
> +		cp->xdp_tx--;

[Severity: High]
Does the sign of this decrement match what idpf expects?

The count is now one per SQE. On the send side, though,
libeth_xdp_tx_xmit_bulk() adds to the same counter:

include/net/libeth/xdp.h:libeth_xdp_tx_xmit_bulk() {
    ...
	if (sq.xdp_tx)
		*sq.xdp_tx += n;
    ...
}

For XSk XDP_TX, idpf_xsk_tx_prep() points sq.xdp_tx at
xdpsq->xdp_tx.

On completion, idpf_xsksq_complete_slow() starts with a zeroed cp. After
k XSk XDP_TX buffers complete, cp.xdp_tx holds (u32)-k. The driver then
does this:

drivers/net/ethernet/intel/idpf/xsk.c:idpf_xsksq_complete_slow() {
    ...
	xdpsq->next_to_clean = ntc;
	xdpsq->xdp_tx -= cp.xdp_tx;
    ...
}

That adds k to xdpsq->xdp_tx instead of subtracting it. Doesn't the
in-flight counter then grow on both send and completion?

The kernel-doc for struct libeth_cq_pp describes xdp_tx as "number of
XDP-not-XSk frames processed", which is a positive count. In idpf/xdp.c,
idpf_xdpsq_complete() uses the same "xdpsq->xdp_tx -= cp.xdp_tx" pattern
with the existing "cp->xdp_tx -= sqe->nr_frags" line. The new XSk case
copies that sign.

idpf_xsksq_complete() uses this counter to choose its fast path:

	if (likely(!xdpsq->xdp_tx)) {
		tx_ntc += done_frames;
		...
		xsk_frames = done_frames;

		goto finalize;
	}

After the first XSk XDP_TX the counter never goes back to zero, so the
slow path is always taken. Each XDP_TX buffer adds 2 to the counter. After
about 2^31 buffers the u32 wraps, and it can read exactly zero while
XDP_TX SQEs are still on the ring.

In that case, would the fast path pass those XDP_TX buffers to
xsk_tx_completed() as xmit completions and never call xsk_buff_free() on
them? Userspace would then see completion ring entries that were never
reserved for xmit, and those UMEM buffers would leak from the pool. That
looks like the same outcome the commit message describes: "idpf may then
complete XDP_TX buffers as XSk xmit frames".

The later patch in this series, "xsk: Keep the shared info of zero-copy
buffers in kernel memory", leaves both cp->xdp_tx-- and
xdpsq->xdp_tx -= cp.xdp_tx unchanged. The mismatch is still present at
the end of the series.

Would it work to have libeth return a positive count (cp->xdp_tx++ and
cp->xdp_tx += sqe->nr_frags)? Changing the idpf consumers to += would
also work.

> +		cp->xss->bytes += sqe->bytes;
> +		break;
>  	default:
>  		break;
>  	}

[ ... ]

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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH net v2 2/4] xdp: Size zero-copy skbs from the data, not the frame size
  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 12:39   ` netdev-bot+sashiko
  2026-12-01 15:58     ` Björn Töpel
  1 sibling, 1 reply; 16+ messages in thread
From: netdev-bot+sashiko @ 2026-12-01 12:39 UTC (permalink / raw)
  To: bjorn
  Cc: magnus.karlsson, maciej.fijalkowski, aleksander.lobakin, ast,
	daniel, hawk, john.fastabend, andrii, eddyz87, memxor, davem,
	edumazet, kuba, pabeni, willemb, netdev, bpf, horms, sdf,
	martin.lau, song, yonghong.song, jolsa, emil, ihor.solodrai,
	anthony.l.nguyen, przemyslaw.kitszel, intel-wired-lan, clecigne

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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH net v2 4/4] xsk: Keep the shared info of zero-copy buffers in kernel memory
  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
  2026-12-01 16:01     ` Björn Töpel
  0 siblings, 1 reply; 16+ messages in thread
From: netdev-bot+sashiko @ 2026-12-01 12:39 UTC (permalink / raw)
  To: bjorn
  Cc: magnus.karlsson, maciej.fijalkowski, aleksander.lobakin, ast,
	daniel, hawk, john.fastabend, andrii, eddyz87, memxor, davem,
	edumazet, kuba, pabeni, willemb, netdev, bpf, horms, sdf,
	martin.lau, song, yonghong.song, jolsa, emil, ihor.solodrai,
	anthony.l.nguyen, przemyslaw.kitszel, intel-wired-lan, clecigne

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

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

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] Logic inconsistency (length limits).
- [Low] Commit message: undisclosed stable prerequisites.

Pre-existing issues:
- [Critical] This problem wasn't introduced by this patch, but the
  patch's premise is that "Userspace may write the UMEM at any time".

--

xsk: Keep the shared info of zero-copy buffers in kernel memory

This patch moves the skb_shared_info of multi-buffer XSk zero-copy
packets out of the UMEM chunk tailroom and into the buffer pool. Pool
buffers are marked with the new XDP_FLAGS_SINFO_EXT flag. For those
buffers xdp_data_hard_end() reserves no tailroom, so the device and
bpf_xdp_adjust_tail() can use the whole chunk.

> Keep the shared info in the buffer pool, which outlives its buffers
> and the queues that point to it, and let the device write up to the
> end of the chunk. One shared info per pool is enough, as a pool builds
> one multi-buffer packet at a time. libeth read it later, at an XDP_TX
> bulk flush, which an earlier patch of this series fixes.

[ ... ]

> Multi-buffer pools now give the device the whole chunk, as
> single-buffer pools already do. Every UMEM accepts a larger headroom,
> also in copy mode, and bpf_xdp_adjust_tail() can grow a zero-copy
> packet up to the end of its chunk.

[Severity: Low]
The message names only the libeth prerequisite. Does this patch also
depend on two other commits from the same series?

  "xdp: Size zero-copy skbs from the data, not the frame size"
  "intel: Copy the exact length of XSk packets to skbs"

Both of them say "The last patch of this series lets multi-buffer pools
and bpf_xdp_adjust_tail() reach the end of a chunk". The intel one
describes a page fault on the guard page after the UMEM, from the memcpy
in igb_clean_rx_irq_zc(), when the tail is grown to the chunk end.

This patch carries Fixes: 24ea50127ecf, so it is a stable candidate. If
it is backported without those two commits, the over-reads in the intel
drivers and the shared-info overwrite in xdp_build_skb_from_zc() would
become reachable on igb/igc/ixgbe.

Could the message name those commits as well, or add stable dependency
annotations for them?

> diff --git a/include/net/xdp.h b/include/net/xdp.h
> index 07231adfb5f82..0524027669882 100644
> --- a/include/net/xdp.h
> +++ b/include/net/xdp.h

[ ... ]

> @@ -178,17 +189,26 @@ xdp_prepare_buff(struct xdp_buff *xdp, unsigned char *hard_start,

[ ... ]

> -#define xdp_data_hard_end(xdp)				\
> -	((xdp)->data_hard_start + (xdp)->frame_sz -	\
> -	 SKB_DATA_ALIGN(sizeof(struct skb_shared_info)))
> +static __always_inline void *xdp_data_hard_end(const struct xdp_buff *xdp)
> +{
> +	u32 tailroom = SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
> +
> +	if (xdp->flags & XDP_FLAGS_SINFO_EXT)
> +		tailroom = 0;
> +	return xdp->data_hard_start + xdp->frame_sz - tailroom;
> +}

[Severity: Medium]
With XDP_FLAGS_SINFO_EXT set, bpf_xdp_adjust_tail() can now grow
data_end up to data_hard_start + frame_sz. xsk_rcv_check() in
net/xdp/xsk.c was not updated. Does it still agree with this new bound?

net/xdp/xsk.c:xsk_rcv_check() {
    ...
	if (len > __xsk_pool_get_rx_frame_size(xs->pool) && !xs->sg) {
		xs->rx_dropped++;
		return -ENOSPC;
	}
    ...
}

__xsk_pool_get_rx_frame_size() is chunk_size - umem headroom -
XDP_PACKET_HEADROOM, which is frame_sz - 256.

Take a zero-copy socket bound without XDP_USE_SG. A program can call
bpf_xdp_adjust_head() with a negative offset, which moves data down to
data_hard_start + sizeof(struct xdp_frame). It can then call
bpf_xdp_adjust_tail() to reach the chunk end. That gives a linear packet
of up to frame_sz - 40 bytes.

Both helpers succeed. After the redirect to the XSKMAP,
xsk_rcv()->xsk_rcv_check() drops the packet and increments rx_dropped,
even though the data fits inside its own chunk.

Before this patch, bpf_xdp_adjust_tail() capped data_end at 320 bytes
before the chunk end and returned -EINVAL, so the program saw the
failure.

bpf_xdp_adjust_head() alone could already exceed this check when a
single-buffer device filled the chunk to its end. This patch extends the
mismatch to the adjust_tail range on any UMEM layout.

Should xsk_rcv_check() use a bound that matches xdp_data_hard_end() for
zero-copy buffers?

[ ... ]

> diff --git a/net/xdp/xsk_buff_pool.c b/net/xdp/xsk_buff_pool.c
> index 5ec092f7cb6f7..28bdc63551bfc 100644
> --- a/net/xdp/xsk_buff_pool.c
> +++ b/net/xdp/xsk_buff_pool.c

[ ... ]

> @@ -125,8 +126,15 @@ void xp_set_rxq_info(struct xsk_buff_pool *pool, struct xdp_rxq_info *rxq)
>  {
>  	u32 i;
>  
> +	/* Userspace may write the UMEM. Keep the shared info in the pool,
> +	 * and let the device write up to the end of each chunk. A NAPI may
> +	 * still run on the buffers, so publish the shared info first.
> +	 */

[Severity: Critical]
This is a pre-existing issue and was not introduced by this patch, but
it is in the class of bug this patch closes. dpaa2 stores a kernel
pointer inside the UMEM chunk, which userspace can write.

drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c:dpaa2_eth_seed_pool() {
    ...
			swa = (struct dpaa2_eth_swa *)(xdp_buffs[i]->data_hard_start +
						       DPAA2_ETH_RX_HWA_SIZE);
			swa->xsk.xdp_buff = xdp_buffs[i];
    ...
}

data_hard_start points into the vmap of the pinned user UMEM pages. On
RX, dpaa2_xsk_rx()->dpaa2_xsk_run_xdp() reads the pointer back from the
same chunk and writes through it:

drivers/net/ethernet/freescale/dpaa2/dpaa2-xsk.c:dpaa2_xsk_run_xdp() {
    ...
	swa = (struct dpaa2_eth_swa *)(vaddr + DPAA2_ETH_RX_HWA_SIZE +
				       ch->xsk_pool->umem->headroom);
	xdp_buff = swa->xsk.xdp_buff;

	xdp_buff->data_hard_start = vaddr;
	xdp_buff->data = vaddr + dpaa2_fd_get_offset(fd);
    ...
}

It then runs the XDP program on that buffer and passes it to
xdp_do_redirect(). dpaa2_eth_free_bufs() also reads swa->xsk.xdp_buff
from the chunk on teardown and passes it to xsk_buff_free():

drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c:dpaa2_eth_free_bufs() {
    ...
			swa = (struct dpaa2_eth_swa *)
				(vaddr + DPAA2_ETH_RX_HWA_SIZE);
			xdp_buff = swa->xsk.xdp_buff;
			xsk_buff_free(xdp_buff);
    ...
}

The pointer is not validated on either path.

The chunk can sit in the fill ring or the hardware buffer pool. Can a
process that owns the UMEM overwrite these 8 bytes during that window?
The kernel would then write through, and do list operations on, an
address that userspace chose.

> +	rxq->ext_sinfo = &pool->sinfo;
> +	/* Pairs with READ_ONCE(xdp->rxq) in xdp_get_shared_info_from_buff() */
> +	smp_wmb();
>  	for (i = 0; i < pool->heads_cnt; i++)
> -		pool->heads[i].xdp.rxq = rxq;
> +		WRITE_ONCE(pool->heads[i].xdp.rxq, rxq);
>  }
>  EXPORT_SYMBOL(xp_set_rxq_info);

[ ... ]

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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH net v2 2/4] xdp: Size zero-copy skbs from the data, not the frame size
  2026-12-01  7:12     ` Björn Töpel
@ 2026-12-01 14:08       ` Alexander Lobakin
  0 siblings, 0 replies; 16+ messages in thread
From: Alexander Lobakin @ 2026-12-01 14:08 UTC (permalink / raw)
  To: Björn Töpel
  Cc: Magnus Karlsson, Maciej Fijalkowski, Alexei Starovoitov,
	Daniel Borkmann, Jesper Dangaard Brouer, John Fastabend,
	Andrii Nakryiko, Eduard Zingerman, Kumar Kartikeya Dwivedi,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Willem de Bruijn, netdev, bpf, Simon Horman, Stanislav Fomichev,
	Martin KaFai Lau, Song Liu, Yonghong Song, Jiri Olsa,
	Emil Tsalapatis, Ihor Solodrai, Tony Nguyen, Przemek Kitszel,
	intel-wired-lan, Clément Lecigne

From: Björn Töpel <bjorn@kernel.org>
Date: Tue, 01 Dec 2026 08:12:05 +0100

> Alexander Lobakin <aleksander.lobakin@intel.com> writes:
> 
>> From: Björn Töpel <bjorn@kernel.org>
>> Date: Mon, 30 Nov 2026 13:37:33 +0100
>>> diff --git a/net/core/xdp.c b/net/core/xdp.c
>>> index 1d679e8fd649..33a6740b411f 100644
>>> --- a/net/core/xdp.c
>>> +++ b/net/core/xdp.c
>>> @@ -738,33 +760,27 @@ static noinline bool xdp_copy_frags_from_zc(struct sk_buff *skb,
>>>   */
>>>  struct sk_buff *xdp_build_skb_from_zc(struct xdp_buff *xdp)
>>>  {
>>> +	u32 size = xdp->data_end - xdp->data_hard_start;
>>>  	const struct xdp_rxq_info *rxq = xdp->rxq;
>>>  	u32 len = xdp->data_end - xdp->data_meta;
>>> -	u32 truesize = xdp->frame_sz;
>>>  	struct sk_buff *skb = NULL;
>>>  	struct page_pool *pp;
>>>  	int metalen;
>>> -	void *data;
>>>  
>>>  	if (!IS_ENABLED(CONFIG_PAGE_POOL))
>>>  		return NULL;
>>>  
>>>  	local_lock_nested_bh(&system_page_pool.bh_lock);
>>>  	pp = this_cpu_read(system_page_pool.pool);
>>> -	data = page_pool_dev_alloc_va(pp, &truesize);
>>> -	if (unlikely(!data))
>>> -		goto out;
>>>  
>>> -	skb = napi_build_skb(data, truesize);
>>> -	if (unlikely(!skb)) {
>>> -		page_pool_free_va(pp, data, true);
>>> +	skb = xdp_zc_alloc_head(pp, rxq->dev, size);
>>> +	if (unlikely(!skb))
>>>  		goto out;
>>> -	}
>>>  
>>>  	skb_mark_for_recycle(skb);
>>
>> I'd move this call to the bottom of xdp_zc_alloc_head() -- kmalloc'd
>> skbs shouldn't be marked for PP recycling.
> 
> Thanks for the acks, Olek!
> 
> I think we need to keep the mark here. A head from kmalloc can still
> carry pp frags from xdp_copy_frags_from_zc(). pp_recycle applies to
> those frags too, so marking only the pp head would make the kmalloc case
> bypass the pp release path.
> 
> The mark does not change how the head is freed. __alloc_skb() leaves
> head_frag clear, so skb_free_head() calls kfree() without checking
> pp_recycle.

Ack, I completely forgot about the frags =\

Thanks,
Olek

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH net v2 1/4] libeth: xsk: Count each XDP_TX buffer on its own
  2026-12-01 12:39   ` netdev-bot+sashiko
@ 2026-12-01 15:57     ` Björn Töpel
  0 siblings, 0 replies; 16+ messages in thread
From: Björn Töpel @ 2026-12-01 15:57 UTC (permalink / raw)
  To: netdev-bot+sashiko, aleksander.lobakin
  Cc: magnus.karlsson, maciej.fijalkowski, ast, daniel, hawk,
	john.fastabend, andrii, eddyz87, memxor, davem, edumazet, kuba,
	pabeni, willemb, netdev, bpf, horms, sdf, martin.lau, song,
	yonghong.song, jolsa, emil, ihor.solodrai, anthony.l.nguyen,
	przemyslaw.kitszel, intel-wired-lan, clecigne

netdev-bot+sashiko@kernel.org writes:

> [Severity: High]
> Does the sign of this decrement match what idpf expects?

It doesn't, but that is older than this patch. libeth counts XDP_TX
completions down and idpf subtracts the result, so xdp_tx grows on both
send and completion, with or without this series. This patch only stops
libeth from reading the count from shared info that may change before
the bulk flush, and keeps the sign libeth already uses for XDP_TX and
XDP_XMIT.

Flipping the sign alone isn't safe either. For XDP_TX and XDP_XMIT the
completion subtracts all frags of a frame, while the send side adds only
the descriptors it posted, so the count has to become exact as well.

That is a separate fix. Olek, would you like to take it?


Björn

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH net v2 2/4] xdp: Size zero-copy skbs from the data, not the frame size
  2026-12-01 12:39   ` netdev-bot+sashiko
@ 2026-12-01 15:58     ` Björn Töpel
  0 siblings, 0 replies; 16+ messages in thread
From: Björn Töpel @ 2026-12-01 15:58 UTC (permalink / raw)
  To: netdev-bot+sashiko
  Cc: magnus.karlsson, maciej.fijalkowski, aleksander.lobakin, ast,
	daniel, hawk, john.fastabend, andrii, eddyz87, memxor, davem,
	edumazet, kuba, pabeni, willemb, netdev, bpf, horms, sdf,
	martin.lau, song, yonghong.song, jolsa, emil, ihor.solodrai,
	anthony.l.nguyen, przemyslaw.kitszel, intel-wired-lan, clecigne

netdev-bot+sashiko@kernel.org writes:

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

Yes, agreed. With 2K chunks, no UMEM headroom and the default MTU, a
full-size frame that a program passes on ice, idpf or gve already
overwrites the shared info of the new skb. Head needs 256 + 1514 + 320 =
2090 bytes and gets 2048, so up to 48 bytes of the shared info come from
the packet.

The fix is the same for both cases, so I'd rather not respin only for
the changelog.

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH net v2 4/4] xsk: Keep the shared info of zero-copy buffers in kernel memory
  2026-12-01 12:39   ` netdev-bot+sashiko
@ 2026-12-01 16:01     ` Björn Töpel
  0 siblings, 0 replies; 16+ messages in thread
From: Björn Töpel @ 2026-12-01 16:01 UTC (permalink / raw)
  To: netdev-bot+sashiko
  Cc: magnus.karlsson, maciej.fijalkowski, aleksander.lobakin, ast,
	daniel, hawk, john.fastabend, andrii, eddyz87, memxor, davem,
	edumazet, kuba, pabeni, willemb, netdev, bpf, horms, sdf,
	martin.lau, song, yonghong.song, jolsa, emil, ihor.solodrai,
	anthony.l.nguyen, przemyslaw.kitszel, intel-wired-lan, clecigne

netdev-bot+sashiko@kernel.org writes:

> [Severity: Low]
> The message names only the libeth prerequisite. Does this patch also
> depend on two other commits from the same series?

Yes. A backport of this patch needs patches 1 to 3 of this series, which
stop libeth and the skb builders from relying on the shared info at the
end of the frame.

> [Severity: Medium]
> With XDP_FLAGS_SINFO_EXT set, bpf_xdp_adjust_tail() can now grow
> data_end up to data_hard_start + frame_sz. xsk_rcv_check() in
> net/xdp/xsk.c was not updated. Does it still agree with this new bound?

The larger tail only lets a packet that still fits in its own chunk
reach xsk_rcv_check(), which drops it and counts rx_dropped, as for any
packet longer than the socket's frame size. Nothing reads or writes
outside the chunk, and bpf_xdp_adjust_head() could already reach the
same check. Changing the frame size limit would change what userspace
sees, so I'd rather not do that in a net fix.

> [Severity: Critical]
> This is a pre-existing issue and was not introduced by this patch, but
> it is in the class of bug this patch closes. dpaa2 stores a kernel
> pointer inside the UMEM chunk, which userspace can write.

Agreed, that is real and separate from this series. I'll report it to
the dpaa2 maintainer.

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2026-12-01 16:01 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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-12-01 15:57     ` Björn Töpel
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 14:08       ` Alexander Lobakin
2026-12-01 12:39   ` netdev-bot+sashiko
2026-12-01 15:58     ` Björn Töpel
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
2026-12-01 16:01     ` Björn Töpel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox