Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=62.96.220.36 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796129047; b=FagW96BmTabZADO+zy8TMsLHNwlVZfwNFFemE4XACnI/si+530YyJ/EJGr1nky1SwTjy Dn9X1U8/Vn4mwkT4165BQ0GVYHzSTFH9qEUhOtTOpnOWZBsOfW6Wtzpxfe5rSqUmdaaaR +Ge93GNxamP/vUYp2eKFS/ugzxIuX7ZYnQvM9fBujQwyiVSp/qNfMIB4F0n84BJp9gHX5 Lt5XPc6XpKXtrUx9l25mvSTqwN74LX3XQtlsavUn339nSHurtEi5pob+ODmnqaFIU6cMg tQvBIchRW5AGs3JsKNs/vkbTD62KziuXXuBxDxhVHtoyMDIz3c0XaEifmwwwM1Mj5qw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796129047; h=DMARC-Filter:Received:X-Virus-Scanned:Received:Received:DKIM-Filter: DKIM-Signature:Received:Received:From:To:CC:Subject:Date:Message-ID: X-Mailer:In-Reply-To:References:MIME-Version:Content-Type: Content-Transfer-Encoding:X-ClientProxiedBy; bh=+GYoqlrVOiYatIM0gSjUmFqOHSPoziHIH3NddMO9WM8=; b=18h4soLFBOjvrIdJYwsvUXLhkSygJK8hslXrcNxYM0hFMvg40hKUtpqENLDUXpudbqF4 IZ6nJDDRuVJTUX4xoHafMIEltfIUxIO7ZKki7VBAEiLmQ3VNgg+Gqvn6t42uUbqb/G2/V S9azxWnw4B7uPlgAR5NgOG7cBwErEkxVYy4PVeMTfhwGxTRQrP8VcBnvftCBviycHxJp4 3IS24VqEd/Zv+wYjLoJluBU+pxsH8j7H1k1A4tcCthZBALBQIlyOppd5caEbV0/XGePyU kntIApOBEWZS5PybmWXEWXUmLdeg1gSIL0vFOOiO0rgRna6QsxOYC/f25BKXExfn/uw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=secunet.com; spf=pass smtp.mailfrom=secunet.com; dkim=pass header.d=secunet.com header.i=@secunet.com header.a=rsa-sha256 header.s=202301 header.b=eeADSNug; arc=none smtp.remote-ip=62.96.220.36 Received: from mx1.secunet.com (mx1.secunet.com [62.96.220.36]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5BDBF606A332 for ; Tue, 1 Dec 2026 12:44:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 5BDBF606A332 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=secunet.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=secunet.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=secunet.com header.i=@secunet.com header.a=rsa-sha256 header.s=202301 header.b=eeADSNug Received: from localhost (localhost [127.0.0.1]) by mx1.secunet.com (Postfix) with ESMTP id F0EEA207BE; Tue, 1 Dec 2026 13:44:04 +0100 (CET) X-Virus-Scanned: by secunet Received: from mx1.secunet.com ([127.0.0.1]) by localhost (mx1.secunet.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id X59xgnAUooYs; Tue, 1 Dec 2026 13:44:03 +0100 (CET) Received: from EXCH-01.secunet.de (rl1.secunet.de [10.32.0.231]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.secunet.com (Postfix) with ESMTPS id DB6B9204D9; Tue, 1 Dec 2026 13:44:03 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.secunet.com DB6B9204D9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=secunet.com; s=202301; t=1796129043; bh=+GYoqlrVOiYatIM0gSjUmFqOHSPoziHIH3NddMO9WM8=; h=From:To:CC:Subject:Date:In-Reply-To:References:From; b=eeADSNugd8RWG0NIXahIy8X7QBq4IDbPF+Elo7CsS683I6DIerNlqAoYUdkm1DVsD svKk8Ix3LUCu3XOCcMet899gD/HD5JeZxBy5mMktu/j5tNgIh2P9TMD6T15zBi5HyX atuPmArCvMsrPYaQlsaAG9oGs+rP5wv7/u4HhyyTtCL4v2y5wokpfOLlvOJwB9SL3M uMFc2Abh+/r/6K7NfjOY0G15vo3CKkIoJx3CaCPWrKlDTUY8oQN6ZYWkLZW6SI8Jb0 w7t6EcRwHELlOZl0Tst5E9saUY8AGs23DLAp5gtS8s2HLg+OYrNe9hS64Xa+6WGgqv r4Xj8daNRJxFw== Received: from gauss4 (10.182.7.102) by EXCH-01.secunet.de (10.32.0.171) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.49; Tue, 1 Dec 2026 13:44:03 +0100 Received: (nullmailer pid 1165797 invoked by uid 1000); Tue, 01 Dec 2026 12:43:55 -0000 From: Steffen Klassert To: David Miller , Jakub Kicinski CC: Herbert Xu , Steffen Klassert , Subject: [PATCH 11/22] xfrm: fix selector matching for IPv6 atomic fragments Date: Tue, 1 Dec 2026 13:41:37 +0100 Message-ID: <20261201124252.1163254-12-steffen.klassert@secunet.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261201124252.1163254-1-steffen.klassert@secunet.com> References: <20261201124252.1163254-1-steffen.klassert@secunet.com> 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-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-ClientProxiedBy: EXCH-04.secunet.de (10.32.0.184) To EXCH-01.secunet.de (10.32.0.171) From: Jérémy Jean IPv6 atomic fragments contain a complete packet, but XFRM leaves the port, ICMPv6 and GRE selector fields unset. Plaintext can then miss a matching policy. Have ipv6_find_hdr() mark non-atomic Fragment headers. Restore the fields only when every Fragment header is atomic. Use its offset when the transport header is before skb->data. Read with skb_header_pointer() so decoding does not pull or reallocate the skb. Fixes: 7e3a42a12c4b ("xfrm6: handling fragment") Cc: stable@vger.kernel.org Signed-off-by: Jérémy Jean Signed-off-by: Steffen Klassert --- include/net/ipv6.h | 1 + net/ipv6/exthdrs_core.c | 25 +++++++++++++------------ net/xfrm/xfrm_policy.c | 19 ++++++++++++++++++- 3 files changed, 32 insertions(+), 13 deletions(-) diff --git a/include/net/ipv6.h b/include/net/ipv6.h index 3de07e738538..10785721b013 100644 --- a/include/net/ipv6.h +++ b/include/net/ipv6.h @@ -1110,6 +1110,7 @@ enum { IP6_FH_F_FRAG = (1 << 0), IP6_FH_F_AUTH = (1 << 1), IP6_FH_F_SKIP_RH = (1 << 2), + IP6_FH_F_NON_ATOMIC = (1 << 3), }; /* find specified header and get offset to it */ diff --git a/net/ipv6/exthdrs_core.c b/net/ipv6/exthdrs_core.c index 4a9748338cf4..f00c28ce2f1e 100644 --- a/net/ipv6/exthdrs_core.c +++ b/net/ipv6/exthdrs_core.c @@ -183,7 +183,8 @@ EXPORT_SYMBOL_GPL(ipv6_find_tlv); * isn't NULL. * * if flags is not NULL and it's a fragment, then the frag flag - * IP6_FH_F_FRAG will be set. If it's an AH header, the + * IP6_FH_F_FRAG will be set. IP6_FH_F_NON_ATOMIC will be set for a + * non-atomic Fragment header. If it's an AH header, the * IP6_FH_F_AUTH flag is set and target < 0, then this function will * stop at the AH header. If IP6_FH_F_SKIP_RH flag was passed, then this * function will skip all those routing headers, where segements_left was 0. @@ -191,23 +192,20 @@ EXPORT_SYMBOL_GPL(ipv6_find_tlv); int ipv6_find_hdr(const struct sk_buff *skb, unsigned int *offset, int target, unsigned short *fragoff, int *flags) { - unsigned int start = skb_network_offset(skb) + sizeof(struct ipv6hdr); - u8 nexthdr = ipv6_hdr(skb)->nexthdr; + unsigned int start = *offset ?: skb_network_offset(skb); + struct ipv6hdr _ip6, *ip6; int exthdr_cnt = 0; + u8 nexthdr; bool found; if (fragoff) *fragoff = 0; - if (*offset) { - struct ipv6hdr _ip6, *ip6; - - ip6 = skb_header_pointer(skb, *offset, sizeof(_ip6), &_ip6); - if (!ip6 || (ip6->version != 6)) - return -EBADMSG; - start = *offset + sizeof(struct ipv6hdr); - nexthdr = ip6->nexthdr; - } + ip6 = skb_header_pointer(skb, start, sizeof(_ip6), &_ip6); + if (!ip6 || (*offset && ip6->version != 6)) + return -EBADMSG; + nexthdr = ip6->nexthdr; + start += sizeof(struct ipv6hdr); do { struct ipv6_opt_hdr _hdr, *hp; @@ -254,6 +252,9 @@ int ipv6_find_hdr(const struct sk_buff *skb, unsigned int *offset, if (!fp) return -EBADMSG; + if (flags && (*fp & htons(IP6_OFFSET | IP6_MF))) + *flags |= IP6_FH_F_NON_ATOMIC; + _frag_off = ntohs(*fp) & ~0x7; if (_frag_off) { if (target < 0 && diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c index 6baff3f797f8..d2e938d4db9a 100644 --- a/net/xfrm/xfrm_policy.c +++ b/net/xfrm/xfrm_policy.c @@ -3530,9 +3530,26 @@ int __xfrm_decode_session(struct net *net, struct sk_buff *skb, struct flowi *fl decode_session4(&flkeys, fl, reverse); break; #if IS_ENABLED(CONFIG_IPV6) - case AF_INET6: + case AF_INET6: { + unsigned int offset = 0; + int thoff = flkeys.control.thoff; + int fh_flags = 0; + + if ((flkeys.control.flags & FLOW_DIS_IS_FRAGMENT) && + ipv6_find_hdr(skb, &offset, -1, NULL, &fh_flags) >= 0 && + (fh_flags & IP6_FH_F_FRAG) && + !(fh_flags & IP6_FH_F_NON_ATOMIC)) { + if (offset > U16_MAX) + thoff = (int)offset; + flkeys.control.flags &= ~FLOW_DIS_IS_FRAGMENT; + flkeys.ports.ports = skb_flow_get_ports(skb, + thoff, + flkeys.basic.ip_proto, + NULL, 0); + } decode_session6(&flkeys, fl, reverse); break; + } #endif default: return -EAFNOSUPPORT; -- 2.53.0