๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #26545

Re: [PATCH net] net: ipv4: reject invalid fragment ranges

#26545
From: netdev-bot+sashiko
Date: Thu, 03 Dec 2026 18:14
131 lines
13024 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 patch does not close the bug it says it fixes.

--

net: ipv4: reject invalid fragment ranges

This patch adds an end <= offset check to inet_frag_queue_insert(). The
check rejects invalid fragment ranges that nf_ct_frag6_queue() can produce
when payload_len underflows below the extension header length. The goal is
to keep the rbtree ordered, which avoids the inet_frag_reasm_prepare()
WARN_ON() and the one-byte out-of-bounds write in nf_ct_frag6_reasm().

> diff --git a/net/ipv4/inet_fragment.c b/net/ipv4/inet_fragment.c
> index f330d0a398233..9f3b632f57536 100644
> --- a/net/ipv4/inet_fragment.c
> +++ b/net/ipv4/inet_fragment.c
> @@ -444,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 (end <= offset)
> +		return IPFRAG_OVERLAP;
> +

[Severity: High]
Does this check fully close the one-byte out-of-bounds write in
nf_ct_frag6_reasm() that the commit message describes?

It catches the case where payload_len underflows. But nf_ct_frag6_queue()
still takes end from payload_len and never checks it against the bytes the
skb actually holds:

net/ipv6/netfilter/nf_conntrack_reasm.c:nf_ct_frag6_queue() {
    ...
	end = offset + (payload_len -
			((u8 *)(fhdr + 1) - (u8 *)(ipv6_hdr(skb) + 1)));
    ...
	if (pskb_trim_rcsum(skb, end - offset)) {
    ...
}

pskb_trim_rcsum() returns 0 and does nothing when len >= skb->len. An skb
that holds less data than its payload_len claims is therefore queued with
the range [offset, end), even though its skb->len is smaller and can be 0.

In the act_ct path, defragmentation runs first:

tcf_ct_act()->tcf_ct_handle_fragments()->nf_ct_handle_fragments()->
nf_ct_frag6_gather()

nf_ct_skb_network_trim() only runs after that, and it hits the same early
return. Nothing rejects these short skbs before they reach the defrag
queue. The native ip6_frag_queue() path is not affected, because
ip6_rcv_core() has already checked skb->len against payload_len.

inet_frag_queue_insert() detects overlaps with the real last->len and
frag_run_len, not the claimed end. Consider this sequence of fragments,
all with the same frag id, saddr and daddr:

1) Fragment Z has an IPv6 header and a fragment header with nexthdr set to
   NEXTHDR_NONE, frag_off 0 and IP6_MF set. Its payload_len is 16 and it
   carries no data (48 bytes total).

   ipv6frag_thdr_truncated() returns false, because ipv6_skip_exthdr()
   returns -1 on NEXTHDR_NONE. end is 8, but skb->len is 0 after
   pskb_pull(), so pskb_trim_rcsum(skb, 8) does nothing.

   The new end <= offset check passes. fragrun_create() makes a run with
   frag_run_len 0, and fq->nhoffset is set to 6.

