๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #26874

Re: [PATCH net v3 4/4] xsk: Keep the shared info of zero-copy buffers in kernel memory

#26874
From: netdev-bot+sashiko
Date: Fri, 04 Dec 2026 10:39
124 lines
13259 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] The commit message understates the bug it fixes.
- [Low] The AF_XDP selftests still model the old UMEM layout, in which ZC
  multi-buffer pools reserved skb_shared_info tailroom at the end ofโ€ฆ

--

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

This moves the skb_shared_info of zero-copy multi-buffer packets out of the
user-writable UMEM chunk tailroom and into the xsk_buff_pool. A new
XDP_FLAGS_SINFO_EXT flag tells xdp_get_shared_info_from_buff() to use
rxq->ext_sinfo, and xdp_data_hard_end() then reserves no tailroom. The
UMEM headroom limit in xdp_umem_reg() is relaxed to match.

> 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.

[Severity: Low]
Does "read and write out of bounds" fully describe the impact?

Before this patch, xdp_get_shared_info_from_buff() returned a pointer into
the UMEM chunk tailroom for a zero-copy head. Each skb_frag_t stored there
holds a netmem_ref plus len and offset. That means userspace could forge
the page pointer, the length and the offset, not just nr_frags.

The consumers use those values directly. xdp_copy_frags_from_zc() does:

	memcpy(page_address(page) + offset, skb_frag_address(frag),
	       len);

This copies from a kernel address that userspace chooses into an skb that
is passed up the stack. bpf_xdp_frags_increase_tail() does:

	memset(skb_frag_address(frag) + skb_frag_size(frag), 0, offset);

This writes at an address that userspace chooses.

__xdp_buff_add_frag() also reads nr_frags back from the UMEM. It only
rejects nr_frags == MAX_SKB_FRAGS, so a forged count of up to 255 sends
the frags[] write far past the chunk.

This gives userspace a kernel read and write at addresses it picks, not an
access limited to the area next to the chunk. To reach it you need
ns_capable(CAP_NET_RAW) in xsk_create(), a netdev that supports zero-copy,
and an AF_XDP socket bound with XDP_USE_SG in zero-copy mode.

Could the commit message state the real impact and the privilege needed?
Stable reviewers and backporters use that to triage. The patch also relaxes
the headroom check in xdp_umem_reg(), so they need it to weigh that change.

> 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: Low]
Should the AF_XDP selftests be updated along with this layout change?

They still assume that zero-copy multi-buffer chunks reserve
skb_shared_info tailroom at the end. test_xsk() in prog_tests/xsk.c and
main() in xskxceiver.c both compute:

	/* 48 bytes is a part of skb_shared_info w/o frags array;
	 * 16 bytes is sizeof(skb_frag_t)
	 */
	umem_tailroom = ALIGN(48 + (max_frags * 16), cache_line_size);

In prog_tests/test_xsk.c, testapp_adjust_tail_grow_mb() still has the
comment "4k is truesize, 3k payload, 256 HR, 320 TR". It also subtracts
umem_tailroom from grow_size.

testapp_stats_rx_dropped() subtracts umem_tr when it sets frame_headroom.
That lands exactly on the old xdp_umem_reg() limit
(4096 - 256 - 128 - 320 = 3392).

These sizes are conservative, so the tests still pass. However, no test
covers a zero-copy bpf_xdp_adjust_tail() grow up to the end of the chunk.
No test uses a UMEM headroom above the old limit either.

Wouldn't these tests pass just the same if the kernel still reserved the
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);
>  }

[ ... ]

-- 
Sashiko AI review ยท https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261203095647.3448925-1-bjorn%40kernel.org
Technical Details
Message-ID: <179638077906.3146.4204032299868924468@kernel.org>
Path: mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-377255-linux-kernel-netdev=dewy.ru
References: <20261203095647.3448925-5-bjorn@kernel.org>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-377255-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net v3 4/4] xsk: Keep the shared info of zero-copy buffers
 in kernel memory
