From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.227.132 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795877110; b=fCwWE9e/8vKuoWdwOW8Nhwdjw4NEjzGnrRPzDnrVI/AWVZM/uvS80MCu8mJY8Myi5tE+ 7ssJB7h1CPEeA1yupZqUgxrwpgrfLigji+nMcH5EXLvhNPbbSU1qBgwoVvGy1sbMBqBi5 1ZI13HJnbHwA//IgMS57mbFvG0+I98NLkD1TN4hTssgNySGmNtvhUSKHXtTL+tl/XRzZn W2HNFaINrmwXkCwJSXBthp6fIOG0mKkMFeSuSpSpxHj8pxHTtOjcbFR/nSHrMEkUpPCZg HQbXN2DV2PlKHvVuwax8BLlRaDlQDYYTmEgdp5LPYaqhiPiBOh/Tb072EbGTDuvZF+g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795877110; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject: Date:Message-ID:X-Mailer:MIME-Version:Content-Transfer-Encoding; bh=yYzGGwI5EbgAAj/SOn20ulTMZQ+hqedEJnub6nNYwrI=; b=EBu3ZPS0AWckdjI5oVNM71X/pz9/WnNavnK6jD7V6/8h0LnOWXJR3JolLd2tUJ9JuXa2 j8afEk3SycMYmSOhtxUUmI03XDTs6qeMlZtGQEvJg7W1EkXPBJaUPc5N7EVl448xgkmO4 NndTnk7HIbztGunZ7gk/vmcW/UaOfjuh14kPec8nOnP6242DVtg2u4/xPyhTmg+OyDRi+ okOHqBJrFSJapAcFJWuhBH+a5dkWCFS7mQN7T9EUA91naAFFyGvjUV7X7o5ytzIfb0maO D5XHMNycHmJHKQqhAwTSQv2tgbTg3GnQS2Y/ZarAe5yDwoMOOzmizUGuZXI2XSiGdEQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=f5Ikc0j2; arc=none smtp.remote-ip=74.125.227.132 Received: from mail-pj2-f4.google.com (mail-pj2-f4.google.com [74.125.227.132]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7786D606A321 for ; Sat, 28 Nov 2026 14:45:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 7786D606A321 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=f5Ikc0j2 Received: by mail-pj2-f4.google.com with SMTP id d9443c01a7336-2f0440f49f4so61746155ad.0 for ; Sat, 28 Nov 2026 06:45:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1795877110; x=1796481910; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=yYzGGwI5EbgAAj/SOn20ulTMZQ+hqedEJnub6nNYwrI=; b=f5Ikc0j2v2pFZM0WwyInT2c7aCfYqJz8kDfU8fBjRpkBqDwuO4YdXUHal05a4qkF9T AD2wmjdDMR/3XwfO5vU1P0MWw+vB+gGW+tboGT2c5SBBQgBzXEx86MSmd6Qrzp29fkxp PTjjvDf8oep726sMLOKvcvzpRUOcrOwholUndk7q8L9UgaB0hOrNeTiKiQ/wqNHOYssn Jf0z88ovj9MvIfWp5nYEEcpvnJ1IYpcqJOpGQYWrfZW76vWisF6ugUHmSsakCVuikD/U FfdDDkVRleEVoHkRKAKRvq3kSkZm1Jf/cgpYp61J3KXW5Qot1Chk+pSQr4WG4MBBJRrk dOpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795877110; x=1796481910; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=yYzGGwI5EbgAAj/SOn20ulTMZQ+hqedEJnub6nNYwrI=; b=MYu/hfDTB/CP82v9MCRHH/Weao7hCPNAgZ2d4U1GG0mtlohHwPG4fYcUzxAA4BUQ7y mNBSwcWnqLEnxa3doUJZ+0WbAC72ofZK4wgvLhHfGzbxa1w7t0xkHmSGgMe27MaA09Cs 13N8huMEzo1Ds6NY+pjRskGTcZs/JGqMpGlGPLV6YXJTb9sZyRTNUGryYcWdouKJfHCD choDC8L6FEWn1ajHmmch+5xD6dHFNjNrRF1Lke+DBznA0EPKQ0BX3eiIHVO2VAYXnKPH CZtFhUDU4oYqDE2wCulFFg6qdSwv2uikA+yhgRghTfaPYbJ6U/D/rH8Y6AEJAicj5T2H wmyA== X-Gm-Message-State: APuU4Z/Chk2xybZtTtKC4EBTdOUUGzc5t0coxdgMkaDL4T3C7/MTH00K dLMU+U6iAPRHtgzuT5TPXytoC45A3p0dOyiveUkyG16XW+7FpUv6fLH3ZNdct+BMPab8uw== X-Gm-Gg: AZFdTZeOfcURzNrcBGLtO5NHKi1K8IshV8exCmj8oFwC2xvl42xwKbUkPdsQg9/CR1T MJBFRt/oN44Btk6aNcMRiVYxkalvKhxOneJD8aqAVLZi2O6tpyrwc2K9Rsyyi+1e8616+cGSdch TB2Kj7bVvCf06caWnftB8tuCpVJp1p79PXLLQB3hoRvXCtWl8DQnMqUs4CuN+k/Pp8yJr2MZRAU IYh6mphQOzIXHU8TVZkzaEd80QyBKhODt/t6ZTEtQCJwaGd2K88fZFNq9SdOVI9VSfWgnoMO3Q2 ORHYAKffcRTYrXJWEmLt69Aq+nO8df6ieThxUuNTuriTFyAm1xw1E1s+gmF//gY5SHamqTTkglf IPrXTMM6obwbtrsGgEuf6jCQBxCOtXqIqcG0j37sAwry1sXX45mJ2Ps0Yy5lUYSqx4j3XpRrpfJ dx0IV68kuHuTpauK2+dZbVfFpsv9ap/oLvl/bAxZ5NvccIhwQztU17ww8s2kSdQROvRWFVDxbFv 5npaACW8DhQFuyEQcV9Qd8LEYy4iHqwmAOUqDkptwpV++LpfGVx5xDLFKncprDSiy2QB4K754+i s+RHHD/8RhJdiMkOGG9MfIGhUT+mulwt1p3P43Xppxqx/VQ7XXdxr3Dp4JLyeJS5yhBEMWtQRA= = X-Received: by 2002:a17:903:2285:b0:2f0:41c7:9a40 with SMTP id d9443c01a7336-2f041c7b268mr303096595ad.4.1795877109640; Sat, 28 Nov 2026 06:45:09 -0800 (PST) Received: from BSDHENRYMA-PC1.localdomain ([43.132.141.31]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-cdec1168866sm4926108a12.25.2026.11.28.06.45.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Nov 2026 06:45:09 -0800 (PST) From: Henry Martin To: David Ahern , Ido Schimmel , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Willem de Bruijn , Simon Horman , Pablo Neira Ayuso , Florian Westphal , Phil Sutter , Peter Oskolkov Cc: netdev@vger.kernel.org, netfilter-devel@vger.kernel.org, coreteam@netfilter.org, Henry Martin , stable@vger.kernel.org Subject: [PATCH net] netfilter: ipv6: fix out-of-bounds write in fragment reassembly Date: Sat, 28 Nov 2026 22:44:37 +0800 Message-ID: <20261128144437.819730-1-bsdhenrymartin@gmail.com> X-Mailer: git-send-email 2.53.0 X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit nf_ct_frag6_queue() trusts the on-wire payload_len, which IPV6_HDRINCL lets diverge from the real packet length. A fragment whose payload_len is smaller than its extension header chain yields end < offset. Only end == offset was rejected, pskb_trim_rcsum() takes the negative length as a huge unsigned value and does not trim, and the lying fragment is queued as is. inet_frag_queue_insert() walks the rb-tree by offset, so a fragment with end < offset lands on the wrong side and breaks the invariant that rb_first() is the first fragment. When the queue completes, nf_ct_frag6_reasm() mistakes a small later fragment for the head and stores the trailing nexthdr byte at skb_network_header(skb)[fq->nhoffset]. nhoffset is controlled through the extension header chain and can point far beyond the head buffer. The result is a one-byte controlled out-of-bounds write past a heap object, which corrupts neighbouring slab objects and panics the kernel, e.g. on mainline v7.4.0-rc4 (KASAN build): Oops: general protection fault, probably for non-canonical address 0xed6d696d6d6d6d6d: 0000 [#1] SMP KASAN NOPTI CPU: 0 UID: 1000 PID: 78 Comm: poc Tainted: G W RIP: 0010:skb_release_data+0x1e7/0x640 Call Trace: sk_skb_reason_drop+0xbd/0x320 nf_ct_frag6_gather+0x13f2/0x28a0 ipv6_defrag+0xa6/0x190 nf_hook_slow+0xa5/0x1c0 ipv6_rcv+0x147/0x260 Kernel panic - not syncing: Fatal exception in interrupt Fix the class rather than a single comparison: * reject a payload_len that promises more than the skb holds before it is used to derive end; * reject end <= offset right after the range check and before the MF/LAST_IN state machine, so a dropped fragment cannot leave fq->q.len and INET_FRAG_LAST_IN modified; * apply the same ordering to ip6_frag_queue() and ip_frag_queue(), which share the check and the rb-tree invariant. end == offset was already rejected; end < offset is never a valid fragment. This issue was discovered by Tencent CodeBuddy Security. Cc: stable@vger.kernel.org Fixes: fa0f527358bd9 ("ip: use rb trees for IP frag queue.") Signed-off-by: Henry Martin --- net/ipv4/ip_fragment.c | 13 +++++++++++-- net/ipv6/netfilter/nf_conntrack_reasm.c | 18 +++++++++++++++--- net/ipv6/reassembly.c | 17 ++++++++++++++--- 3 files changed, 40 insertions(+), 8 deletions(-) diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c index 0688be8142c4b..3cc12e8b1786b 100644 --- a/net/ipv4/ip_fragment.c +++ b/net/ipv4/ip_fragment.c @@ -294,6 +294,17 @@ static int ip_frag_queue(struct ipq *qp, struct sk_buff *skb, int *refs) end = offset + skb->len - skb_network_offset(skb) - ihl; err = -EINVAL; + /* A fragment must carry at least one byte after its IP header, + * otherwise end < offset and the rb-tree ordering breaks. Reject + * before touching any qp state. + */ + if (end <= offset) + goto discard_qp; + + /* tot_len must fit in the skb; IP_HDRINCL lets it diverge. */ + if (ntohs(ip_hdr(skb)->tot_len) > skb->len - skb_network_offset(skb)) + goto discard_qp; + /* Is this the final fragment? */ if ((flags & IP_MF) == 0) { /* If we already have some bits beyond end @@ -317,8 +328,6 @@ static int ip_frag_queue(struct ipq *qp, struct sk_buff *skb, int *refs) qp->q.len = end; } } - if (end == offset) - goto discard_qp; err = -ENOMEM; if (!pskb_pull(skb, skb_network_offset(skb) + ihl)) diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c index f25ff2a12a824..953eb25e440c7 100644 --- a/net/ipv6/netfilter/nf_conntrack_reasm.c +++ b/net/ipv6/netfilter/nf_conntrack_reasm.c @@ -184,6 +184,14 @@ static int nf_ct_frag6_queue(struct frag_queue *fq, struct sk_buff *skb, payload_len = ntohs(ipv6_hdr(skb)->payload_len); + /* IPV6_HDRINCL allows payload_len to differ from the real packet + * length. Never let it promise more than the skb actually holds. + */ + if (payload_len + sizeof(struct ipv6hdr) > skb->len) { + pr_debug("payload_len exceeds skb length.\n"); + goto err; + } + offset = ntohs(fhdr->frag_off) & ~0x7; end = offset + (payload_len - ((u8 *)(fhdr + 1) - (u8 *)(ipv6_hdr(skb) + 1))); @@ -193,6 +201,13 @@ static int nf_ct_frag6_queue(struct frag_queue *fq, struct sk_buff *skb, return -EINVAL; } + /* A fragment must carry at least one byte after its fragment + * header, otherwise end < offset and the rb-tree ordering breaks. + * Reject before touching any fq state. + */ + if (end <= offset) + goto err; + ecn = ip6_frag_ecn(ipv6_hdr(skb)); if (skb->ip_summed == CHECKSUM_COMPLETE) { @@ -236,9 +251,6 @@ static int nf_ct_frag6_queue(struct frag_queue *fq, struct sk_buff *skb, } } - if (end == offset) - goto err; - /* Point into the IP datagram 'data' part. */ if (!pskb_pull(skb, (u8 *) (fhdr + 1) - skb->data)) { pr_debug("queue: message is too short.\n"); diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c index 91a65fe673500..2f20b0f745cf5 100644 --- a/net/ipv6/reassembly.c +++ b/net/ipv6/reassembly.c @@ -124,6 +124,13 @@ static int ip6_frag_queue(struct net *net, } err = -EINVAL; + + /* IPV6_HDRINCL allows payload_len to differ from the real packet + * length. Never let it promise more than the skb actually holds. + */ + if (ntohs(ipv6_hdr(skb)->payload_len) + sizeof(struct ipv6hdr) > skb->len) + goto discard_fq; + offset = ntohs(fhdr->frag_off) & ~0x7; end = offset + (ntohs(ipv6_hdr(skb)->payload_len) - ((u8 *)(fhdr + 1) - (u8 *)(ipv6_hdr(skb) + 1))); @@ -138,6 +145,13 @@ static int ip6_frag_queue(struct net *net, return -1; } + /* A fragment must carry at least one byte after its fragment + * header, otherwise end < offset and the rb-tree ordering breaks. + * Reject before touching any fq state. + */ + if (end <= offset) + goto discard_fq; + ecn = ip6_frag_ecn(ipv6_hdr(skb)); if (skb->ip_summed == CHECKSUM_COMPLETE) { @@ -178,9 +192,6 @@ static int ip6_frag_queue(struct net *net, } } - if (end == offset) - goto discard_fq; - err = -ENOMEM; /* Point into the IP datagram 'data' part. */ if (!pskb_pull(skb, (u8 *) (fhdr + 1) - skb->data)) -- 2.53.0