🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #12305

[PATCH net v3 2/2] xfrm: fix selector matching for IPv6 atomic fragments

#12305
From: Jérémy Jean
Date: Fri, 06 Nov 2026 20:29
96 lines
13162 bytes
Commit 7e3a42a12c4b ("xfrm6: handling fragment") stopped decoding IPv6
selector fields after a Fragment header. That is correct for real
fragments because later fragments do not carry those fields, yet an
atomic fragment is different because it contains the complete
datagram, which allows XFRM to read its ports, ICMPv6 type and code,
and GRE key. Leaving those fields zero lets a plaintext atomic
fragment miss a policy that matches on one of them.

Leave ports, ICMPv6 type and code, and GRE key unset for real
fragments. For atomic fragments, treat the packet as a complete
datagram during IPv6 session decoding and recover the ports at the
transport offset found by the flow dissector.

Have ipv6_find_hdr() report non-atomic Fragment headers while it walks
the extension header chain. Pull the base IPv6 header before calling
it so nonlinear skbs are safe, and recover selectors only when every
Fragment header it sees is atomic.

Fixes: 7e3a42a12c4b ("xfrm6: handling fragment")
Cc: stable@vger.kernel.org
Signed-off-by: Jérémy Jean <Jeremy.Jean@oss.cyber.gouv.fr>
---
 include/net/ipv6.h      |  1 +
 net/ipv6/exthdrs_core.c |  6 +++++-
 net/xfrm/xfrm_policy.c  | 17 ++++++++++++++++-
 3 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/include/net/ipv6.h b/include/net/ipv6.h
index 3de07e738538f..10785721b013d 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 4a9748338cf40..9b9e2ce72e170 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.
@@ -254,6 +255,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 bda5100c9fdbf..679343b23df35 100644
--- a/net/xfrm/xfrm_policy.c
+++ b/net/xfrm/xfrm_policy.c
@@ -3526,9 +3526,24 @@ 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 fh_flags = 0;
+
+		if ((flkeys.control.flags & FLOW_DIS_IS_FRAGMENT) &&
+		    pskb_network_may_pull(skb, sizeof(struct ipv6hdr)) &&
+		    ipv6_find_hdr(skb, &offset, -1, NULL, &fh_flags) >= 0 &&
+		    (fh_flags & IP6_FH_F_FRAG) &&
+		    !(fh_flags & IP6_FH_F_NON_ATOMIC)) {
+			flkeys.control.flags &= ~FLOW_DIS_IS_FRAGMENT;
+			flkeys.ports.ports = skb_flow_get_ports(skb,
+								flkeys.control.thoff,
+								flkeys.basic.ip_proto,
+								NULL, 0);
+		}
 		decode_session6(&flkeys, fl, reverse);
 		break;
+	}
 #endif
 	default:
 		return -EAFNOSUPPORT;