2) Fragment D has offset 0, IP6_MF set, and 8 bytes of data behind about
   1KB of hop-by-hop and destination options headers, so nhoff is about
   1064. In inet_frag_queue_insert():

	else if (FRAG_CB(last)->ip_defrag_offset + last->len < end) {
		...
		if (offset == FRAG_CB(last)->ip_defrag_offset + last->len)
			fragrun_append_to_last(q, skb);

   Since 0 + 0 < 8, D takes the tail branch. offset == 0, so D is
   appended instead of returning IPFRAG_DUP or IPFRAG_OVERLAP. Then
   nf_ct_frag6_queue() overwrites nhoffset with D's value:

	if (offset == 0) {
		fq->nhoffset = nhoff;

3) The last fragment covers [8, 16). meat reaches 16, which equals q.len,
   so nf_ct_frag6_reasm() runs.

   The head is rb_first, which is Z at offset 0, so the WARN_ON() in
   inet_frag_reasm_prepare() never fires. But nhoffset came from D:

	skb_network_header(skb)[fq->nhoffset] = skb_transport_header(skb)[0];

Wouldn't this write an attacker-chosen byte about 1KB past the end of Z's
48-byte header area? That would land in the tailroom, in skb_shared_info,
or past the allocation. The end <= offset check never fires here, because
end (8) is greater than offset (0).

An exact claimed-vs-real length check probably can't go into the shared
helper, since lowpan_frag_queue() passes end = d_size (the whole datagram
size).

Would it work better to validate in nf_ct_frag6_queue() or
nf_ct_frag6_gather()? Some options:

  - reject a payload_len that is smaller than the extension header length
  - reject skb->len < end - offset after pskb_pull()
  - have act_ct check and trim the skb against payload_len before
    defragmentation

The check added here could stay as hardening.

>  	/* The reassembled skb keeps the first fragment's secpath. */
>  	if (last && !secpath_equal(last, skb))
>  		return IPFRAG_MIXED_SECPATH;

-- 
Sashiko AI review ยท https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261201031146.56825-1-alex000young%40gmail.com
Technical Details
Message-ID: <179632168593.3146.17576515938905468722@kernel.org>
Path: mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!srv.newsdeef.eu!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.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-376815-linux-kernel-netdev=dewy.ru
References: <20261201031146.56825-1-alex000young@gmail.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!srv.newsdeef.eu!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.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-376815-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net] net: ipv4: reject invalid fragment ranges
Date: Thu, 03 Dec 2026 18:14:45 +0000
Organization: Usenet Network
Message-ID: <179632168593.3146.17576515938905468722@kernel.org>
References: <20261201031146.56825-1-alex000young@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="2562908"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:oxSpu2wTeDUL+IAqct2tFjBvNtk= sha256:f//j45MFr5R6Wdg5Dt93CneDr4KYc5FIEwlMsOcjzfw=
	sha1:xUBlH//Kv798m1NYAbczxyFxcnQ= sha256:gYeoqPS2y/5xtcItBGA1dBUfgeHji3tMALMFcP7Ynus=
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 67163117A04; Thu,  3 Dec 2026 21:15:03 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.64
X-Spam-Status: No, score=-3.64 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.24, 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 8Srwpi1ghaej;
	Thu,  3 Dec 2026 21:14:59 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-376815-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 76BAA1179F7; Thu,  3 Dec 2026 21:14:50 +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 8F73B27E40; Thu,  3 Dec 2026 18:14:48 +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=1796321688;
	b=c9JXLiBRTFBaigM3MvlcQZycudzys8+cp8Yy1iIXZg90PGg633mvsDzyvr2MrbLlvOGp
	 AleTHMWTVrpk4JGCbq9E/E1Aucjti0ARA78N2q8hII6CjEm+rvkDF7lMTUCVdV0Smvpvq
	 1pi4AkiObxvJRtcGoPNzboB0mqWgNm3iPTrZNN1Qjw2dRkkBJ+miFDIzWRVfiYqb5R06g
	 vlAz7uGhAsPwRlGxaLW9Nsgxuab1SZnKlQjG9cR/V0WzM227peIO4VgoDo1DUWWHxogzu
	 nytDteCVUWrJpn+WmOo/vhpBKpr9yhOE1fkLaAsrzNssOmcNfgc0kZVfLUpDoa5heFg==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796321688;
	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=zc9whdgBuIVSBKJ0qDvTj/p8PsuRJ2lIJWKPNas73bo=;
	b=QSYq1O8c7hN/eOfaHd9LpD6qGubuPOcHV84RjfAVulWtrKvq42L7d2cZj6zz1Rnzp66v
	 1OcROQZGwSHhTl2dUmzVuT3j67q5JX6z06Gs2ruFytZeVvFaYomRwFPJeEEmcI5XwRcGU
	 XSoSAttSZfshdwr869nhYzY9XprsnRlLpubQfHMWU+wFJk8zhnWTA1NQjvoWdHyi4H7Y4
	 kiS8pK/bPAs+chuB/HgYhX0TrR5D8aIncGxmgNlUHK83MKWsWXJA5wcitqkNKfDYAGEnY
	 aQKHmclsAdoMn5JDzl2lTG/5Oe/tyRYHnwABnR6sHaqNB7SwlAmUQANbfzKOfdTGKxA==
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=jupOBKY9;
	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 637FA606A322;
	Thu,  3 Dec 2026 18:14:48 +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=jupOBKY9
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=1796321687;
	b=DVVWNMhRUl/GOezDBIz9Yi2b7f3g/ZkTqto0Oxvr/1Y5jHl0/qR45eZKQapWN7plZ33Y
	 wkv1T1iYxsVNle4TsLzfxoZPU41Dpxcbhs66hMVR4feMYyQI49fgKoHtxYYFfuHjsqDy3
	 1eRM/IYDhoc4szU0k29unNpj2ufLQ+76jhZk0HHDu5a8QW/tplywjZOOyNeiBiAVWC9rW
	 H6fslmU9nPw5h6bO4qDC0K8LSJwP206ZUSZDReU6X7u+j5gEfxumgc9S0mnz5hHIxQeJO
	 buFRIpF+XC4+rNiVZzyhZqhB7agRI7zp8e2pJeEbixu2LbwGsMt6jXLZaLfWMUgxDUQ==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796321687;
	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=zc9whdgBuIVSBKJ0qDvTj/p8PsuRJ2lIJWKPNas73bo=;
	b=Fh0mcDOjB0fMDShEKJ+BjcNl+b1OEHzyXrEd1gh8TIl56bcNlfCgb4zvOI2PCJqFyHPg
	 fAvC1plJHm1oKLoxDD9N/xDM4YyEKw/9AJOXj8rd7RaA8uNj16InNzI6NWkoG6inGNk/M
	 QDwYwhLj75rBHoLlpMRxtZUCDkHn/t/l7VW+SE5EOmOpIxgqbSv5U9TZEiIGxC9Wl/KDG
	 WySazLwNW6Z0AeymgkEn6hG5mG3pZ3tuTmj9IteARWN+8mbIASMjC3RvZaMUEZB8GAEIY
	 ztE7Irt5iCQ0LIF/fLREIJB8Pq9OTjn6jHz5wmfSVPMPKvaN4skxkShFjYJRhpY/Ujg==
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=jupOBKY9;
	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 819A2606A32D
	for <netdev@vger.kernel.org>; Thu,  3 Dec 2026 18:14:46 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5C7191F00893;
	Thu,  3 Dec 2026 18:14:46 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1796321686;
	bh=zc9whdgBuIVSBKJ0qDvTj/p8PsuRJ2lIJWKPNas73bo=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=jupOBKY9c0+uPoe6DaO1uWRIQvPx1EgENNBMCcvSza7v11shA6AilPdgdOp0TDMrh
	 4RaFMFa8OSOl0tUG1yE8LXjuTkExI/KC/Gzv6LCcdWyI1VwxZ1LuYwwKy9Q3a7V1Kq
	 j1HQooY15hOT5LsukKUlVODXVwKTdz+Incy6hxy44Tkpb8dqDnXH6UZ+8HaCkn/bfu
	 5vjBoj57x0tl+hfZbpqZ4/1FFQ7CNaKvWFvtZhnzX3QH4S6dJ+NTttrCJRbCF3nhaI
	 VMZvGf1vQRG/QRk510sepa4RKHhqSIuii6rY8ipTQ5YKf3bZ+9fCefAX7tOUHS3Iy4
	 LfWQe6Mzmb1+Q==
X-Cc: dsahern@kernel.org, idosch@nvidia.com, davem@davemloft.net,
 edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com, willemb@google.com,
 netdev@vger.kernel.org
X-In-Reply-To: <20261201031146.56825-1-alex000young@gmail.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