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 4/4] xsk: Keep the shared info of zero-copy buffers in kernel memory
Date: Tue, 01 Dec 2026 12:39:19 +0000	[thread overview]
Message-ID: <179612875904.3146.8079683295083998736@kernel.org> (raw)
In-Reply-To: <20261130123737.125432-5-bjorn@kernel.org>

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

      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
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 [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=179612875904.3146.8079683295083998736@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