Skip to contentSkip to conversation

ieee802154: 6lowpan: validate fragment offset against datagram size

PATCH Superseded Ryan Prinz 3 participants 11 messages Nov 7 – Nov 23

Subsystems (3)

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Ryan Prinz

author
#0 lore raw

PATCH 1/1 ieee802154: 6lowpan: validate fragment offset against datagram size

A 6LoWPAN fragment announces the total size of the datagram it belongs to (d_size) and its own offset within that datagram. The reassembly code never checks that the offset actually fits inside d_size, so a fragment claiming to start far past the end of the datagram is accepted the same as a legitimate one, allowing an attacker to forge data of another sender.

lowpan_frag_queue() considers a datagram complete by counting bytes received (fq->q.meat) against the declared size (fq->q.len), not by verifying the bytes form a contiguous range. A fragment with an out-of-range offset still has its length counted toward that total, so a legitimate fragment exchange plus an attacker fragment can sum to d_size, marking the datagram complete while a gap in the data was never filled, and appending the out-of-range fragment's bytes to the end of the reassembled buffer as if they were part of the message.

IPv6's reassembly (net/ipv6/reassembly.c, ip6_frag_queue()) computes end = of
fset + payload length for every fragment and checks end against IPV6_MAXPLEN, which bounds offset by construction. 6LoWPAN's d_offset and d_size are independent wire fields with no such coupling, and no separate bounds check was added for it.

The same class of bug was assigned CVE-2019-8359 (CVSS 9.8) in Contiki-NG's 6LoWPAN stack before a 2019 fix; RIOT-OS's implementation (gnrc_sixlowpan_frag_rb_add) rejects a fragment once offset + size exceeds the reassembly buffer's datagram_size. Linux's 6LoWPAN reassembly is the only one of these implementations without an equivalent check.

Fix by rejecting any fragment whose offset, or offset plus length, falls outside [0, d_size).

Fixes 7240cdec60b1 ("6lowpan: handling 6lowpan fragmentation via inet_frag api")

---
Reproduced two ways: with a local kernel module calling lowpan_frag_rcv() directly, and over mac802154_hwsim with three independent processes standing in for s
ender, receiver and attacker.
An attacker in radio range who observes one fragment of an in-progress transmission reads d_tag, d_size and the addressing in the clear, then sends a single out-of-range fragment of its own. The receiver's reassembly completes with the attacker's bytes appended to the legitimate data. Both reproducers were re-run against this fix to confirm the out-of-range fragment is now rejected and the datagram no longer completes with it included.

AI Disclosure: An AI assistant (Claude) was used to assist with the analysis and testing. I have verified the vulnerability, the fix, and the test results myself and take responsibility for this contribution, per Documentation/process/coding-assistants.rst.

 net/ieee802154/6lowpan/reassembly.c | 3 +++
 1 file changed, 3 insertions(+)
