From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795014416; b=A5xzH0OY8niElmfWaLeOmd6GySTvImmC7Q7RPpBFoKk8XToohqWHNVmcojj3gTjnqJvR lqg9uMnS/mrEzkX+3PBmcjUPAN40c1a9xIIA8vZkED9xBybUg5qxzTl1PFgViuVsjAwXE RXUUA5xu9rR3TyWMQaE2uNK9EECBF7p5s5FJEkagLGSoylve7ZHg9lP85WTuNO48AHqkh mTgaKvWnvA66odAxILpyvPjwpii2/YoFLfm/iFOk9Rmod3I5YiEfV5hzi/5PfU4I2D8Y3 AxrypvJQwGeujplh9v18cdtPxy8TMcJB05oHB8JSgDJM7QonNZzBUJmVSg8NI5cHARA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795014416; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=ftKFUNowZzQxWQZGicToyZ8aLd002MKmbxo09EDj6kg=; b=qqyY8rmNBW9YqHxj2MjB8wf4xn/qXJobOrUgBFzt2gXx6RjAAKEnnozNVFbKDD02Cfdp zDwbAzgFko7zd8tvzkf6bEu3bqHrhtJV3Vh7L+ec/TudPFt6UeCG3kgfAjb2P1Q0YroQq tEtvRlAEjzdzl7fYwuNcToogf76yQFZYHVagoZDj5aZkrj9fhvJUVgrNOOOpQdoYZRC3m BNPXsc8Ql35hAUbxVtufCifwYfcEQbJcrE602eU7hx9SGfMpcQqxmbCldbsxQBvGdZfG7 lnWsFGYK7koZ6PuhRApcjQ1DlagJjmsGugIm5LzvNShyIuuHv/PjZMwuqLKw/raDZUA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=QUgV+IlI; arc=none smtp.remote-ip=100.103.45.18 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 5F0E3606A31C; Wed, 18 Nov 2026 15:06:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=QUgV+IlI Received: by smtp.kernel.org (Postfix) with ESMTPSA id BA41A1F000C8; Wed, 18 Nov 2026 15:06:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795014416; bh=ftKFUNowZzQxWQZGicToyZ8aLd002MKmbxo09EDj6kg=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=QUgV+IlIC62KBn7JKgXDbCgHOMT4szGe/0z7fehC17BfqZ3iy7SDRRE2Fk9WW0xCD iRVjnf+eilUjhr0qDltc5Y1o2spAamiTAPDts/nekJfFApB/LGMVNl290BFJU814tx 8NgPklCQO2ruR7MwD3IyQPCCiM053ujp1VV3+NnY= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Kyle Zeng , Florian Westphal , Eric Dumazet , Ido Schimmel , Jiayuan Chen , Wang Zhan , Paolo Abeni , Sasha Levin Subject: [PATCH 6.18 0002/2151] inet: frags: limit the truesize of a reassembly queue Date: Wed, 18 Nov 2026 15:28:57 +0100 Message-ID: <20261118150121.724065764@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261118150121.603863898@linuxfoundation.org> References: <20261118150121.603863898@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Eric Dumazet [ Upstream commit 3ae20e4697eb969104fe4b1e98a675f0100382b6 ] 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 Cc: Florian Westphal Signed-off-by: Eric Dumazet Reviewed-by: Ido Schimmel Reviewed-by: Jiayuan Chen Tested-by: Wang Zhan Link: https://patch.msgid.link/20261030081225.2575462-1-edumazet@kernel.org Signed-off-by: Paolo Abeni [ sashal: Adjusted context for the absence of IPFRAG_MIXED_SECPATH and secpath_equal(). ] Signed-off-by: Sasha Levin --- 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 365925c9d2628..6aea2d1ac376f 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; }; @@ -171,6 +173,13 @@ extern const u8 ip_frag_ecn_table[16]; #define IPFRAG_OK 0 #define IPFRAG_DUP 1 #define IPFRAG_OVERLAP 2 +#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 21f7bf9ea5ba2..436b8737b2b66 100644 --- a/net/ipv4/inet_fragment.c +++ b/net/ipv4/inet_fragment.c @@ -337,6 +337,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); @@ -443,6 +444,9 @@ int inet_frag_queue_insert(struct inet_frag_queue *q, struct sk_buff *skb, { struct sk_buff *last = q->fragments_tail; + 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 @@ -507,6 +511,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