-- 
2.47.3
Technical Details
Message-ID: <20261106202910.723098-6-Jeremy.Jean@oss.cyber.gouv.fr>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-358159-linux-kernel-netdev=dewy.ru
References: <20261106202910.723098-2-Jeremy.Jean@oss.cyber.gouv.fr>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-358159-linux-kernel-netdev=dewy.ru
From: Jeremy.Jean@oss.cyber.gouv.fr (Jérémy Jean)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net v3 2/2] xfrm: fix selector matching for IPv6 atomic fragments
Date: Fri,  6 Nov 2026 20:29:08 +0000
Organization: Usenet Network
Message-ID: <20261106202910.723098-6-Jeremy.Jean@oss.cyber.gouv.fr>
References: <20261106202910.723098-2-Jeremy.Jean@oss.cyber.gouv.fr>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="3969521"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:WQXLYBQ8EVYvzfaR6U00GW+bU8A= sha256:Dxw7N3xqYmlxLfP2gWB4KiO5/vAj2qYQEv9PoKRu9fw=
	sha1:a3Z4FU9L/gp6wEHI6iC80GMdg0A= sha256:A3LscpA4EDmz44YbGOe94YMje+Z/S4pqD/qmuzJ0QrA=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
	X-Source
	X-Source-Args
	X-Source-Dir
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 61CA911331A; Fri,  6 Nov 2026 23:32:54 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.052
X-Spam-Status: No, score=-3.052 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1,
	DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,
	HEADER_FROM_DIFFERENT_DOMAINS=0.249, MAILING_LIST_MULTI=-1,
	RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001]
	autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=oss.cyber.gouv.fr
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id 9y-xLe75b4zQ;
	Fri,  6 Nov 2026 23:32:51 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-358159-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=oss.cyber.gouv.fr
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id EA94B11330F; Fri,  6 Nov 2026 23:32:42 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id 7763A3397E; Fri,  6 Nov 2026 20:29:58 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1793996998;
	b=UZVgINnL3HugsQ0nG70jji6gVAynAw4NFQSN7MS1Ou7SQVcU7ah1n+NJO7wCU6Iq1Mf3
	 VkY6NQGXkS9Yra+PFm0V3Rnmzi1Q2LE3h4UJMLfzO/sJGhoyPUStqctzAV0qxJATdmxvB
	 QRiYGhH4rEkxPVFVLKRwZvL8bnOuE2Ji64QZ4fl2yNnjPXaR7UKv5sHavt5UUEkTopw7C
	 5udLUh9ylw05S9aUbuSSxg/JHfxbCEsX7esACK2IbftJf2IWK3N87lme1UWSifD9+cgJs
	 a30t4f0Zt+zcm9dA9PhnGfXMsREqdjksP86gnGT2KbA4qV7rGpmqZX0JIvILiLFUgFw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793996998;
	h=X-Original-To:Received:DMARC-Filter:DKIM-Signature:Received:From:To:
	 Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References:
	 X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
	 List-Unsubscribe:List-Owner:Precedence:MIME-Version:Content-Type:
	 Content-Transfer-Encoding:X-AntiAbuse:X-AntiAbuse:X-AntiAbuse:
	 X-AntiAbuse:X-AntiAbuse:X-Get-Message-Sender-Via:
	 X-Authenticated-Sender:X-Source:X-Source-Args:X-Source-Dir;
	bh=HrXkiiGdUBmwU/LbSqgOWqBj4+1gSdkVc3p2fHsXaTk=;
	b=tg7ItjXC0qcIBCRQhrmmteqi0Y82bCJlLo4YfL/4nePGNsB7Z/VsMXFtBkzDpF4RccGh
	 inC5x8wL/cqNgS5zMw2CKqQl81GBmkScx4hieHHPR2XwaGrAjQRTcTPuEm3s7u5R0pOw6
	 E4/KB4lEa/2kjKF85RscSMz2SC3HjEH0g5SrHiU1xlTPyOWKZhlLS8NLlcHLV2YjKDGD+
	 ov6dT0QaWDqM1bkR+/cwRjXT2N1lTqP0jvjiH8po/uVurmKvj8Fe2Kyk2NuuCtAmMFSh1
	 jdGcgZpx8JKAom1+Zrg44dYVorfIgXIEGrXADV6fRJuxMP65CJ4oACOSgVk6KQGsbvQ==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=oss.cyber.gouv.fr header.i=@oss.cyber.gouv.fr header.a=rsa-sha256 header.s=default header.b="YITxRy/H";
	dmarc=pass header.from=oss.cyber.gouv.fr;
	spf=pass smtp.mailfrom=oss.cyber.gouv.fr;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 4C330606A329;
	Fri,  6 Nov 2026 20:29:58 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key, unprotected) header.d=oss.cyber.gouv.fr header.i=@oss.cyber.gouv.fr header.a=rsa-sha256 header.s=default header.b=YITxRy/H
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=51.159.188.251
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1793996982;
	b=MqWzmLqo1wjU0wAjQxofSOYgglrJCi5E2oAJ+o5m3EGyeie71+F8y7XkMCRQ1Ag6p2qK
	 larpAQZeYMUJ5IGTIZbFixTdatoND0t61IgGS4CmGEocr1LIFlQk29ZenF2ZpqH108Lbe
	 kLBme9Vn/qRvVbOQ22J92XC+mVHkR+M3EnZalQLpESc4Vx87XRk6IO3l6HSizN1o5ZKLr
	 dUrQcsHuCwHhwE4BDFWjkWgAEaSkmDwO9pGWnQIqrRM4DOS42qajKAi6/ElVexH+UoPfF
	 ETKvvCWoX14SBIH19dzMEmG3kOR28S7eSSEja8+B0rv3qA8pTqCsjcu2cecWD94wKwA==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793996982;
	h=DMARC-Filter:DKIM-Signature:Received:From:To:Cc:Subject:Date:
	 Message-ID:X-Mailer:In-Reply-To:References:MIME-Version:Content-Type:
	 Content-Transfer-Encoding:X-AntiAbuse:X-AntiAbuse:X-AntiAbuse:
	 X-AntiAbuse:X-AntiAbuse:X-Get-Message-Sender-Via:
	 X-Authenticated-Sender:X-Source:X-Source-Args:X-Source-Dir;
	bh=HrXkiiGdUBmwU/LbSqgOWqBj4+1gSdkVc3p2fHsXaTk=;
	b=VQhqiTL9Yyo7DNC7rGzTXnSvr5tcwbHK7i3SvYWLAFlczOkLXLro0a5pZ2uR/tN8wz8L
	 goy2oAYleF4BOM+YUeG6GrviOzmpgnYQTXKRhWtCppHNhwcVgenkBNR1mTXJhvGam/LlG
	 YWzfY83m6cXpPors1eyeYg2Ywin15bGNQIu8yKNoWzrLyFnjkjvWLazUgkWanaLEv/uCX
	 7L0aGLZvGvl7BOp/26Zjx0DOpgwiLfcH0RE1gNXZCqS1K/mHgSGQRDTjk0+tAfr2EwXuI
	 z/Na+4X0JM4Pa6cqQkfDvnDmNQJwAAokhqYQhCPfiwCUWCDbGAESGwpH+X1Y5saN5UQ==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=pass header.from=oss.cyber.gouv.fr;
	spf=pass smtp.mailfrom=oss.cyber.gouv.fr;
	dkim=pass header.d=oss.cyber.gouv.fr header.i=@oss.cyber.gouv.fr header.a=rsa-sha256 header.s=default header.b="YITxRy/H";
	arc=none smtp.remote-ip=51.159.188.251
