From: netdev-bot+sashiko@kernel.org
To: rc4d5a@protonmail.com
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
Subject: Re: [PATCH net v2] ieee802154: 6lowpan: validate fragment offset against datagram size
Date: Mon, 16 Nov 2026 15:44:18 +0000 [thread overview]
Message-ID: <179484385868.3136.2031122352295651681@kernel.org> (raw)
In-Reply-To: <20261112153034.1015181-1-rc4d5a@protonmail.com>
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
prev parent reply other threads:[~2026-11-16 15:44 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-07 22:32 [PATCH] ieee802154: 6lowpan: validate fragment offset against datagram size Ryan Prinz
2026-11-08 13:05 ` [PATCH RESEND] " Ryan Prinz
2026-11-08 14:20 ` [PATCH net " Ryan Prinz
2026-11-09 9:03 ` Ryan Prinz
2026-11-12 9:05 ` netdev-bot+sashiko
2026-11-12 15:29 ` Ryan Prinz
2026-11-12 15:31 ` [PATCH net v2] " Ryan Prinz
2026-11-16 15:44 ` netdev-bot+sashiko [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=179484385868.3136.2031122352295651681@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=alex.aring@gmail.com \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-wpan@vger.kernel.org \
--cc=miquel.raynal@bootlin.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=rc4d5a@protonmail.com \
--cc=stefan@datenfreihafen.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox