🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #21593

Re: [PATCH net-next v6 6/7] net: prevent mixing frags from different memory providers or bindings

#21593
From: netdev-bot+sashiko
Date: Tue, 24 Nov 2026 08:14
173 lines
13981 bytes
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

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

- [High] skb_mem_provider_compat() is now called in skb_try_coalesce()
  and skb_gro_receive(), but both functions can still move a struct page…
- [Low] The commit message calls the issue 'theoretical' and only talks
  about mixing provider instances or devmem bindings.

--

net: prevent mixing frags from different memory providers or bindings

This adds skb_mem_provider_compat(). Two skbs count as compatible when
both are readable, or when both are unreadable and frags[0] of each
resolves to the same net_iov provider instance. The check is enforced in
skb_try_coalesce(), skb_gro_receive(), skb_gro_receive_list(),
skb_segment() and tcp_skb_can_collapse(), and skb_shift() gets a debug
assertion.

> diff --git a/net/core/gro.c b/net/core/gro.c
> index c093fe388dfe8..6852b19e48408 100644
> --- a/net/core/gro.c
> +++ b/net/core/gro.c
> @@ -109,6 +109,9 @@ int skb_gro_receive(struct sk_buff *p, struct sk_buff *skb)
>  	if (p->pp_recycle != skb->pp_recycle)
>  		return -ETOOMANYREFS;
>  
> +	if (!skb_mem_provider_compat(p, skb))
> +		return -ETOOMANYREFS;
> +
>  	if (skb_zcopy(p) || skb_zcopy(skb))
>  		return -ETOOMANYREFS;
>  

[Severity: Low]
This isn't a bug, but could the commit message say more about what this
hunk fixes? The message says:

    This issue is theoretical and was found by manual code inspection and
    LLM review; it was not triggered in production.

It only describes the problem as mixing provider instances or devmem
bindings.

Before this patch, skb_gro_receive() and skb_gro_receive_list() did not
check readable against unreadable at all. skb_gro_receive() only compared
pp_recycle, which is 1 for both normal page_pool pages and net_iov
page_pool memory. It also never set p->unreadable.

