๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #22529

Re: [PATCH net-next 02/15] xdp: Keep the shared info of a buffer in kernel memory

#22529
From: netdev-bot+sashiko
Date: Wed, 25 Nov 2026 14:07
137 lines
13678 bytes
Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] A comment is now stale.

Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but the patch's
  commit message names it and the series leaves it open.

--

xdp: Keep the shared info of a buffer in kernel memory

This patch lets an RX queue keep the skb_shared_info of its XDP buffers
in kernel memory, allocated by xdp_rxq_info_reg_ext_sinfo(). Buffers
with the new XDP_FLAGS_SINFO_EXT flag look up their shared info there.
For such buffers xdp_data_hard_end() reserves no tailroom, and frame
and skb conversion refuse them.

> diff --git a/include/net/xdp.h b/include/net/xdp.h
> index 1629e347b71fb..944418111a86e 100644
> --- a/include/net/xdp.h
> +++ b/include/net/xdp.h

[ ... ]

> @@ -212,17 +226,27 @@ 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;
> +}

[Severity: Low]
This isn't a bug, but should the comment in bpf_xdp_adjust_tail() be
updated along with this change?

net/core/filter.c:bpf_xdp_adjust_tail() {
    ...
	/* Notice that xdp_data_hard_end have reserved some tailroom */
	if (unlikely(data_end > data_hard_end))
		return -EINVAL;
    ...
}

xdp_data_hard_end() no longer reserves tailroom for XDP_FLAGS_SINFO_EXT
buffers. For those buffers this bound reaches the end of the frame, and
frame_sz is the only limit.

>  
>  static inline struct skb_shared_info *
>  xdp_get_shared_info_from_buff(const struct xdp_buff *xdp)
>  {
> +	/* Kernel structures stay out of memory that userspace may write */
> +	if (unlikely(xdp->flags & XDP_FLAGS_SINFO_EXT))
> +		return xdp->rxq->ext_sinfo;
> +
>  	return (struct skb_shared_info *)xdp_data_hard_end(xdp);
>  }

[Severity: High]
This is a pre-existing issue, not one introduced by this patch. The
commit message gives it as the motivation:

    Classic AF_XDP zero copy keeps it in the tail of a UMEM chunk, where
    userspace can rewrite it.

Is classic AF_XDP zero copy meant to stay exposed? XSK pool buffers
never get XDP_FLAGS_SINFO_EXT, either here or later in the series. Later
in the series only xdp_sink_mark() sets the flag, and only for
MP_XDP_ONLY page pools.

So xsk_buff_add_frag() still writes the fragment list into the UMEM
tail:

xsk_buff_add_frag()
  __xdp_buff_add_frag(head, ...)
    xdp_get_shared_info_from_buff(head)
      xdp_data_hard_end(head)

That is the tailroom that xsk_pool_get_rx_frame_size() reserves when
XDP_UMEM_SG_FLAG is set.