X-Received: from oss.cyber.gouv.fr (oss.cyber.gouv.fr [51.159.188.251])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id DC2D0606A32F;
	Fri,  6 Nov 2026 20:29:41 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org DC2D0606A32F
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=oss.cyber.gouv.fr
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.cyber.gouv.fr
X-DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed;
	d=oss.cyber.gouv.fr; s=default; h=Content-Transfer-Encoding:Content-Type:
	MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:
	Reply-To:Sender:Content-ID:Content-Description:Resent-Date:Resent-From:
	Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID;
	bh=HrXkiiGdUBmwU/LbSqgOWqBj4+1gSdkVc3p2fHsXaTk=; b=YITxRy/HbXJm1Ad71+dJ1GnA7k
	FQwQtX8nd+8e8LMWhluvLtF/1NtD6J4SY1VHF5PzsyuWPiS+SGzEnjO6pbomf649Z49n/AjcsRsRF
	9Y6395JGcR94EskTCbhA+dsxZlLJyVRYmqFUTbTylILK4C96Ssej/8RWHdWFQR7HN7cDCe9gE/ofh
	QLVXJiNgSwFgtSJtIE0k0kPia2syppa//6J+2cJtwMsMpojKeLmPcSWNco6vGsonOmT7PaudJENgp
	SvIcrWNvyMuXk8owIrd9KIrOvUtWiPcLIkPK9J6/F2aBy/2pcPndZsWScKzaEA3OU4NSZjk4xS/NY
	+GCpgGhg==;
X-Received: from [151.115.150.205] (port=56674 helo=gepetto..)
	by pf-012.whm.fr-par.scw.cloud with esmtpsa  (TLS1.3) tls TLS_AES_256_GCM_SHA384
	(Exim 4.100.1)
	(envelope-from <Jeremy.Jean@oss.cyber.gouv.fr>)
	id 1xPQZD-00000001I6n-2K02;
	Fri, 06 Nov 2026 21:29:40 +0100
X-Cc: netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Jérémy Jean <Jeremy.Jean@oss.cyber.gouv.fr>,
	stable@vger.kernel.org
X-Mailer: git-send-email 2.47.3
X-In-Reply-To: <20261106202910.723098-2-Jeremy.Jean@oss.cyber.gouv.fr>
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list
X-AntiAbuse: This header was added to track abuse, please include it with any abuse report
X-AntiAbuse: Primary Hostname - pf-012.whm.fr-par.scw.cloud
X-AntiAbuse: Original Domain - vger.kernel.org
X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12]
X-AntiAbuse: Sender Address Domain - oss.cyber.gouv.fr
X-Get-Message-Sender-Via: pf-012.whm.fr-par.scw.cloud: authenticated_id: jeremy.jean@oss.cyber.gouv.fr
X-Authenticated-Sender: pf-012.whm.fr-par.scw.cloud: jeremy.jean@oss.cyber.gouv.fr