Netdev List
 help / color / mirror / Atom feed
* [PATCH net] net: ipv4: reject invalid fragment ranges
@ 2026-12-01  3:11 zhuorao yang
  2026-12-03 18:14 ` netdev-bot+sashiko
  0 siblings, 1 reply; 2+ messages in thread
From: zhuorao yang @ 2026-12-01  3:11 UTC (permalink / raw)
  To: David Ahern, Ido Schimmel, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Willem de Bruijn
  Cc: netdev

inet_frag_queue_insert() assumes offset is smaller than end when it
inserts a fragment into the interval tree. nf_ct_frag6_queue() can
violate that assumption for an unclipped IPv6 skb: payload_len minus
the extension header length underflows, leaving end smaller than
offset.

The invalid range then enters the left subtree and breaks the rbtree
ordering. Reassembly can select a non-first fragment as the head,
triggering inet_frag_reasm_prepare()'s WARN_ON(). On current mainline,
the misplaced head also reaches the conditional one-byte out-of-bounds
write in nf_ct_frag6_reasm().

Reject end <= offset in the shared insertion helper before inserting
the range.

Fixes: c23f35d19db3 ("net: IP defrag: encapsulate rbtree defrag code into callable functions")
Signed-off-by: zhuorao yang <alex000young@gmail.com>
---

Vulnerability report

Affected versions: Linux 7.4.0-rc5 at
  fe6ff8d5d675c01793b9f051d16055dd4aa75244; the rbtree form dates to
  v5.1.
Trigger conditions: CONFIG_USER_NS and CONFIG_NET_ACT_CT. A local user
  can create a user and network namespace, configure tc ingress ct
  processing, and send the malformed IPv6 fragments. The same path is
  reachable from network traffic when such pre-L3 conntrack
  defragmentation is deployed.
Reproducer status: A QEMU/KASAN reproduction on 7.4.0-rc5 reaches
  inet_frag_queue_insert(offset=8, end=0), triggers the
  inet_frag_reasm_prepare() WARN_ON(), and reports a one-byte KASAN
  write in nf_ct_frag6_gather(). The fixed kernel completes the same
  test without the warning or KASAN report. Reproducer material is
  available to maintainers on request.
Reproducer material is intentionally withheld from this public message.

AI assistance: DeepSeek identified the issue and drafted the patch.
The submitter reviewed the code and certified the Developer Certificate
of Origin.

 net/ipv4/inet_fragment.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/net/ipv4/inet_fragment.c b/net/ipv4/inet_fragment.c
index f330d0a39823..9f3b632f5753 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;
+
 	/* The reassembled skb keeps the first fragment's secpath. */
 	if (last && !secpath_equal(last, skb))
 		return IPFRAG_MIXED_SECPATH;
-- 
2.56.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH net] net: ipv4: reject invalid fragment ranges
  2026-12-01  3:11 [PATCH net] net: ipv4: reject invalid fragment ranges zhuorao yang
@ 2026-12-03 18:14 ` netdev-bot+sashiko
  0 siblings, 0 replies; 2+ messages in thread
From: netdev-bot+sashiko @ 2026-12-03 18:14 UTC (permalink / raw)
  To: alex000young
  Cc: dsahern, idosch, davem, edumazet, kuba, pabeni, willemb, netdev

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-12-03 18:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-01  3:11 [PATCH net] net: ipv4: reject invalid fragment ranges zhuorao yang
2026-12-03 18:14 ` netdev-bot+sashiko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox