๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #21491

Re: [PATCH net] net: keep skbs with a prefetched socket out of gro_cells gro

#21491
From: netdev-bot+sashiko
Date: Tue, 24 Nov 2026 03:03
113 lines
11645 bytes
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 fix is incomplete.

--

net: keep skbs with a prefetched socket out of gro_cells gro

This patch makes gro_cells_receive() send skbs that carry a prefetched
socket from bpf_sk_assign() to netif_rx() instead of the GRO cell. The
goal is to stop GRO from clearing skb->sk and skb->destructor on merged
skbs, which leaks one socket reference per merged skb.

> diff --git a/net/core/gro_cells.c b/net/core/gro_cells.c
> index 31352cac355ce..4e8b9c3cd7da0 100644
> --- a/net/core/gro_cells.c
> +++ b/net/core/gro_cells.c

[ ... ]

> @@ -26,7 +27,8 @@ int gro_cells_receive(struct gro_cells *gcells, struct sk_buff *skb)
>  
>  	skb_unset_transport_header(skb);
>  
> -	if (!gcells->cells || skb_cloned(skb) || netif_elide_gro(dev)) {
> +	if (!gcells->cells || skb_cloned(skb) || netif_elide_gro(dev) ||
> +	    unlikely(skb_sk_is_prefetched(skb))) {

[Severity: High]
Is matching only skb->destructor == sock_pfree enough here? An skb that
got its socket from bpf_sk_assign() can still reach gro_cells_receive()
with a different destructor that owns one sk_refcnt reference per skb.

One path: bpf_sk_assign() at tc ingress attaches a non-refcounted socket,
such as a TCP listener or a UDP socket. It sets sock_pfree and takes no
reference. ip_rcv_core() keeps it. Then an NFQUEUE rule matches the outer
ipip/gre/esp packet, and __nf_queue() converts it:

net/netfilter/nf_queue.c:__nf_queue() {
    ...
	if (skb_sk_is_prefetched(skb)) {
		struct sock *sk = skb->sk;

		if (!sk_is_refcounted(sk)) {
			if (!refcount_inc_not_zero(&sk->sk_refcnt))
				return -ENOTCONN;

			/* drop refcount on skb_orphan */
			skb->destructor = sock_edemux;
		}
	}
    ...
}

After an NF_ACCEPT reinject, the packet is decapsulated. With !xnet,
skb_scrub_packet() does not orphan it, so the skb arrives here with
skb->sk set and destructor == sock_edemux. skb_sk_is_prefetched() now
returns false, and the skb is queued for GRO.

skb_gro_receive() then clears both fields on each merged skb without
calling sock_edemux():

net/core/gro.c:skb_gro_receive() {
    ...
	/* sk ownership - if any - completely transferred to the aggregated packet */
	skb->destructor = NULL;
	skb->sk = NULL;
    ...
}

The frag_list merge path in the same function does the same thing.
gro_list_prepare() still allows the merge because p->sk == skb->sk.

Wouldn't each merged skb then leak the reference that __nf_queue() took?
That is the same socket and netns teardown leak described in the commit
message.

The tree already has a general rule for this in skb_prepare_for_gro():

include/net/sock.h:skb_prepare_for_gro() {
	if (skb->destructor != sock_wfree) {
		skb_orphan(skb);
		return;
	}
	skb->slow_gro = 1;
}

veth_xdp_rcv_skb() calls it before napi_gro_receive(). Could
gro_cells_receive() divert or orphan any skb that still has skb->sk set
with a destructor other than sock_wfree, rather than checking for
sock_pfree only? Checking skb->sk directly would be one way to do it.

Separately, the "sk ownership - if any - completely transferred to the
aggregated packet" comments in skb_gro_receive() look wrong for
destructors that hold one reference per skb (sock_pfree on refcounted
sockets, sock_edemux, sock_efree).

>  		res = netif_rx(skb);
>  		goto unlock;
>  	}

-- 
Sashiko AI review ยท https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261121160204.4024204-1-razor%40blackwall.org
Technical Details
Message-ID: <179548941922.3135.9577858774980848901@kernel.org>
Path: mbox-mo1.pugleaf.net!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-369975-linux-kernel-netdev=dewy.ru
References: <20261121160204.4024204-1-razor@blackwall.org>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!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-369975-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net] net: keep skbs with a prefetched socket out of gro_cells gro
Date: Tue, 24 Nov 2026 03:03:39 +0000
Organization: Usenet Network
Message-ID: <179548941922.3135.9577858774980848901@kernel.org>
References: <20261121160204.4024204-1-razor@blackwall.org>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="4039494"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:24WVAb+6V34yLCeAVu3TjVwqX9Y= sha256:BeY8lJQqq/sADWLQL+lI9fRtrJ+CmAjfJQNPfiV5vJs=
	sha1:E1srFbU94cQ7A2vNJPyre6T6DtU= sha256:q6sl3yDpiYpyTQu0slmR/IlCQfb2DeC59jDu8mA8l3E=
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 05C03125DC7; Tue, 24 Nov 2026 06:04:09 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.401
X-Spam-Status: No, score=-3.401 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] 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 gdzg6i3IHp0d;
	Tue, 24 Nov 2026 06:04:00 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=104.64.211.4; helo=sin.lore.kernel.org; envelope-from=netdev+bounces-369975-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 sin.lore.kernel.org (sin.lore.kernel.org [104.64.211.4])
	by mail.dewy.ru (Postfix) with ESMTPS id C9466125DC6; Tue, 24 Nov 2026 06:03:50 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sin.lore.kernel.org (Postfix) with ESMTP id 87A24276FA; Tue, 24 Nov 2026 03:03:47 +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=1795489426;
	b=W8/TyH130xgt3TA9E9Mo7t7ezMvCOJlwDJfcmSOJfFl6u3G4xY/ojjko2dJ11yEgFfaQ
	 ltnGqH88GhPPEQfADhgIBjKYHka97xY/Kd/x9Sp6pWDZWv7lVabsDOn+YBRP7+Vg3+iin
	 0umAO60dzwePqrlT+kCwGw6V272DzCJ32m64phRcMqNitHZXQ9X0LeOakvxEIPYM68uX/
	 NPtvk1Iuh63R4jd/NcdMC5RJPUgJjLLvS9rgeEIdUiywYHEvZpF7XMFzeHZ6G+b8Ip2lq
	 LJ4EQoQvPxGx49X6Gnjx5Oz/r2bZvYUtUryL1L9tZki8pnPRd78lqKlAs/erktyvx0A==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795489426;
	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=QtOO178Xl6HCtpiOteX/ptXW459o9pIRF2Md167GErQ=;
	b=BvbDuB32x1vlLP2Pg4CjBznAeXCVVU/ojJp9u9zF4qg5rI/wvd5ZknMHeIBj49DGqpCq
	 XwTTGWSXNct/GfloOw1JJfKP5Q+lot9jjS5KXGVhelUzgrBvjs0QXxjOvYVtWy+U9K0Ck
	 lUkOWXJh1QVoktmsIqdAtUF197zfDccNBG3BC5KIpz4Q8DMARJfCJPr42bb4ktgjQavLk
	 h4ASsO4TGrO8lMUfV/L8TWqZixtZPGOlotuZI06jxe1nQ81ferzpLJh4v9Cr4lBHiG+vv
	 gnj3owsASXKuHxT+rLPJAjLk5UZ6zp7f/a1+vEIZcSKMRX6xv5lKYQTqWhSdkPIGbBg==
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=c8Hgok7H;
	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 9AA98606A321;
	Tue, 24 Nov 2026 03:03:46 +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=c8Hgok7H
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=1795489420;
	b=shmJf1o/0wgJC/JdIcOn7Ng/2eYw/acyR+sJcGGv3/Z4J1+jCDozzhj0wVlFw3NFoltS
	 EFVj1/TKWbBepRczyPDCCDYwB+l47KF6yE7Umxg/dUM7KKgKuPoxWv08kpvXfn0cGikeN
	 6473G9oxacRoNyC+ynzQHuOvhvJvWdTTi/jeSoC6fO4NVf3FzZb4HxiWfU4Tz4On3Z7RU
	 0S6su2Q5fdbsnWNv6o9/j9RH9aQcXZ9hY269xZvqq3Eb6JeKxTWoQPSk3rQ8V2QpZyqnl
	 Qw+ubjPRVP1rMmOfo3dAZhlB8GQprLkQcpGu33Qx+pyo0Sb7/wdJZYo75LqFzhZUBxQ==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795489420;
	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=QtOO178Xl6HCtpiOteX/ptXW459o9pIRF2Md167GErQ=;
	b=i5q19CYV8geCvli8ssHFnibO86sOMArlbH+JBFR/EzCl1kuqF8+g3+jRq3WpRrsf15iy
	 FbShdTvcEkBlZTYM2BsVyyspvaWVU+XfawSUEbAQxwApF2creKuH/54V/N00B6VorKk+m
	 /nYqj169jdrWZ/h14+hiQc7+OYiWbny+bw0r0vt7eMiK1tGlPvS6tZjV6pJtMrseQ1tEz
	 /Jv0iw0uosnvumhwowCOvr+pTuJsIHNTwSks82UhgODSqjvJ/6Cg78X6orDuHRCMew09V
	 bnG9iLgkYx9IjcgQ1G199fJddGXjCEIyA9b4rJRCRDX+9l0oaCccVTgHCdEbaRcuUhQ==
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=c8Hgok7H;
	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 B910D606A31E;
	Tue, 24 Nov 2026 03:03:40 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id B02331F000C4;
	Tue, 24 Nov 2026 03:03:39 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1795489420;
	bh=QtOO178Xl6HCtpiOteX/ptXW459o9pIRF2Md167GErQ=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=c8Hgok7HkJgGYEstz6ua34gOCO2URWkpB6P9ViYTpCgnFOxb5m7Sx2F/am7iCwWA2
	 pX9aX7R8jNMh6EZp94jDqfj1w+UuBn/BtvdBsM/cqosa019/6bcctUcQBXAo/Y5Aju
	 5e6TubAQCdTLwwdRIFZMUf3Drs8s2YrlE+AVf4PGQfBvHapDaLvBF9T3cCBMOLOV8d
	 lTsHvsnFAEwQhR1uLQNcKZ4pJkriA5pKVDGGTWT3xRKEvJkbZ+Zie09RCKVSTsG8gX
	 GkqNbCHbk+xmffxOtfCw/5b9Cgx/8WGkAg8RTF40gG9bcFsOU9MODgtPI1pvOM2XrE
	 GN2370hlM1R7Q==
X-Cc: netdev@vger.kernel.org, davem@davemloft.net, edumazet@kernel.org,
 kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, ast@kernel.org,
 kafai@fb.com, joe@wand.net.nz, daniel@iogearbox.net, bpf@vger.kernel.org
X-In-Reply-To: <20261121160204.4024204-1-razor@blackwall.org>
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