Date: Fri, 04 Dec 2026 10:39:39 +0000
Organization: Usenet Network
Message-ID: <179638077906.3146.4204032299868924468@kernel.org>
References: <20261203095647.3448925-5-bjorn@kernel.org>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="2742325"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:xRn2c1g1f2G2V692i73GyRflpDM= sha256:7LsbWWgdf528m8yKdqrpoxI2CDnimzWebssuI0Hlqnk=
	sha1:FlESALXyEB73EVxejOSKiBoEuFE= sha256:l4gtB9okIphNrLiBdBp38520m1E9ve7bQ8KVpAa01QY=
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 B2A40117BA8; Fri,  4 Dec 2026 13:40:03 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.541
X-Spam-Status: No, score=-3.541 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.142, 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 Xufxp4uJG7TO;
	Fri,  4 Dec 2026 13:40:00 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-377255-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 sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 71631117BA4; Fri,  4 Dec 2026 13:39:51 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id E77F6325E6; Fri,  4 Dec 2026 10:39:44 +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=1796380782;
	b=BNUIyTP0OKCgBb05rHGoscjTFfYKxk17628flhlTShfmON76ROBP5hiswwBvPe+pXNTa
	 nl3AxFQJnX0yohGyBUl0N3nmwpM6gfZ6LF+MCletRFg0TEtHIKtseFb8hyGphPxIHiyQM
	 VnDh5O/qOA4HC9TmPoJWbhuy0NhlfyXvAOTKo33c7WPnp+jQnS5gOMx2YOr6ld1bPWA1V
	 hmoEm8+WEbsE8ncjFMGaUe7lUhxvYfFbMtZbmvQybsHgWyGQOB7kZ3a2/ddBLJYdjOwnQ
	 Fyr5QZtw4O+kgICfBZaucjdyXNHnMf3AjS/VogOPKSXxaQ4vBEvYyd9rCFrUuCnY1/w==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796380782;
	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=NvMqtwTJ0gPIXlQ2cGXtbbpJEcWjV1pfZphOh2t3qU8=;
	b=OFgK+0XHZkyaZ/b0rlGht8SwmNcyK1IRefFwzs/TcyztWtqSgesBx5iD/xBbM/Mum5fu
	 IP2eUsRrrSfBlzn/bHnr5kTq/kQSTXv9KaFNR+7L4kVHI8jom4eWBm45Lw0sk2/+hFI24
	 MEK6TKURGgWfTgYBlRm5DUUbWXIp8ffTeplsKQqjUq9SlY9oNNND6r84QudiQRW9a/r9z
	 9fMgCj2aU5IMDqacQ0GFmqiYYS2VifpvZoGE2vcEVmL+rEcn+s6xDgY2Q8Eg6JIjesl5Z
	 mueYNbHrYSBSBcUHpwDgDlVhZdTZ9mRe72UERsCpOcri2YI22hVKoVcdT+rrZFAKapg==
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=F9uB26Y6;
	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 6127C606A322;
	Fri,  4 Dec 2026 10:39:42 +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=F9uB26Y6
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=1796380781;
	b=SMdh2MmKaR6Zre3zo0dAJtFoHulT3DKmw8XWNLM3smg+DeD9MjN2LuV/JeukupjSKUHj
	 +KVwIAJf9uBFXx8LZKGPKGRTiY/zvm498NcnUKK0MS6nUuDtDrxdJDbOwwwkRKRXTdjkl
	 aMX+jbU07yNSrl1yPR7+uDrAIf3H56frqSWH0Tlypcnn+WzadoQtxTsLE5fq1oC/+vhQo
	 9TVsRevJct5BtAqQTxrnMYN9WkTCMkSnNFpUpie3FXRjWbFo6SlLslghuaqSzWJKvVHiA
	 isoZPoF9hObasQRvRacN51pANfIjU0Fl7fxD109FPjNQh29Frllyswnyi63Boku+pWw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796380781;
	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=NvMqtwTJ0gPIXlQ2cGXtbbpJEcWjV1pfZphOh2t3qU8=;
	b=Mb6SXwJ2VOu4v4xU//fYFFBHP59OlgwX4c7ZynvsAhFTUoIuQU5XW8nIL4IdeL9+1rgo
	 1TlkJlTUOzkmsEe7qHUYHf9ExXEzqjlBO6ua9Xp1szrwvbpMTRxaKRGDqwrbTDnK18AMv
	 +5VDIIKyfg1zIu6CruLfWrUdI0QrVdt8WNhjbf9/5i1Y6IlvANMjanLnPan8hgn0KUZUK
	 SaQWtC7jBY2oFdkxzz32IAxxPOZWWLwXGvoZR8kcsEpM0dVxo11iKcQS+0N23qKoHlu3I
	 7VgnK3q4i9SbUBwNd0cMBkKVEO1oQU9Q+W+HFl2NuzqkQKGye5h5Wx3DVUmPTiSIo8A==
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=F9uB26Y6;
	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 80C88606A332;
	Fri,  4 Dec 2026 10:39:41 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7FE9E1F000CE;
	Fri,  4 Dec 2026 10:39:39 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1796380781;
	bh=NvMqtwTJ0gPIXlQ2cGXtbbpJEcWjV1pfZphOh2t3qU8=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=F9uB26Y6d9D2IB8pyuZ8ZPDzAzaNyvjZULAmbKtb8yO2d9YaSQGqawNn0K4CYKyjC
	 hDCF9mrSVRP3YGPpygG9WLffJiy3xxEWdfXUM54jWp5W8rCCjs9Ha+aIToPEDhuSTf
	 WL3/rGA4+p3SQZ0ckvFM87D7yC7ygpcyO6ZmZXl6y2daBw/D3T4SYIeWWjQB+prtfO
	 2HkuQYWCRTv/YA2xujQ8UbZCVrGkL+WJnFTl4FPCiMhE78UJWo2LiIkU9/lDwSp/Zv
	 8UQGbSe3sIqyzkqVp9i8PZuKvVJYyzhFdqDydSP/E99+RxRn97CZLA4VmpFUoh/nd/
	 ez+3weobvMYZA==
X-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, andrew+netdev@lunn.ch,
 anthony.l.nguyen@intel.com, przemyslaw.kitszel@intel.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, intel-wired-lan@lists.osuosl.org,
 clecigne@google.com, michal.swiatkowski@linux.intel.com,
 sriram.yagnaraman@ericsson.com, kurt@linutronix.de
X-In-Reply-To: <20261203095647.3448925-5-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