๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #17298

Re: [PATCH net v2] ieee802154: 6lowpan: validate fragment offset against datagram size

#17298
From: netdev-bot+sashiko
Date: Mon, 16 Nov 2026 15:44
216 lines
17018 bytes
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

Critical: 0 ยท High: 1 (1) ยท Medium: 1 ยท 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] ieee802154: 6lowpan: zero-length fragments accepted in
  lowpan_frag_queue()
- [Medium] The commit message gets both the impact and the mechanism
  wrong, and overstates what the patch protects against.

Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but it is in the
  code path the patch's scenario depends on.

--

ieee802154: 6lowpan: validate fragment offset against datagram size

This patch adds a bounds check to lowpan_frag_queue(). The check rejects
any 6LoWPAN fragment whose offset is greater than d_size, or whose offset
plus length is greater than d_size. The commit message says this stops an
attacker's out-of-range fragment from being spliced into a reassembled
datagram in place of the legitimate sender's bytes.

> If an attacker's out-of-range fragment lands in a gap before the
> legitimate fragment for that span arrives, inet_frag_queue_insert()
> accepts the attacker's bytes into that span; when the legitimate
> fragment for the same span then arrives, it collides with the
> attacker's skb and is dropped as an overlap (IPFRAG_OVERLAP). The
> datagram still completes, but with the attacker's bytes in the
> reassembled buffer instead of the legitimate sender's.

[Severity: Medium]

Does this describe what happens to a fragment that starts past d_size?

lowpan_frag_queue() passes end = d_size to inet_frag_queue_insert(). If
the attacker's node sits at an offset greater than d_size, a later
legitimate fragment always takes the left branch in the binary search:

net/ipv4/inet_fragment.c:inet_frag_queue_insert() {
    ...
			if (end <= FRAG_CB(curr)->ip_defrag_offset)
				rbn = &parent->rb_left;
    ...
}

So nothing is dropped as an overlap. The out-of-range fragment only adds
to fq->q.meat. In most cases meat == len is then never reached, and the
queue waits for the timeout.

A DUP/OVERLAP collision can only happen for the other half of the check
(offset < d_size, offset + len > d_size). Even then, one such fragment
pushes meat past d_size. Doesn't "the datagram still completes" need
more conditions than the message gives?

Also, the new check still accepts an in-range forged fragment that gives
the same splice. Take d_size = 96, with a legitimate FRAG1 covering
[0, 48) already queued. An attacker sends a FRAGN with the same d_tag,
d_size and addresses, d_offset = 6 and 48 bytes of payload:

    offset = 48, skb->len = 48, end = 96
    48 > 96 is false, 48 > 96 - 48 is false  -> check passes
    48 + 48 == 96                            -> final, LAST_IN set

inet_frag_queue_insert() appends it on the common path. meat reaches 96,
and lowpan_frag_reasm() completes the datagram with the attacker's bytes.

802.15.4 has no source authentication without llsec, so no reassembly
bounds check can prevent that.

The check still works as hardening against malformed fragments. Could the
commit message be reworded so readers and stable backporters don't take
it as a fix for third-party fragment splicing?

