From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.227.131 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795876644; b=Sodf+chJSrfu23K1A7Iooy7yeIks7YweHYXpdNITEl9HaFJ4RjKLDQ9qTr3r03dfdscx fUZj637/fqUf4w5Jh0S/Luz66baWlnD4zdfYp5T7Lm1Wrrij9pUa6iK6JL362DxZTA4lN Svku8tpWlFoCsHTKA9si3FpJiiMIjpLeyE/cZtygR94JfAcJjJD3JvjiynHCnMBa+Q+5r ACtuImYOJ6MNOUpj4AZt2ljbQ0g7nMr3yQSpRBGZYJsdjLFdUb6MowMKC/un0vtAIzpcZ DQrN9dkvJOO06ycPn7M0j0kk0InFeHBWOFuaiOI1gwXHTkJiv50EUXJa4qZZyzFaR3w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795876644; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted: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=Z/8sq399iOQi8b5iggBDdx0erp9tLsunSAgn1MXEQrjwuvnCvLklkuMzQC/e92slSsVC irxyv9RD+LcmbaWQ7/loLYDvk68/oDLkcC2EztFdSrj79zbkkVAEX1C8Du3wsGkWFEi0g BWXb39MXXBUrLVG/iQYvSrElT8WZ2bRm4KNwnfupTntdSLcj192YTZUFCsW0fkCnsqYCU am664+C3Sk4VvC99khvFhrRM3zfxlxc8aU8Qamx6NmXv8U4QfkiAQgQVGqGCY2IP3zxfS Pmg/aOD0/qCUJjqYFJ4bfu7epOLg32XsAvg46LJH/7o//oXnCKS/TkEi+AVZrMUdeMA== 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=wc4ZFCqq; arc=none smtp.remote-ip=74.125.227.131 Received: from mail-pj2-f3.google.com (mail-pj2-f3.google.com [74.125.227.131]) (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 B7548606A31C for ; Sat, 28 Nov 2026 14:37:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B7548606A31C 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=wc4ZFCqq Received: by mail-pj2-f3.google.com with SMTP id 98e67ed59e1d1-3b497279bf2so668957a91.1 for ; Sat, 28 Nov 2026 06:37:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1795876643; x=1796481443; 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=wc4ZFCqq3wEvKNv4SIwxw5mdJHFIq7gKHb9bsh6VIY8HbE9Sm0IG5lcCoPgrpDtpX5 waOsaADDFUIaQGzn5fdhAOkp467/vHWfbFJoS7lJP8R3aYsoOhlQYPKoK3vjyGwf7GVI ap1yCNOmftXkcznR3YI4lDboi2ja/+6e+0YYjAqODYysPec4fD0SQeOL04qGOWY4dhn5 qEkH3SAWB5Ch53hENEy405Nvll31O/sud8DiY1lQA0leQHK1zWoZ4HsJfOOolpMaaamb yr6V8hnA22GulbWZ8BQkW3RqNLjxoOlIEuvnpawOJE9ShmQibT/yxqkz8cCxGfvDI9qu cOaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795876643; x=1796481443; 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=H8lNOu0N9ytS4wsYBgb4XIxyqVigqDS9vXPM2YQ8oHIIkFOW+z/DePMST6ffgqixb8 tsXPjYo9LkUVe4KFrOwvFJQXMvTETnucYIknKn/DcZ7iF/xuXXt8stISw6nhA1kfbzXV Yx4xO1qHhsgXcvVXuymK70X4o2GPLrbkJRnua6eu0Mjc9F66o1aMBiwKZuICd9AGcQgw N4U1oymICh1CIRlRYmt53dk7QChnfbW+2dzsAY07obM4ht4Y2PBQgMRL0bOrPPs4351L 7bOtnqjgt4iBXu+ZhDl0KcaobFbhrKJcLxHdnoToHyg/5eumrjeK6vYFG0P/EMQlrL2h 14MA== X-Forwarded-Encrypted: i=1; AL+hErFgvrk1C6sBN8Sup2tEyMMV9Leb1IgvlHgm8QwIyJWD7oV1/ivfushKS3sHiFe8rlL2gXBt9gI=@vger.kernel.org X-Gm-Message-State: APuU4Z+4n3Ypy/hjvCLi/Dw6YlRX9gcCOIc7e4xyCeNFIhSHOgX9LAAn 0EHOw3LaN6PH1se0Bn2EqYLhtZGhe2DNmmsgMjNoGE0corogcDI2EDug X-Gm-Gg: AZFdTZd/Me7vkTC0h4xJ5tFZxDhFSq41IYHLR/tyZ8VtOb5XiEaTKD3L5mB3iM9Zk5N Y4otCgsVXpHaJQZXL9Vp/sXm49m4HOwMMTs78oLRf/fulguJK1RA3BGKtg1+4vwWLhLvIZBgXRX AXfMKJwZ6k+lP//26SsKrH1vbtW8ljfFelh9mtKo0bSxI2rG1GzS8wtUBL9HrKsopP/Jo0h79Wi zBlGnb3puG3GoGHB5GYWmK8Vgsk9Ma7s8IOrI6aDtQzwTHLXxo/p/ke2Hei0McCvGWkvp0RAZzs ft2Vg5mDhVNIzRaTIj8yVPzJH3g2mrJC6yjP40BFPbHgdrq6U/IWG3MBMmu1hWBoGnHC5girqVF hKpEfbsuFQueeFVtLO5hWiIwTXUUl9NAtfeBjEcMkrSIVNBkrRF0gBCg+gf2lxv9I1+ISl8k2++ 4KwvtFb1kC6jiZb5rBae3oD1JAxPnY3/k6bjnkckyKl4qzaakpHj83xbW1iaZAn5p9vky+wdQFS 1PgmayQw8PFk2Qiv06RrKl/2EJRgHvHJ+LCcEZBOm+i+c0usFoq659O0qLRMDZgilmI3OVeyHiO 4lc2lM730UpF2iYBeqMCTqwhzydySxUnsow8POeWhvMRqbs9LTWs6VKUzTLeBZVkMhtRQ7H317r 9 X-Received: by 2002:a17:90b:3c11:b0:3a7:9ec3:ea0e with SMTP id 98e67ed59e1d1-3b41c908114mr17793259a91.22.1795876642889; Sat, 28 Nov 2026 06:37:22 -0800 (PST) Received: from BSDHENRYMA-PC1.localdomain ([43.132.141.26]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3b405ecb486sm46221316a91.16.2026.11.28.06.37.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Nov 2026 06:37:21 -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, stable@vger.kernel.org Subject: [PATCH net] netfilter: ipv6: fix out-of-bounds write in fragment reassembly Date: Sat, 28 Nov 2026 22:37:09 +0800 Message-ID: <20261128143710.811389-1-bsdhenrymartin@gmail.com> X-Mailer: git-send-email 2.53.0 X-Mailing-List: stable@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