So the headlen <= offset frags path could merge an unreadable skb into a
readable p. The result would be a readable skb holding net_iov frags.
__skb_datagram_iter() only checks skb_frags_readable() before doing:

	skb_frag_foreach_page(frag, ...) {
		vaddr = kmap_local_page(p);

Here skb_frag_page() returns NULL for a net_iov.

skb_try_coalesce() and tcp_skb_can_collapse() already compared
readability, so for those paths this patch only tightens the check. The
GRO hunks close a much larger gap.

Could the message mention this, so stable maintainers can judge the
impact?

[ ... ]

> diff --git a/net/core/skbuff.c b/net/core/skbuff.c
> index aac61fbe419f2..212d76ef9672e 100644
> --- a/net/core/skbuff.c
> +++ b/net/core/skbuff.c

[ ... ]

> @@ -6620,7 +6667,7 @@ bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
>  	 * belong to the same memory provider instance; do not coalesce skbs
>  	 * that would mix them.
>  	 */
> -	if (skb_frags_readable(from) != skb_frags_readable(to))
> +	if (!skb_mem_provider_compat(to, from))
>  		return false;
>  
>  	if (len <= skb_tailroom(to) && skb_frags_readable(from)) {

[Severity: High]
Can a struct page still end up in an unreadable skb's frag array after
this check passes?

If to and from are both unreadable and share a provider,
skb_mem_provider_compat() returns true. Suppose from carries payload in
its linear area. The tailroom copy is skipped because
skb_frags_readable(from) is false.

If from also has head_frag set and is not cloned, skb_head_is_locked() is
false, so the head gets stolen:

net/core/skbuff.c:skb_try_coalesce() {
    ...
	if (skb_headlen(from) != 0) {
		struct page *page = virt_to_head_page(from->head);
		unsigned int offset;

		offset = from->data - (unsigned char *)page_address(page);
		skb_fill_page_desc(to, to_shinfo->nr_frags,
				   page, offset, skb_headlen(from));
		*fragstolen = true;
	}

	memcpy(to_shinfo->frags + to_shinfo->nr_frags,
	       from_shinfo->frags, ...
    ...
}

skb_gro_receive() seems to do the same after its new check when
headlen > skb_gro_offset(skb):

net/core/gro.c:skb_gro_receive() {
    ...
	} else if (skb->head_frag) {
		...
		struct page *page = virt_to_head_page(skb->head);
		...
		skb_frag_fill_page_desc(frag, page, first_offset, first_size);

		memcpy(frag + 1, skbinfo->frags, sizeof(*frag) * skbinfo->nr_frags);
    ...
}

Either way, the skb has unreadable set but its frags mix a page_pool
header page with net_iovs. That goes against the comment right above the
new check: "All frags in an skb must either all be struct page-backed or
all belong to the same memory provider instance".

skb_zerocopy() already rejects this layout:

	if (!skb_frags_readable(from) && j > 0 && len) {
		skb_frag_unref(to, 0);
		return -EFAULT;
	}

Documentation/networking/devmem.rst says payload lands in the linear area
when the NIC can't split the packet at the header boundary. The remote
peer controls the shape of those packets.

A devmem receiver would then reach this in tcp_recvmsg_dmabuf():

			if (!skb_frag_net_iov(frag)) {
				net_err_ratelimited("Found non-dmabuf skb with net_iov");
				err = -ENODEV;
				goto out;
			}

The skb is never consumed. Wouldn't every later recvmsg() on that socket
fail the same way?

Also, skb_net_iov_provider() only looks at frags[0], so later merges
won't catch a mixed skb once it exists. Nothing later in the series
appears to touch these paths.

Should skb_try_coalesce() and skb_gro_receive() refuse to steal the head
of an unreadable skb, the way skb_zerocopy() does?

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261120201408.3445445-1-almasrymina%40google.com
Technical Details
Message-ID: <179550807001.3135.15837206052330880112@kernel.org>
Path: mbox-mo1.pugleaf.net!news-can.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-370094-linux-kernel-netdev=dewy.ru
References: <20261120201408.3445445-7-almasrymina@google.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-can.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-370094-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net-next v6 6/7] net: prevent mixing frags from different
 memory providers or bindings
Date: Tue, 24 Nov 2026 08:14:30 +0000
Organization: Usenet Network
Message-ID: <179550807001.3135.15837206052330880112@kernel.org>
References: <20261120201408.3445445-7-almasrymina@google.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="4086065"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:Hhq4jdhqkEwojZrspxzFUv+9fr8= sha256:2LqZ5pbYNZWSwqPfWWuxUbUBPmPuSYcbpADjF7f4kBE=
	sha1:CEIFF93yQMuohP7QE0/v3sPmwCM= sha256:m42tm9fUqs6P8YS8rijtTwsXJtctIk1aJXS9HDLikrM=
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 29A96125DD7; Tue, 24 Nov 2026 11:14:50 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.4
X-Spam-Status: No, score=-3.4 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, 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 3gjoTLzJcdTw;
	Tue, 24 Nov 2026 11:14:46 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-370094-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 1E135125DE0; Tue, 24 Nov 2026 11:14:37 +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 ED2C133A9F; Tue, 24 Nov 2026 08:14:32 +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=1795508072;
	b=yZ+WqZR7FkKscVWyy5c+N8po1vugabpJzj73Tqol1AYiZHVF7+Z3A15GcaEvirXtNmXk
	 o4cLR2rMQFhXbsiCKSfFP6jJjtPiml0Tvmq4DJJR48tdwxyT7kMggyszuMRoeLtIEAvoS
	 kjoJaGrB1n5tCFRAy8L2ZllZjZtLuL+aLn+pOScJrpZTTnX7xHS1CDVjLTzUsm5Fj7zp3
	 1L1+z4WES/n7CFXvy2VlN98JNpVXkZeDvUt7LEkhXwFCSVFHlelE2jZbD/qaU77LLnvXe
	 gFoloZDOQc1vojExvn0tN7rT8kUCdmt/vJ0mrIlljtPUAYWh+5JaulCB9moAorQ8nUg==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795508072;
	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=5kIJ6tQi0PHKcy1HxVFl+UQPO7ioAUVMwSZpbfVBl2U=;
	b=JeFoFj++nnZoQ08OihY2E69R9Wi/g1qD1kI4vK8FFqbh1HDguPPIV9voZSyWbzlbjFUT
	 Pk+TfVRfTA0bXy2v2wPck9tWb2SrDwiKzyRF2YfvzLtv074xS8Nex3WRy5VLdXCF58Wz7
	 n29OwZ1bULsaFwYV3irX4+ix9lHVIPNM/qPy6ST/vk9PrynlqrgCyBn/yc4yQotB8f3Y4
	 QzyAU5RZn36I/o4WuqqUDGbK7vaJR3iXR1T1D4qJSMdOo557Of4Zv3dc0vsY8/SUZyJaF
	 UYKVk0WunhIXK4BOeLU1XOuVMjEbWCGdehpBBlp56oQ/N0s8gOklv63vxDIapxsf+Dg==
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=XgFZtFdF;
	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 BD7B1606A331;
	Tue, 24 Nov 2026 08:14:32 +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=XgFZtFdF
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=1795508071;
	b=vpNXRMQmEQs0G8DF7UF1ZMowrE0hB4gmskmyQeHvx+3CYvytHFqAyK6+copAPekkB6ix
	 oLkGDpyozXSvcSAXEurL58Q2FkP3k2/Ig7l2o2SJsjNGoGl0N8CIQvD/TR9IucmRBADu9
	 hV2l36TN+/j2x6DoMZfgtQOW3slg3mTl/uEe8TQ8hAfKFRPgNVMvajqxpWTyY1PGBmEJS
	 c+YF45OYlPnITF7usFZ9u74nYGd1CUb1H2qI4mdblLUj+CRQXxeqMyEBXsTQbQwgiBZ8o
	 2u2oJRWnQehRtKaPJtLtsLp8cks8wDX/xQsAHfqquAP7c4/VdzhqEZNlhf13oPyK4cg==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795508071;
	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=5kIJ6tQi0PHKcy1HxVFl+UQPO7ioAUVMwSZpbfVBl2U=;
	b=i6efuHN+IJxEuF9Jukrpk7R0n9T8YGDbCUhI+oyo58ouOAB43rgSpXLvmDGBl4p6ZDsj
	 KJxGVEvTi2rGYurK2MNHGLKKtPhRH4o5Swxqy+MFjJjYJZK3Afykbu/8DX7fLeLMOGEIJ
	 nMMdxE+QgHKfLTuoW2EUXvofe/3gkauBngSC91Eh7B3GU48P/l38l4qBiZi3x4/fMEfKv
	 laJn9V3R3w9pxkEWnvhJJ70GZBY37X+/Mc2NJMSzLD1fSQoF1EDha9O5K/TAvwLEz2YhG
	 xeC7Ss2ziSj0hubUwk85H+8jlv2cBrxin6BPmivwr+6Hr/LDo3bRHAcTxkq6xb0aFsA==
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=XgFZtFdF;
	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 D9841606A330
	for <netdev@vger.kernel.org>; Tue, 24 Nov 2026 08:14:31 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6B6951F000C4;
	Tue, 24 Nov 2026 08:14:30 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1795508071;
	bh=5kIJ6tQi0PHKcy1HxVFl+UQPO7ioAUVMwSZpbfVBl2U=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=XgFZtFdF0V4fbRTG5wXJzkN+0nEC84NCbktt2Dgz/Z6AV4hiJk/+4xdb5OVgHTe98
	 d1DyJBHFEcOJXlQRGzHGB5qmYW4wRFNVPoHTGbOpqCfxK1d3WpY5qS94QymFAEbeKx
	 8R2F15BDHj9k/PXTZqEgE/VFzSZ59ZkbOmQJXXyChtKmQXdYaU75NRoN09RUMauuyQ
	 SRN6Fjt3K4IwYCoM+jiSNE78O6pmkCH/6aCJB2xAmSSrq07CwE/NB23VO8zL42P0QN
	 TRuCCvQFPoS5qo4WAWCtt+t0RYjFJ+1UrUPwPqMAsgpfw/CF+x9WrldyF0LqNbs9im
	 uJd0hOoNObLlw==
X-Cc: netdev@vger.kernel.org, edumazet@kernel.org, ncardwell@google.com,
 kuniyu@google.com, davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com,
 horms@kernel.org, sdf@fomichev.me, kaiyuanz@google.com, willemb@google.com,
 daniel@iogearbox.net, josef@toxicpanda.com, sdf.kernel@gmail.com,
 dtatulea@nvidia.com, asml.silence@gmail.com, bobbyeshleman@meta.com
X-In-Reply-To: <20261120201408.3445445-7-almasrymina@google.com>
X-sashiko-severity: High
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