🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #8815

[PATCH v2 net] inet: frags: limit the truesize of a reassembly queue

#8815
From: Eric Dumazet
Date: Fri, 30 Oct 2026 08:12
102 lines
11633 bytes
The truesize of fragments in a reassembly queue is only bounded by
the per netns ipfrag_high_thresh sysctl, which has no upper limit.

inet_frag_reasm_finish() sums the truesize of all fragments in an int.
If this sum reaches 2^32, it wraps, and the final sk_wmem_alloc
adjustment of the socket owning the reassembled skb can cancel its own
reference, leading to a use-after-free of this socket.

This can be triggered from an unprivileged user/network namespace,
raising ipfrag_high_thresh and using padded TUN packets, which keep
a large truesize after being trimmed by ip_rcv_core().

Track the sum of the truesize of fragments in each queue, and refuse
a fragment that would make it bigger than INT_MAX / 2. Callers kill
the queue on this error. This bound is far above the needs of
legitimate traffic.

Fixes: 18685451fc4e ("inet: inet_defrag: prevent sk release while still in use")
Cc: stable@vger.kernel.org
Reported-by: Kyle Zeng <kylebot@openai.com>
Cc: Florian Westphal <fw@strlen.de>
Signed-off-by: Eric Dumazet <edumazet@kernel.org>
---
v2: reset q->truesize in inet_frag_queue_flush(), as ip_frag_reinit()
    can keep a queue alive after flushing its fragments (Wang Zhan, Sashiko).
    Document @truesize in struct inet_frag_queue kernel-doc (Sashiko).
v1: https://lore.kernel.org/netdev/20261028182934.2236310-1-edumazet@kernel.org/

Kyle Zeng provided a more complicated patch, I wrote something much simpler.
LLM was used to discover the bug, build a repro, and test the fix.
---
 include/net/inet_frag.h  | 9 +++++++++
 net/ipv4/inet_fragment.c | 5 +++++
 2 files changed, 14 insertions(+)