Userspace can rewrite nr_frags and frags[] of chunks it has handed over
through the fill ring while NAPI builds a multi-buffer packet. Can a
forged nr_frags then overflow sinfo->frags[]? __xdp_buff_add_frag()
only checks:

	} else if (unlikely(nr_frags == MAX_SKB_FRAGS)) {
		return false;

With a value above MAX_SKB_FRAGS, it writes frags[nr_frags] past the
end of the chunk.

On XDP_PASS, xdp_copy_frags_from_zc() in net/core/xdp.c has the same
problem:

	xinfo = xdp_get_shared_info_from_buff(xdp);
	nr_frags = xinfo->nr_frags;

	for (u32 i = 0; i < nr_frags; i++) {

There is no bound on nr_frags here. It indexes skb_shinfo()->frags[] of
the new skb and copies from skb_frag_address() of the forged frag
netmems. xsk_rcv_zc() also sizes its RX ring reservation from nr_frags.

Triggering this needs a zero-copy AF_XDP socket with XDP_UMEM_SG_FLAG
and an attached XDP program.

Could the commit message say that classic zero copy stays out of scope?
Or could MEM_TYPE_XSK_BUFF_POOL buffers use ext_sinfo as well?

[ ... ]

-- 
Sashiko AI review ยท https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261124112707.118678-1-bjorn%40kernel.org
Technical Details
Message-ID: <179561567996.3135.9952128421877275714@kernel.org>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-371366-linux-kernel-netdev=dewy.ru
References: <20261124125654.183091-2-bjorn@kernel.org>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-371366-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net-next 02/15] xdp: Keep the shared info of a buffer in
 kernel memory
Date: Wed, 25 Nov 2026 14:07:59 +0000
Organization: Usenet Network
Message-ID: <179561567996.3135.9952128421877275714@kernel.org>
References: <20261124125654.183091-2-bjorn@kernel.org>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="222809"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:hqUV1McbWsF5YyByuT14n1y38fk= sha256:lhI4AeIrOVEB0hYedFvNSAtOZIyRQAa2vXdlWsRrUck=
	sha1:M/bD0M5muexLLI9KtKmwy+yoFk0= sha256:58+mdUfu9RvJdcsQ2aOTQNvuFQe1eTCDXzTWmC6lNTI=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id D41F7125E6E; Wed, 25 Nov 2026 17:08:32 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.5
X-Spam-Status: No, score=-3.5 tagged_above=-9999 required=6.31
	tests=[DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
	DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1,
	RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001,
	URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id Std0g1aK1zU0;
	Wed, 25 Nov 2026 17:08:29 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-371366-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
	by mail.dewy.ru (Postfix) with ESMTPS id 0D00B125E6D; Wed, 25 Nov 2026 17:08:19 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by tor.lore.kernel.org (Postfix) with ESMTP id 051C038F5C; Wed, 25 Nov 2026 14:08:13 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1795615685;
	b=J5XtBG0zLIvXVI91Q/9VpSWCP3KHW5o3yHn9O3joEkvaShAuTKnzBNxRyHVj5gKEipV0
	 eavJpBTHle48pPfitZJ96gtKfobsv0uaU/9G3qQFag04PrfWu49T8nTdt8WUKvA99LoIu
	 wiG382kK23wJgQhNgzbw7BHPXYWyPrgyUQeI4neq73CFznALaZMNFblkYclYLz3gj9sTV
	 A9plQ+JmvzprQTLFD8w5ulVOe3AeLtG9HiuNw/1NthZyfuLRiL3ZDauyCvygBCuqPOY3n
	 O8Rl2zEg6TyKeNFFxjhkEb7WQcR+Oy5EXk86Z8vfrwWzeYyzeNewwk/Uf/udDu9wCGQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795615685;
	h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc:
	 Date:Message-ID:In-Reply-To:References:X-sashiko-severity:
	 Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version;
	bh=cipA+kILZiIJQlmhgfoyflHJGAWoJdqgBfED6D2DA3Y=;
	b=aYncqIAiLA5ihfMR+5OeVm8kBwZIBSIHHVAkgjUFeHYBFeM5PESGLI0MoWPqiSuF6s/7
	 6BQqlYeO12ox0y4yvrev5Ley+AoI7I0gbD7k42GjePn751X2iKEac5oJSaPNG500EWCA2
	 xgEt8TqF6HjUlRTVirP2gbcWFTeOl6miYuaAterE+Ujtp9mQgZYkpzczlP8wqOvvzUrom
	 SSwOT0ZMUtYLdHECjII0F07aA3UvmjMsuoRDRFpgheAY55gcs2OB35KnICSZBsWB4OfWN
	 awG3/Vhproo/TN2Bl6jPZiHH1eM+HH7oUHxUzkjowbKcAUXADjEe77pigWXIH7nDssg==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b="EyFU3W/D";
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 457FF606A33A;
	Wed, 25 Nov 2026 14:08:05 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=EyFU3W/D
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1795615684;
	b=IZEGKloAg3PVc5YUvRI2fPewZziMIkpG0gXP87jBynArB8yFy5w1Pebarn5wgzN89MNW
	 9zYo1lE+xnfuULeDexVIWSh0MMxpu9n+msmbRPpNt9hkTu+YlkpGqXYlIB8UlyEsOCcqB
	 4k8XnbG+a+A19lV0/FsJb8rnm/sUGtCIyY7t2iu8nmJ/5npjpgQtU8dfcvkbLAvpu+f6g
	 FvgM26WFWy6E4IzT4OcS4Ew8mjlgjdGVw3UVOc1N7drQ0TF8qCig8APGpURW6OhaIDfcz
	 DJIvaJ3RimmO0CrEWz5vYnLrF0QYDgw1gHjja9q3//QG94548LlmvbhfG0CIWZ8ZAjg==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795615684;
	h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID:
	 In-Reply-To:References:X-sashiko-severity:Content-Type:
	 Content-Transfer-Encoding:MIME-Version;
	bh=cipA+kILZiIJQlmhgfoyflHJGAWoJdqgBfED6D2DA3Y=;
	b=kUFHrG59auuO7OGpjCcjenxALezBpCuZRKK8zHNRn+bs7Cc1WABV2IrGMzbmu7NBbBQz
	 zdxBsdAcxHYKbr3bIIbT4UINW5aR1S7iBpyYw1vVj0LfHiR4uzGBlgoRO7d00fLwVc/9B
	 obAgJNbiWZv0EvIh+kNmgezHfWBXzilh1YrFb2HO35OdadS+JiFHXABjcUYUdbiRJqvxu
	 Qy1m7v6ihdkQ55n+GMPsJBDi1CVTrOoqYQOQjUXyrnCU/+UzV2RrlCo5lvCyjnTleH83A
	 NRWdcmP0OO/pdTXjRdcmM+HOJLOsthiQo6yhs+WdCkadp8pj6mtD5hWEM1ZBCyagooQ==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b="EyFU3W/D";
	arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 64C24606A330;
	Wed, 25 Nov 2026 14:08:04 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 668D71F000C4;
	Wed, 25 Nov 2026 14:08:00 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1795615683;
	bh=cipA+kILZiIJQlmhgfoyflHJGAWoJdqgBfED6D2DA3Y=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=EyFU3W/Dl8NqcV26L+1cmrna14csDw/8L2rjmj4K1LssG6qsllNJedujYGTumm6FT
	 za8ONu7mGlUm3XMvOZ0gnYuK+PicgkjKAT5wtKMp/Yu4MiyId/6A3EynKuGlBQRQgt
	 7d7MXixZYfA1EyELKWAwXI/Qh+GRI208912ci1Dwyiw8dW6N6928WGL4jpyWnUEyki
	 udyIsfAMyEKFchLdaTBwgwyHv/Z7Uj2mYxKbQhRkCDu4IXLYZND4ULl/czCW0nrG/V
	 3515Uio0EklXVTbNaZh3WX8jkqbDTs9jDOHNUWDnZagpJZPAGgXOdYLesXowFntrnp
	 OnRe2onIGZ/2A==
X-Cc: magnus.karlsson@intel.com, maciej.fijalkowski@intel.com,
 davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com,
 andrew+netdev@lunn.ch, ast@kernel.org, daniel@iogearbox.net, hawk@kernel.org,
 john.fastabend@gmail.com, andrii@kernel.org, eddyz87@gmail.com,
 memxor@gmail.com, ilias.apalodimas@linaro.org, alexanderduyck@fb.com,
 saeedm@nvidia.com, tariqt@nvidia.com, mbloch@nvidia.com, leon@kernel.org,
 michael.chan@broadcom.com, pavan.chebbi@broadcom.com, corbet@lwn.net,
 shuah@kernel.org, bpf@vger.kernel.org, netdev@vger.kernel.org,
 stuclar@meta.com, sdf@fomichev.me, horms@kernel.org, martin.lau@linux.dev,
 almasrymina@google.com, song@kernel.org, yonghong.song@linux.dev,
 jolsa@kernel.org, emil@etsalapatis.com, ihor.solodrai@linux.dev,
 rdunlap@infradead.org, kernel-team@meta.com, dimitri.daskalakis1@gmail.com,
 bobbyeshleman@meta.com, mohsin.bashr@gmail.com, kees@kernel.org,
 leitao@debian.org, maxime.chevallier@bootlin.com, cuitao@kylinos.cn,
 vadim.fedorenko@linux.dev, mike.marciniszyn@gmail.com, kuniyu@google.com,
 jiayuan.chen@linux.dev, mkarsten@uwaterloo.ca, razor@blackwall.org,
 dw@davidwei.uk, asml.silence@gmail.com, linux-rdma@vger.kernel.org,
 linux-kselftest@vger.kernel.org, linux-doc@vger.kernel.org,
 linux-kernel@vger.kernel.org
X-In-Reply-To: <20261124125654.183091-2-bjorn@kernel.org>
X-sashiko-severity: Low
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list