> diff --git a/net/ieee802154/6lowpan/reassembly.c b/net/ieee802154/6lowpan/reassembly.c
> index ddb6a5817d098..905ba5f868442 100644
> --- a/net/ieee802154/6lowpan/reassembly.c
> +++ b/net/ieee802154/6lowpan/reassembly.c
> @@ -103,6 +103,9 @@ static int lowpan_frag_queue(struct lowpan_frag_queue *fq,
>  	offset = lowpan_802154_cb(skb)->d_offset << 3;
>  	end = lowpan_802154_cb(skb)->d_size;
>  
> +	if (offset > end || skb->len > end - offset)
> +		goto err;
> +

[Severity: High]
Should this also reject skb->len == 0?

The new check lets a zero-length fragment through at any offset up to
d_size. The commit message also says a zero-length final fragment at
offset == d_size is meant to be accepted. ip_frag_queue(),
ip6_frag_queue() and nf_ct_frag6_queue() all treat end == offset as
invalid, and drop the fragment before it reaches
inet_frag_queue_insert().

Empty fragments are easy to produce here:

  - lowpan_get_cb() only checks !skb->len on the FRAG1 branch. A FRAGN
    frame carrying nothing but its 5-byte header therefore reaches
    lowpan_frag_queue() with skb->len == 0.

  - A FRAG1 whose only payload is the LOWPAN_DISPATCH_IPV6 byte passes
    lowpan_get_cb() with skb->len == 1. lowpan_rx_h_ipv6() then pulls
    that byte, so this fragment also arrives here empty.

Take an empty FRAGN with d_offset = 0 that arrives before FRAG1. It
becomes the first node in fq->q.rb_fragments, with ip_defrag_offset 0
and len 0. When the real FRAG1 arrives at offset 0, the common path in
inet_frag_queue_insert() sees

    offset == FRAG_CB(last)->ip_defrag_offset + last->len   (0 == 0)

It calls fragrun_append_to_last(), so FRAG1 is chained behind the
empty skb.

Once meat reaches len, inet_frag_reasm_prepare() uses the first
rb_fragments node as the head, which is the empty FRAGN.
inet_frag_reasm_finish() then does

    skb_push(head, head->data - skb_network_header(head));

That pushes the pulled FRAGN header back in front of the packet. The
decompressed IPv6 header from FRAG1 sits behind it in frag_list. The
dispatch-only FRAG1 case does the same with the 0x41 byte. In both
cases the reassembled packet passed up the stack no longer starts with
its IPv6 header.

Empty fragments at offset == d_size cause a different problem. The
first one sets INET_FRAG_LAST_IN before the real final fragment has
arrived. Repeats go down the binary search in inet_frag_queue_insert(),
where "end <= ip_defrag_offset" holds (d_size <= d_size) before the
IPFRAG_DUP test is reached. Each copy is linked into rb_fragments and
charged through add_frag_mem_limit(). fq->q.meat never moves, so the
memory stays held until the reassembly timer fires.

At an intermediate offset, an empty fragment can do one of two things.
It can be chained onto the tail run without advancing frag_run_len.
Or it can start a zero-length run, so that a later legitimate fragment
below it fails with IPFRAG_OVERLAP.

Would it make sense to add !skb->len to this check, and drop the
zero-length wording from the commit message? Putting it here rather
than in lowpan_get_cb() also covers the FRAG1 case, because that skb
only becomes empty after the rx handlers run.

This matters even more if the insert end is changed to
offset + skb->len, because inet_frag_queue_insert() assumes
offset < end.

[Severity: High]

This is a pre-existing issue and was not introduced by this patch, but
the scenario in the commit message depends on it. Further down,
lowpan_frag_queue() does:

	err = inet_frag_queue_insert(&fq->q, skb, offset, end);

Here end is d_size, the size of the whole datagram, rather than the
fragment's own end (offset + skb->len). ip_frag_queue() and
ip6_frag_queue() both pass the fragment's own end:

net/ipv6/reassembly.c:ip6_frag_queue() {
    ...
	end = offset + (ntohs(ipv6_hdr(skb)->payload_len) -
			((u8 *)(fhdr + 1) - (u8 *)(ipv6_hdr(skb) + 1)));
    ...
}

Doesn't this make inet_frag_queue_insert() treat every 6LoWPAN fragment
as covering [offset, d_size)?

On the common path, the "last_end < end" test turns into
"last_end < d_size". Any fragment with offset < last_end then returns
IPFRAG_OVERLAP.

On the binary search path, "end <= curr offset" is never true for an
in-range node. The walk can never go left, so it ends in IPFRAG_DUP or
IPFRAG_OVERLAP.

Trace 1, d_size = 96, fragments arrive out of order:

    FRAGN d_offset=6, len 48  -> final, run [48, 96)
    FRAG1 offset 0, len 48    -> last_end 96 is not < 96, binary search
                                 96 <= 48 false, 0 >= 96 false,
                                 0 >= 48 false -> IPFRAG_OVERLAP

FRAG1 is freed through goto err and INET_FRAG_FIRST_IN is never set, so
the datagram can never complete.

Trace 2, four 24-byte fragments at offsets 0/24/48/72, arriving in the
order 0, 48, 24:

    fragment 24 -> last_end 72 < 96, offset 24 < 72 -> IPFRAG_OVERLAP

So it looks like any datagram whose fragments arrive out of ascending
order, or with a gap, can never be reassembled. The partial queue keeps
its frag memory until the reassembly timer expires. This seems to date
back to 254c5dbe15d4 ("6lowpan: use rbtree for IP frag queue").

The "dropped as an overlap" behaviour in the commit message looks like a
side effect of this wrong interval, not real overlap detection.

Would it make sense to also pass offset + skb->len as the insert end,
and use d_size only for q.len and the completion check?

-- 
Sashiko AI review ยท https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261112153034.1015181-1-rc4d5a%40protonmail.com
Technical Details
Message-ID: <179484385868.3136.2031122352295651681@kernel.org>
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!2.eu.feeder.erje.net!feeder.erje.net!feeder1.feed.ams11.usenet.farm!feed.usenet.farm!peer03.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!feeder.usenetexpress.com!tr3.eu1.usenetexpress.com!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-364515-linux-kernel-netdev=dewy.ru
References: <20261112153034.1015181-1-rc4d5a@protonmail.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!2.eu.feeder.erje.net!feeder.erje.net!feeder1.feed.ams11.usenet.farm!feed.usenet.farm!peer03.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!feeder.usenetexpress.com!tr3.eu1.usenetexpress.com!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-364515-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net v2] ieee802154: 6lowpan: validate fragment offset against datagram size
Date: Mon, 16 Nov 2026 15:44:18 +0000
Organization: Usenet Network
Message-ID: <179484385868.3136.2031122352295651681@kernel.org>
References: <20261112153034.1015181-1-rc4d5a@protonmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network; logging-data="2102476"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:fquAMVl84GleVO+mb+THbmG5+p8= sha256:QThAngWF1CE73Z8CeSuDSPjcbyUWMPS3sh/MdOn7y9o= sha1:PHd9QEGwZv0rbeLsHCCc5YAobO8= sha256:nZEwES7s0smYcJj5nYpDKs/Cusqs7t5/iPVkvmbZcnw=
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 1C1E5114CB8; Mon, 16 Nov 2026 18:44:39 +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 DCcs58Lt7pO5; Mon, 16 Nov 2026 18:44:34 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-364515-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 tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114]) by mail.dewy.ru (Postfix) with ESMTPS id 5A3D5114CAD; Mon, 16 Nov 2026 18:44:26 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by tor.lore.kernel.org (Postfix) with ESMTP id DBA752A9F0; Mon, 16 Nov 2026 15:44:23 +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=1794843861; b=Veown1flK5ZD0/VSHEi+soEBx3QxitrcK/uDPLAToWwPc4dDbqrm14fsCUF8wG64wikS TGYmLOw2BrbhsTOLkUkqo1ZHBBB1UKE4nIpF38RxAJXuAFiZMUYWkve+8R0/ptd8knId9 jFQFdAt4h+OKE8OquPh7sMo1NbteDDH+LU1cfsoRF7Gz+TTItDpP+VfkehHwzdn2ls3xk /y5YHDVCGEmSxK///c0U1O0KeaH4ckg+DRv/oVnC8snxY/XzFerFXnv6fCYE80MMdVx4r eoBX4g+bD9KkxQNRItx5HNZmdagVeBQYTYrClyXO7APxGieENgp+93BD54w+EsRsI5w==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794843861; 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=C9+XjET5RSQdlM7ZfuD3xAhjrNGw9Kacup8gENsd8So=; b=kjiSBCXX0BSQGphR/++bX9J0dYt7imbpkqxsnv23uaHVbOhplUP2aAWR4HXRm8ljAUho nu9lQQ2b03a1PupkgGx7SCuKbsNVNHDIa95ieZAa/cJQXp4/GiHpgRNJMluvwHE4N609t lAVEhE8+AwTp/FXcLab6Ej530kTdxmN2hp9i6arTPmW41brvWBJTviLbVsWxcd5xWIeAf i3gizLyC/Je6BnnmNZy41WmGpbO7kT58vDoOLyu6RBXDQ5doZsnLknEdOHN45tglEzAeF SUrPk0FZQJAU66nP7MrxjdnY6++IrBH7EAgBRTSrGYNcE45P8esDsosjsCsf3BE8HYQ==
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=UWJT8Xpk; 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 2A854606A330; Mon, 16 Nov 2026 15:44:21 +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=UWJT8Xpk
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=1794843860; b=boKMJTblZCd4dGbNpf5RjKFDI18yqHWjobUIEpSRYef5mCYIX7uj25NOOwm8cXePky9o 9diaRUngOV7K2icPWeLaVn+OjzlOt7sqBb82Ctgsu8r4LmwpDvM68ouZL/gOVFCsrKPxe le5vKifLpb34OYgfYipqk4yoBoIKkUfrn+AH+q7zrIVM7L7U0mmEwggROVFeRujgmqvWS NFBLRX+dkhbG6gZE0UIWA4qUV8peQINMGbAKuBaBzMawzHBuKFUR9Z8k5nzSilc7sWZMi kc5/PfRGYtfgo/fdco+yFfs/5e4GqJGjGDmr6Rr9GR6zw7bSkir237BTZktH879qpwA==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794843860; 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=C9+XjET5RSQdlM7ZfuD3xAhjrNGw9Kacup8gENsd8So=; b=3PT1IkBTd81cJx3645zL/UbWYfo5ZKs6EwqhedqxFnbq9+7uwhBGvWYByhuodkZkANte 2SF0uh7qJ3WWp1VPYK7SMGDrpoQ2igt3mM27YcNhP7dbDTDX/GZ7Ckj1aXhPWlMAUT+ok 0zCRd7JUzpnby1Ur3nFrc3E/7e82l0lyTh05a4s4N5KFuC7NnwO2WkolVKjLyJ65Om9dn xX7DyFi2fWl+1DwBAhHT6I961QX5b6w91b5kuTY7eJrh/ZApm5cYfNz2Z/jIwjLEtM0FU q7RsM1vdXiTCPbbdF80FnnaE09bNtkhVVSJOnDtG6Quq7kPMtqUQoutKHzTuxF/i0iQ==
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=UWJT8Xpk; 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 4557C606A323; Mon, 16 Nov 2026 15:44:20 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 321FC1F000C9; Mon, 16 Nov 2026 15:44:19 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794843859; bh=C9+XjET5RSQdlM7ZfuD3xAhjrNGw9Kacup8gENsd8So=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=UWJT8XpkK/yddz+mkY7X5hnChMl5ZLi6pXmEs/tQcHYLURFwYuj0T/JR1CBdbZzX3 BFF1H4HXOhzcIIqEzTPkZZrpf0EgSIsms53gJaWy3m/SDwUKmCKQhYLWNQpYPxn07v BYNHsbzk3hALhnw6jsAu52bUCjy3EGaw1AyCTKhZudhwJsC9hiHboITQDoQILB1gr/ BQx+ehQZxG0mNh8KaV022+SV2Nx8PNKDK2+IDH+5YON8F8zc1YcdLcbyg2zIOsA4MT a+DsEVTQzwYl+9jLCUgSUv93mybbo/C1o01Xj2uhLwpwjQnTtz8nyQJtHB6yavDNnZ BH8VHImzrUu/A==
X-Cc: linux-wpan@vger.kernel.org, netdev@vger.kernel.org, alex.aring@gmail.com, stefan@datenfreihafen.org, miquel.raynal@bootlin.com, davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, linux-kernel@vger.kernel.org
X-In-Reply-To: <20261112153034.1015181-1-rc4d5a@protonmail.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
X-Received-Bytes: 16732