diff --git a/include/net/inet_frag.h b/include/net/inet_frag.h
index b02d2472b003ec6e7b8e391d56115e8f0578ca61..c1fb419a9cf03a346edd0424ca0ba5b06b6a20f0 100644
--- a/include/net/inet_frag.h
+++ b/include/net/inet_frag.h
@@ -79,6 +79,7 @@ struct frag_v6_compare_key {
  * @tstamp_type: stamp has a mono delivery time (EDT)
  * @flags: fragment queue flags
  * @max_size: maximum received fragment size
+ * @truesize: sum of the truesize of queued fragments
  * @fqdir: pointer to struct fqdir
  * @rcu: rcu head for freeing deferall
  */
@@ -100,6 +101,7 @@ struct inet_frag_queue {
 	u8			tstamp_type;
 	__u8			flags;
 	u16			max_size;
+	unsigned int		truesize;
 	struct fqdir		*fqdir;
 	struct rcu_head		rcu;
 };
@@ -172,6 +174,13 @@ extern const u8 ip_frag_ecn_table[16];
 #define IPFRAG_DUP	1
 #define IPFRAG_OVERLAP	2
 #define IPFRAG_MIXED_SECPATH	3
+#define IPFRAG_TOOBIG	4
+
+/* Max sum of the truesize of fragments in a queue. This keeps the sums
+ * done in inet_frag_reasm_prepare() and inet_frag_reasm_finish() well
+ * below INT_MAX. Legitimate traffic stays far below this limit.
+ */
+#define INET_FRAG_MAX_TRUESIZE	(INT_MAX / 2)
 int inet_frag_queue_insert(struct inet_frag_queue *q, struct sk_buff *skb,
 			   int offset, int end);
 void *inet_frag_reasm_prepare(struct inet_frag_queue *q, struct sk_buff *skb,
diff --git a/net/ipv4/inet_fragment.c b/net/ipv4/inet_fragment.c
index c18da91c1f031ee0b97f9e072837d053380da2f2..0b8d22ffafca69b2bccd98eca3d4bda93ebb816a 100644
--- a/net/ipv4/inet_fragment.c
+++ b/net/ipv4/inet_fragment.c
@@ -336,6 +336,7 @@ void inet_frag_queue_flush(struct inet_frag_queue *q,
 	q->rb_fragments = RB_ROOT;
 	q->fragments_tail = NULL;
 	q->last_run_head = NULL;
+	q->truesize = 0;
 }
 EXPORT_SYMBOL(inet_frag_queue_flush);
 
@@ -446,6 +447,9 @@ int inet_frag_queue_insert(struct inet_frag_queue *q, struct sk_buff *skb,
 	if (last && !secpath_equal(last, skb))
 		return IPFRAG_MIXED_SECPATH;
 
+	if (skb->truesize > INET_FRAG_MAX_TRUESIZE - q->truesize)
+		return IPFRAG_TOOBIG;
+
 	/* An IP fragment is never a GSO packet, but an untrusted source
 	 * (virtio_net_hdr) may have attached GSO metadata to it. Do not let
 	 * that reach the reassembled skb, whose head keeps the first
@@ -510,6 +514,7 @@ int inet_frag_queue_insert(struct inet_frag_queue *q, struct sk_buff *skb,
 	if (offset)
 		nf_reset_ct(skb);
 
+	q->truesize += skb->truesize;
 	return IPFRAG_OK;
 }
 EXPORT_SYMBOL(inet_frag_queue_insert);
-- 
2.53.0
Technical Details
Message-ID: <20261030081225.2575462-1-edumazet@kernel.org>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-353642-linux-kernel-netdev=dewy.ru

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-353642-linux-kernel-netdev=dewy.ru
From: edumazet@kernel.org (Eric Dumazet)
Newsgroups: linux.kernel.netdev
Subject: [PATCH v2 net] inet: frags: limit the truesize of a reassembly queue
Date: Fri, 30 Oct 2026 09:12:25 +0100
Organization: Usenet Network
Message-ID: <20261030081225.2575462-1-edumazet@kernel.org>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="2188429"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:B6wfy2dt9EIzkuSOxVsRNwJ+1AM= sha256:WucFusjvwuK6LWASsrxfYtaywU/D5I6Iw9rjYRKSqyY=
	sha1:jEh2aDyYOz62dAg6ndsrEmvoX2M= sha256:2cSoNfgsBAojj0wzx/7UfaqLN97LffFbgBnPSOuS5Do=
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 942E7125C8A; Fri, 30 Oct 2026 11:12:58 +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 Pp14jZ6Q-uJm;
	Fri, 30 Oct 2026 11:12:55 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-353642-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 C50B1125C89; Fri, 30 Oct 2026 11:12:45 +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 771EE2B378; Fri, 30 Oct 2026 08:12:37 +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=1793347957;
	b=Q0OcBF8/O2FIYjML8Nxr6GumkLbWPdcp8O6ZF/cWaDBapnr+GMtTRtSD8p2XIKe/edzI
	 yR4A1pdsnpqXBgjXfCxTJBxa5q3kluXUNkGnDqKlB0QsmNI3c7O1DWwA7ORbDI8UJG7gU
	 LkuQ79m0S0LMiShmfpQuLPatZSic+0Igil9wRpgm1vhveTn7VpQ3TqIkmDRku8EW6HNgz
	 48G1k9QafLMbb7xO9BigLZh9eMz2UPwXIUMtLx6eHkJGUEBuTVGq9QF5AOTC/A9tLD2f+
	 xMlYtxoLqEAx2tZ/+5gqvjnDX479jr946LnHj+HHrtc4pQ/p0tKdQKnzZe31Ki0TfvA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793347957;
	h=X-Original-To:Received:Received:DKIM-Signature:From:To:Cc:Subject:
	 Date:Message-ID:X-Mailer:X-Mailing-List:List-Id:List-Post:List-Help:
	 List-Subscribe:List-Unsubscribe:List-Owner:Precedence:MIME-Version:
	 Content-Transfer-Encoding;
	bh=cwt4Hg4qMuIaaCvAXceJlYQIKFNEo2HNhM36aeH05D4=;
	b=a6dhUiqZCTQSvMYo077g2RQDv+XRHR+QRxrc9mDykBPNEZJE1cGE6cgf83f2F9MkTj/M
	 K5l3vWcLwDm+3XY7aVKgggMAeo4BwQJDXvbwMszfxwbQbO7Z+4OGNbm+pYfSqNJRAji5N
	 y0e/MAS8as6yAjqXhqKPyhUpQ1XDMUvRqkRxAFtqgmMvS0N92sipesyZD4m8KCr5i2Erw
	 ucicItXPnPbnfmb4mzM1iicCKbZ9dz2DiDpAVNxlntETRP2pBYbZmqmYTiRLMEQ4BUIn/
	 OAOLGGzoBW7SWJh/3Ywg1kU3WfuyNwEU9th2e1iZMGyIMEpc8SUeChQtn2+np6ARaOg==
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=QJnsaMfq;
	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 0E664606A323;
	Fri, 30 Oct 2026 08:12:37 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=QJnsaMfq
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=1793347951;
	b=btNvBLrGtnGufJpGzOG95Tta9NDBdAJS1ETEsH0cmkSZ+Oj5EBQXSDfTNcR7mti+exfI
	 xC6U0e5dM1aHLoI8iGc9dd9LS/ajHofiQvtiV6m3mzsjsgH/a8E9gtdL8XFnso087CBTJ
	 7NlKcSJ1TadfZLMQ/yiPOWSs/k0TpsEe0s/Pf/ko4A937c3bltf17mpFXgLWT9aIVGVXM
	 XotDJL44BY7qvNbQiOpI/r0J+wIZb8K3AyN5NFEj8Q7mN1wLBS9r4CoitrqRiaXiOpUgC
	 bq2HVbGT3L8jqgD0wjmcjFFnR6zhLAQ2X+OVTRC7jgf/X4n1Gby2E55t+mkjavheI+g==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793347951;
	h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer:
	 MIME-Version:Content-Transfer-Encoding;
	bh=cwt4Hg4qMuIaaCvAXceJlYQIKFNEo2HNhM36aeH05D4=;
	b=xuBoMPdx64+2VQJPLrspW0LsTl83BwTlG5VeAh9hE9S67nQmgSpBCviBp3ZuLOIVohS3
	 T1Lrh2Ek5OmXk9J2+vLLNs8vZOLZ+2UWaQZmegx3JgHbF70lk0bzUjkUAA74aP6Pg63Oa
	 U95R99uvYkYCUCSpL1795cqWdQ3/2Ge3909ZzpIPiKKO/i0N3Qq+eZfeM7IFxDPYa79FB
	 rlb0PKMJldlzGL25c9vnR2BgobHzqj6CrOCwVeuVthJ59kx6Wh4wJ6qYRqy8dZ5xyQY0D
	 YFSfYXoJ2FAWgiwO+/rfubzLRSLRvqE3OHp/koRYCupm1rMlSdr+0iQMtEBuEHAI/Gw==
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=QJnsaMfq;
	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 DEDB1606A31C;
	Fri, 30 Oct 2026 08:12:30 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id DFF631F000C1;
	Fri, 30 Oct 2026 08:12:27 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1793347950;
	bh=cwt4Hg4qMuIaaCvAXceJlYQIKFNEo2HNhM36aeH05D4=;
	h=From:To:Cc:Subject:Date;
	b=QJnsaMfq3q22zM8v2AhRdonJAq1zicvekS3FWa1Wh3jaP7OM653ElGaDufODpuzLn
	 atlGfBVEhY9P5V4x7Qn8r+6cchg/KJ4KmNZAwpBlZV4oKhZ82gRdt8NttcsYYeDLBV
	 /YHj2XhHaSQnc89zxkHY7EROmScwcnleDu541wUoYKAd9VsNDPjwQmb+xio+KiaoP8
	 SZoLRvYQkMTGdyP0tIJRL9vYkW2L2D5XdPWpvqCQWB+hY6dcpbxa91wLSK82F2ewLl
	 wiSTzcqT4KrkYesxYrU2Z6h1LoKOsL+v+mC2WaGYCsgS1FEFAQ/SH8SjdLNdtNKBqm
	 SH6mfc10UZaNg==
X-Cc: Simon Horman <horms@kernel.org>,
	David Ahern <dsahern@kernel.org>,
	Ido Schimmel <idosch@nvidia.com>,
	netdev@vger.kernel.org,
	edumazet@kernel.org,
	stable@vger.kernel.org,
	Kyle Zeng <kylebot@openai.com>,
	Florian Westphal <fw@strlen.de>
X-Mailer: git-send-email 2.53.0
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