net/ieee802154/6lowpan/reassembly.c +0 -0
index ddb6a5817d09..905ba5f86844 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;
+
/* Is this the final fragment? */
if (offset + skb->len == end) {
/* If we already have some bits beyond end
--
2.51.2

author
#1 lore raw

PATCH RESEND 1/1 ieee802154: 6lowpan: validate fragment offset against datagram size

A 6LoWPAN fragment announces the total size of the datagram it belongs to (d_size) and its own offset within that datagram. The reassembly code never checks that the offset actually fits inside d_size, so a fragment claiming to start far past the end of the datagram is accepted the same as a legitimate one, allowing an attacker to forge data of another sender.

lowpan_frag_queue() considers a datagram complete by counting bytes received (fq->q.meat) against the declared size (fq->q.len), not by verifying the bytes form a contiguous range. A fragment with an out-of-range offset still has its length counted toward that total, so a legitimate fragment exchange plus an attacker fragment can sum to d_size, marking the datagram complete while a gap in the data was never filled, and appending the out-of-range fragment's bytes to the end of the reassembled buffer as if they were part of the message.

IPv6's reassembly (net/ipv6/reassembly.c, ip6_frag_queue()) computes end = of
fset + payload length for every fragment and checks end against IPV6_MAXPLEN, which bounds offset by construction. 6LoWPAN's d_offset and d_size are independent wire fields with no such coupling, and no separate bounds check was added for it.

The same class of bug was assigned CVE-2019-8359 (CVSS 9.8) in Contiki-NG's 6LoWPAN stack before a 2019 fix; RIOT-OS's implementation (gnrc_sixlowpan_frag_rb_add) rejects a fragment once offset + size exceeds the reassembly buffer's datagram_size. Linux's 6LoWPAN reassembly is the only one of these implementations without an equivalent check.

Fix by rejecting any fragment whose offset, or offset plus length, falls outside [0, d_size).

Reproduced two ways: with a local kernel module calling lowpan_frag_rcv() directly, and over mac802154_hwsim with three independent processes standing in for sender, receiver and attacker. An attacker in radio range who observes one fragment of an in-progress transmission reads d_tag, d_size and
the addressing in the
clear, then sends a single out-of-range fragment of its own. The receiver's reassembly completes with the attacker's bytes appended to the legitimate data. Both reproducers were re-run against this fix to confirm the out-of-range fragment is now rejected and the datagram no longer completes with it included.

AI Disclosure: An AI assistant (Claude) was used to assist with the analysis and testing. I have verified the vulnerability, the fix, and the test results myself and take responsibility for this contribution, per Documentation/process/coding-assistants.rst.

Fixes 7240cdec60b1 ("6lowpan: handling 6lowpan fragmentation via inet_frag api")

---
Resending to fix a diff formatting issue in my previous mail.

 net/ieee802154/6lowpan/reassembly.c | 3 +++
 1 file changed, 3 insertions(+)
net/ieee802154/6lowpan/reassembly.c +0 -0
index ddb6a5817d09..9

05ba5f86844 100644

net/ieee802154/6lowpan/reassembly.c +3 -0
@@ -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;
+
 	/* Is this the final fragment? */
 	if (offset + skb->len == end) {
 		/* If we already have some bits beyond end
Signature · 1 line
2.51.2
author
#2 lore raw

PATCH RESEND 1/1 ieee802154: 6lowpan: validate fragment offset against datagram size

In reply to Ryan Prinz

A 6LoWPAN fragment announces the total size of the datagram it belongs to (d_size) and its own offset within that datagram. The reassembly code never checks that the offset actually fits inside d_size, so a fragment claiming to start far past the end of the datagram is accepted the same as a legitimate one, allowing an attacker to forge data of another sender.

lowpan_frag_queue() considers a datagram complete by counting bytes received (fq->q.meat) against the declared size (fq->q.len), not by verifying the bytes form a contiguous range. A fragment with an out-of-range offset still has its length counted toward that total, so a legitimate fragment exchange plus an attacker fragment can sum to d_size, marking the datagram complete while a gap in the data was never filled, and appending the out-of-range fragment's bytes to the end of the reassembled buffer as if they were part of the message.

IPv6's reassembly (net/ipv6/reassembly.c, ip6_frag_queue()) computes end = of
fset + payload length for every fragment and checks end against IPV6_MAXPLEN, which bounds offset by construction. 6LoWPAN's d_offset and d_size are independent wire fields with no such coupling, and no separate bounds check was added for it.

The same class of bug was assigned CVE-2019-8359 (CVSS 9.8) in Contiki-NG's 6LoWPAN stack before a 2019 fix; RIOT-OS's implementation (gnrc_sixlowpan_frag_rb_add) rejects a fragment once offset + size exceeds the reassembly buffer's datagram_size. Linux's 6LoWPAN reassembly is the only one of these implementations without an equivalent check.

Fix by rejecting any fragment whose offset, or offset plus length, falls outside [0, d_size).

Reproduced two ways: with a local kernel module calling lowpan_frag_rcv() directly, and over mac802154_hwsim with three independent processes standing in for sender, receiver and attacker. An attacker in radio range who observes one fragment of an in-progress transmission reads d_tag, d_size and
the addressing in the
clear, then sends a single out-of-range fragment of its own. The receiver's reassembly completes with the attacker's bytes appended to the legitimate data. Both reproducers were re-run against this fix to confirm the out-of-range fragment is now rejected and the datagram no longer completes with it included.

AI Disclosure: An AI assistant (Claude) was used to assist with the analysis and testing. I have verified the vulnerability, the fix, and the test results myself and take responsibility for this contribution, per Documentation/process/coding-assistants.rst.

Fixes 7240cdec60b1 ("6lowpan: handling 6lowpan fragmentation via inet_frag api")

---
Resending with correct tree designator in the subject

 net/ieee802154/6lowpan/reassembly.c | 3 +++
 1 file changed, 3 insertions(+)
net/ieee802154/6lowpan/reassembly.c +0 -0
index ddb6a5817d09..905ba5f86

844 100644

net/ieee802154/6lowpan/reassembly.c +3 -0
@@ -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;
+
 	/* Is this the final fragment? */
 	if (offset + skb->len == end) {
 		/* If we already have some bits beyond end
Signature · 1 line
2.51.2
author
#3 lore raw

PATCH RESEND 1/1 ieee802154: 6lowpan: validate fragment offset against datagram size

In reply to Ryan Prinz

A 6LoWPAN fragment announces the total size of the datagram it belongs to (d_size) and its own offset within that datagram. The reassembly code never checks that the offset actually fits inside d_size, so a fragment claiming to start far past the end of the datagram is accepted the same as a legitimate one, allowing an attacker to forge data of another sender.

lowpan_frag_queue() considers a datagram complete by counting bytes received (fq->q.meat) against the declared size (fq->q.len), not by verifying the bytes form a contiguous range. A fragment with an out-of-range offset still has its length counted toward that total, so a legitimate fragment exchange plus an attacker fragment can sum to d_size, marking the datagram complete while a gap in the data was never filled, and appending the out-of-range fragment's bytes to the end of the reassembled buffer as if they were part of the message.

IPv6's reassembly (net/ipv6/reassembly.c, ip6_frag_queue()) computes end = offset + payload length for every fragment and checks end against IPV6_MAXPLEN, which bounds offset by construction. 6LoWPAN's d_offset and d_size are independent wire fields with no such coupling, and no separate bounds check was added for it.

The same class of bug was assigned CVE-2019-8359 (CVSS 9.8) in Contiki-NG's 6LoWPAN stack before a 2019 fix; RIOT-OS's implementation (gnrc_sixlowpan_frag_rb_add) rejects a fragment once offset + size exceeds the reassembly buffer's datagram_size. Linux's 6LoWPAN reassembly is the only one of these implementations without an equivalent check.

Fix by rejecting any fragment whose offset, or offset plus length, falls outside [0, d_size).

Reproduced two ways: with a local kernel module calling lowpan_frag_rcv() directly, and over mac802154_hwsim with three independent processes standing in for sender, receiver and attacker. An attacker in radio range who observes one fragment of an in-progress transmission reads d_tag, d_size and the addressing in the clear, then sends a single out-of-range fragment of its own. The receiver's reassembly completes with the attacker's bytes appended to the legitimate data. Both reproducers were re-run against this fix to confirm the out-of-range fragment is now rejected and the datagram no longer completes with it included.

AI Disclosure: An AI assistant (Claude) was used to assist with the analysis and testing. I have verified the vulnerability, the fix, and the test results myself and take responsibility for this contribution, per Documentation/process/coding-assistants.rst.

Fixes 7240cdec60b1 ("6lowpan: handling 6lowpan fragmentation via inet_frag api")

---
Resending with correct tree designator in the subject

 net/ieee802154/6lowpan/reassembly.c | 3 +++
 1 file changed, 3 insertions(+)
net/ieee802154/6lowpan/reassembly.c +3 -0
index ddb6a5817d09..905ba5f86844 100644
@@ -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;
+
 	/* Is this the final fragment? */
 	if (offset + skb->len == end) {
 		/* If we already have some bits beyond end
Signature · 1 line
2.51.2
#4 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.

Critical: 0 · High: 0 · 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).

- [Medium] The commit message overstates the security impact and misstates the check it adds.

--

ieee802154: 6lowpan: validate fragment offset against datagram size

This commit adds a bounds check to lowpan_frag_queue() that rejects a 6LoWPAN fragment when its offset, or its offset plus length, goes past the declared datagram size (d_size). The commit message says this stops an attacker from forging another sender's data. It also compares the bug to CVE-2019-8359 in Contiki-NG.

Quoted 3 lines

fragment claiming to start far past the end of the datagram is accepted the same as a legitimate one, allowing an attacker to forge data of another sender.

[ ... ]

Quoted 2 lines

The same class of bug was assigned CVE-2019-8359 (CVSS 9.8) in Contiki-NG's 6LoWPAN stack before a 2019 fix; RIOT-OS's implementation

[ ... ]

Quoted 2 lines

Fix by rejecting any fragment whose offset, or offset plus length, falls outside [0, d_size).

[ ... ]

net/ieee802154/6lowpan/reassembly.c static int lowpan_frag_queue(struct lowpan_frag_queue *fq, · line 108

Quoted 11 lines
net/ieee802154/6lowpan/reassembly.c +3 -0
index ddb6a5817d098..905ba5f868442 100644
@@ -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: Medium]
Does the commit message match what this check rejects and what it protects against?

The check accepts offset + skb->len == end, which it has to for the final fragment. It also accepts a zero-length FRAGN with offset == d_size. So the fragment end has a closed upper bound, not the "[0, d_size)" range the message gives.

ip6_frag_queue() drops zero-length fragments:

	if (end == offset)
		goto discard_fq;

lowpan_frag_queue() still accepts them. They add nothing to fq->q.meat, so they can't append any data.

About "allowing an attacker to forge data of another sender": the message assumes the attacker can read d_tag, d_size and the addressing in the clear. With that, can't the attacker still send an in-range fragment at the next expected offset? For example, with d_size = 200:

  FRAG1 [0, 64)       legitimate, queued
  FRAGN [64, 136)     attacker, passes the new check
  FRAGN [64, 136)     legitimate, rejected as an overlap
  FRAGN [136, 200)    legitimate, completes the datagram

The attacker's fragment takes the append path in
inet_frag_queue_insert():

	else if (FRAG_CB(last)->ip_defrag_offset + last->len < end) {
		/* This is the common case: skb goes to the end. */
		/* Detect and discard overlaps. */
		if (offset < FRAG_CB(last)->ip_defrag_offset + last->len)
			return IPFRAG_OVERLAP;
		if (offset == FRAG_CB(last)->ip_defrag_offset + last->len)
			fragrun_append_to_last(q, skb);

The legitimate [64, 136) fragment then gets IPFRAG_OVERLAP and is freed through goto err in lowpan_frag_queue(). The reassembled datagram ends up holding the attacker's bytes.

Also, 802.15.4 has no source authentication without llsec, so an attacker can just spoof a whole datagram. This bug doesn't really enable forging another sender's data, and the patch doesn't prevent it.

About "The same class of bug was assigned CVE-2019-8359 (CVSS 9.8)": the Contiki-NG bug was an out-of-bounds write into a fixed reassembly buffer. Linux never copies payload to a computed offset. inet_frag_reasm_finish() links the fragment skbs to the head:

				head->data_len += fp->len;
				head->len += fp->len;
				head->truesize += fp->truesize;

				*nextp = fp;

So before this patch, an out-of-range offset only changed the contents of the reassembled payload. It never touched memory outside it. Could the comparison and the 9.8 score come out of the message? They may mislead stable and CVE triage.

The change itself looks like a reasonable integrity and robustness fix:
a reassembled datagram can no longer contain bytes past the declared d_size. Could the message describe it that way, and give the fragment end's upper bound as closed?

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261109090226.799973-1-rc4d5a%40protonmail.com
author
#5 lore raw

Thanks for the review! These are fair points, I'll respin.

- The accepted offset range has a closed upper bound (offset + length == d_size is allowed, as needed for the final fragment, including a zero-length one at offset == d_size), not the open [0, d_size) I described.
- 802.15.4 has no source authentication without llsec, so this bug doesn't let an attacker impersonate another sender as the message implied. The real effect is an attacker's fragment getting spliced into the reassembled datagram in place of a legitimate sender's bytes for a given span, via the overlap-eviction path you described.
- The CVE-2019-8359/Contiki-NG comparison doesn't match. That was an out-of-bounds write into a fixed buffer. This is a reassembly data-integrity issue only, since inet_frag_reasm_finish() links skbs by pointer rather than copying into a computed offset. Dropping that comparison.

Sending v2 with the commit message corrected; the fix itself is unchanged.

pw-bot: cr

author
#6 lore raw

PATCH v2 1/1 ieee802154: 6lowpan: validate fragment offset against datagram size

In reply to Ryan Prinz

A 6LoWPAN fragment announces the total size of the datagram it belongs to (d_size) and its own offset within that datagram. The reassembly code never checks that the offset actually fits inside d_size, so a fragment claiming to start past the end of the datagram is accepted the same as a legitimate one.

lowpan_frag_queue() considers a datagram complete by counting bytes received (fq->q.meat) against the declared size (fq->q.len), not by verifying the bytes form a contiguous range. A fragment with an out-of-range offset still has its length counted toward that total. 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.

IPv6's reassembly (net/ipv6/reassembly.c, ip6_frag_queue()) computes end = offset + payload length for every fragment and checks end against IPV6_MAXPLEN, which bounds offset by construction. 6LoWPAN's d_offset and d_size are independent wire fields with no such coupling, and no separate bounds check was added for it. RIOT-OS's 6LoWPAN implementation (gnrc_sixlowpan_frag_rb_add) already rejects a fragment once offset + size exceeds the reassembly buffer's datagram_size; Linux's 6LoWPAN reassembly had no equivalent check.

Fixed by rejecting any fragment whose offset exceeds d_size, or whose offset plus length would exceed d_size. A final fragment ending exactly at d_size, including a zero-length one at offset == d_size, is still accepted, matching the completion check right below it.

Fixes 7240cdec60b1 ("6lowpan: handling 6lowpan fragmentation via inet_frag api")

---
v2:
- Reworded the impact description. 802.15.4 has no source authentication without llsec, so this bug doesn't let an attacker impersonate another sender; the real effect is that an attacker's fragment can get spliced into the reassembled datagram in place of a legitimate sender's bytes, with the legitimate fragment for that span evicted as an overlap.
- Dropped the CVE-2019-8359/Contiki-NG comparison. That bug was an out-of-bounds write into a fixed buffer; this one only corrupts the reassembled payload's contents, since inet_frag_reasm_finish() links fragment skbs by pointer rather than copying into a computed offset. The two aren't the same severity class.
- Corrected the described accepted range: the check allows offset + length == d_size, which it must for the final fragment (including a zero-length one at offset == d_size), so the accepted range has a closed upper bound, not the open "[0, d_size)" the v1 message stated.

No change to the fix itself; the diff in reassembly.c is unchanged from v1.

Reproduced two ways: with a local kernel module calling lowpan_frag_rcv() directly, and over mac802154_hwsim with three independent processes standing in for sender, receiver and attacker. An attacker in radio range who observes one fragment of an in-progress transmission reads d_tag, d_size and the addressing in the clear, then sends a single out-of-range fragment of its own before the legitimate fragment for that span arrives. The receiver's reassembly completes with the attacker's bytes in place of the legitimate sender's for that span, and the legitimate fragment is dropped as an overlap. Both reproducers were re-run against this fix to confirm the out-of-range fragment is now rejected outright.

AI Disclosure: An AI assistant (Claude) was used to assist with the analysis and testing. I have verified the vulnerability, the fix, and the test results myself and take responsibility for this contribution, per Documentation/process/coding-assistants.rst.

 net/ieee802154/6lowpan/reassembly.c | 3 +++
 1 file changed, 3 insertions(+)
net/ieee802154/6lowpan/reassembly.c +3 -0
index ddb6a5817d09..905ba5f86844 100644
@@ -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;
+
 	/* Is this the final fragment? */
 	if (offset + skb->len == end) {
 		/* If we already have some bits beyond end

--
2.51.2

#7 lore raw
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.

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.

Quoted 7 lines

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?

net/ieee802154/6lowpan/reassembly.c static int lowpan_frag_queue(struct lowpan_frag_queue *fq, · line 108

Quoted 11 lines
net/ieee802154/6lowpan/reassembly.c +3 -0
index ddb6a5817d098..905ba5f868442 100644
@@ -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?

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261112153034.1015181-1-rc4d5a%40protonmail.com
author
#8 lore raw

Thanks again, these are correct, and I've made the adjustments.

- [High] Zero-length fragments: agreed, the new check doesn't reject skb->len == 0. lowpan_get_cb() only checks !skb->len on the FRAG1 branch, and that check runs before lowpan_rx_h_ipv6() pulls the dispatch byte, so a FRAG1 whose only payload is that byte, or a FRAGN carrying nothing but its header, both reach lowpan_frag_queue() empty. Adding !skb->len to the bounds check, and dropping the "a zero-length final fragment is accepted" wording from the commit message. It shouldn't be accepted, and won't be.

- [Medium] Commit message mechanism: agreed, and it follows from your next point. Reworded the impact description to stop asserting one specific mechanism (the overlap-eviction splice), since that isn't reliable given the issue below. The new wording just states what the fix itself guarantees: no out-of-range or empty fragment is accepted into the queue.

- [High, pre-existing] end = d_size passed to inet_frag_queue_insert() instead of the fragment's own offset + skb->len: confirmed by tracing both of your examples against the actual insert logic. This predates this patch and isn't something this bounds-check patch should carry. I'm tracking it as a separate issue to address on its own rather than folding it in here.

v4 incoming with the zero-length check added and the commit message reworded to not overstate the mechanism.

pw-bot: cr

author
#9 lore raw

PATCH v4 1/1 ieee802154: 6lowpan: validate fragment offset against datagram size

In reply to Ryan Prinz

A 6LoWPAN fragment carries the datagram's total size (d_size) and its own offset within it. lowpan_frag_queue() never checks that the offset, or offset plus length, fits inside d_size, and never rejects an empty fragment.

A datagram is considered complete once enough bytes have been counted (fq->q.meat) toward d_size, regardless of whether those bytes actually form a contiguous range. So an out-of-range or empty fragment's length still counts toward completion, even though it doesn't belong anywhere in the datagram.

IPv6's ip6_frag_queue() already bounds each fragment's end against IPV6_MAXPLEN and rejects zero-length fragments; 6LoWPAN had no equivalent checks.

Fixed by rejecting any fragment that is empty, or whose offset (or offset + length) exceeds d_size.

Fixes 7240cdec60b1 ("6lowpan: handling 6lowpan fragmentation via inet_frag api")

---
v4:
- Added a check for zero-length fragments (!skb->len), which the previous check missed. ip6_frag_queue() and nf_ct_frag6_queue() already reject these; this patch now does too.
- Reworded the impact description to stop claiming one specific mechanism for how an out-of-range fragment causes harm. A separate, pre-existing bug elsewhere in the reassembly code made that mechanism unreliable; it's left out of scope here and will be addressed on its own.

Reproduced two ways: with a local kernel module calling lowpan_frag_rcv() directly, and over mac802154_hwsim with three independent processes standing in for sender, receiver and attacker. An attacker in radio range who observes one fragment of an in-progress transmission reads d_tag, d_size and the addressing in the clear, then sends a single out-of-range fragment of its own before the legitimate fragment for that span arrives. In this arrival order, the receiver's reassembly completed with the attacker's bytes included in the final buffer instead of the out-of-range fragment being rejected. Both reproducers were re-run against this fix to confirm the out-of-range fragment is now rejected outright.

AI Disclosure: An AI assistant (Claude) was used to assist with the analysis and testing. I have verified the vulnerability, the fix, and the test results myself and take responsibility for this contribution, per Documentation/process/coding-assistants.rst.

 net/ieee802154/6lowpan/reassembly.c | 3 +++
 1 file changed, 3 insertions(+)
net/ieee802154/6lowpan/reassembly.c +3 -0
index ddb6a5817d09..4edd307000c8 100644
@@ -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 (!skb->len || offset > end || skb->len > end - offset)
+		goto err;
+
 	/* Is this the final fragment? */
 	if (offset + skb->len == end) {
 		/* If we already have some bits beyond end

--
2.51.2

maintainer
#10 lore raw
Quoted 4 lines · On Mon, 23 Nov 2026 13:43:58 +0000 Ryan Prinz wrote:

A 6LoWPAN fragment carries the datagram's total size (d_size) and its own offset within it. lowpan_frag_queue() never checks that the offset, or offset plus length, fits inside d_size, and never rejects an empty fragment.

Please don't send patches in reply to existing threads.