🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #9982

Re: [PATCH net] xfrm: fix IPv6 first-fragment protocol decode

#9982
From: netdev-bot+sashiko
Date: Mon, 02 Nov 2026 23:09
184 lines
14808 bytes
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.

Critical: 0 · High: 0 (1) · Medium: 1 · 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).

- [Medium] After this patch, decode_session6() stays compatible with the
  old decoder's fragment behaviour only when the built-in C flow…

Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but it is an IPsec
  policy bypass on the same code path.

--

xfrm: fix IPv6 first-fragment protocol decode

For AF_INET6, this commit makes __xfrm_decode_session() pass
FLOW_DISSECTOR_F_PARSE_1ST_FRAG, so the flow dissector walks past an
IPv6 Fragment header to the real upper-layer protocol. It also changes
decode_session6() so the GRE key and ICMPv6 type/code are only set when
FLOW_DIS_IS_FRAGMENT is clear, which matches the old decoder.

> diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
> index 9ea60c7717ff8..c9c2370b07cc1 100644
> --- a/net/xfrm/xfrm_policy.c
> +++ b/net/xfrm/xfrm_policy.c
> @@ -3489,14 +3489,16 @@ decode_session6(const struct xfrm_flow_keys *flkeys, struct flowi *fl, bool reve
>  		fl6->fl6_dport = flkeys->ports.dst;
>  	}
>  
> -	switch (flkeys->basic.ip_proto) {
> -	case IPPROTO_GRE:
> -		fl6->fl6_gre_key = flkeys->gre.keyid;
> -		break;
> -	case IPPROTO_ICMPV6:
> -		fl6->fl6_icmp_type = flkeys->icmp.type;
> -		fl6->fl6_icmp_code = flkeys->icmp.code;
> -		break;
> +	if (!(flkeys->control.flags & FLOW_DIS_IS_FRAGMENT)) {
> +		switch (flkeys->basic.ip_proto) {
> +		case IPPROTO_GRE:
> +			fl6->fl6_gre_key = flkeys->gre.keyid;
> +			break;
> +		case IPPROTO_ICMPV6:
> +			fl6->fl6_icmp_type = flkeys->icmp.type;
> +			fl6->fl6_icmp_code = flkeys->icmp.code;
> +			break;
> +		}
>  	}

[Severity: High]
This is a pre-existing issue, not one introduced by this patch, but it is
on the same path. This path now finds the real L4 protocol for IPv6
atomic fragments (offset 0, M=0). Could the ports and ICMPv6 type/code be
recovered as well?

An atomic fragment is a complete datagram. ipv6_frag_rcv() only moves the
transport header past the Fragment header and returns 1:

net/ipv6/reassembly.c:ipv6_frag_rcv() {
    ...
	if (!(fhdr->frag_off & htons(IP6_OFFSET | IP6_MF))) {
		/* It is not a fragmented frame */
		skb->transport_header += sizeof(struct frag_hdr);
		...
		return 1;
    ...
}

After that, udpv6_rcv()/tcp_v6_rcv() -> xfrm6_policy_check() ->
__xfrm_decode_session() -> __skb_flow_dissect() dissects the packet again
from the network header. With PARSE_1ST_FRAG, ip_proto is now correct.
The ports are still skipped, though:

net/core/flow_dissector.c:__skb_flow_dissect() {
    ...
	if (!(key_control->flags & FLOW_DIS_IS_FRAGMENT))
		__skb_flow_dissect_ports(skb, flow_dissector, target_container,
					 data, nhoff, ip_proto, hlen);
    ...
}

So flkeys.ports keeps its memset value of zero, and decode_session6()
copies zeros into fl6_sport/fl6_dport. The new gate above also leaves the
ICMPv6 type/code and the GRE key unset. The ICMPv6 type/code share storage
with the port fields that xfrm_flowi_sport()/xfrm_flowi_dport() read.

As a result, __xfrm6_selector_match() can never match a selector scoped by
port, ICMPv6 type or GRE key:

	!((xfrm_flowi_dport(fl, &fl6->uli) ^ sel->dport) & sel->dport_mask) &&

Take an inbound "proto udp dport 1701, tmpl ESP level required" policy,
with no broader policy covering that traffic and a default inbound policy
of accept. __xfrm_policy_check() then takes its !pol branch and returns 1.
Could a remote sender put plaintext UDP or TCP inside an atomic Fragment
header and have it delivered to the socket that policy is meant to
protect?

The old open-coded decoder behaved the same way (NEXTHDR_FRAGMENT set
onlyproto = 1), and the commit message keeps this on purpose. For atomic
fragments (FLOW_DIS_FIRST_FRAG with M=0), the ports are as reliable as
the protocol. Would it make sense to handle that case here?

>  
>  	fl6->flowi6_proto = flkeys->basic.ip_proto;
> @@ -3507,10 +3509,13 @@ int __xfrm_decode_session(struct net *net, struct sk_buff *skb, struct flowi *fl
>  			  unsigned int family, int reverse)
>  {
>  	struct xfrm_flow_keys flkeys;
> +	unsigned int flags = FLOW_DISSECTOR_F_STOP_AT_ENCAP;
>  
>  	memset(&flkeys, 0, sizeof(flkeys));
> +	if (family == AF_INET6)
> +		flags |= FLOW_DISSECTOR_F_PARSE_1ST_FRAG;
>  	__skb_flow_dissect(net, skb, &xfrm_session_dissector, &flkeys,
> -			   NULL, 0, 0, 0, FLOW_DISSECTOR_F_STOP_AT_ENCAP);
> +			   NULL, 0, 0, 0, flags);

[Severity: Medium]
Is the old fragment behaviour still kept when a BPF flow dissector is
attached?

decode_session6() copies flkeys->ports into fl6_sport/fl6_dport for every
packet. Only the GRE/ICMPv6 fields check FLOW_DIS_IS_FRAGMENT. Fragments
get zero ports only because the C dissector skips
__skb_flow_dissect_ports() when FLOW_DIS_IS_FRAGMENT is set.

When a BPF_PROG_TYPE_FLOW_DISSECTOR program is attached to init_net or to
the netns, __skb_flow_dissect() runs it instead of the C code.
bpf_flow_dissect() passes the new flag through unchanged:

net/core/flow_dissector.c:bpf_flow_dissect() {
    ...
	flow_keys->flags = flags;
    ...
}

The in-tree reference program, PROG(IPV6FR) in
tools/testing/selftests/bpf/progs/bpf_flow.c, keeps parsing first
fragments when PARSE_1ST_FRAG is set:

	return parse_ipv6_proto(skb, fragh->nexthdr);

That fills in sport/dport. __skb_flow_bpf_to_target() then copies them
into FLOW_DISSECTOR_KEY_PORTS without any fragment check:

		key_ports->src = flow_keys->sport;
		key_ports->dst = flow_keys->dport;

So with a BPF dissector, IPv6 first fragments now reach the XFRM policy
lookup with real ports. Later fragments of the same datagram get zero
ports, and so does every fragment under the C dissector.

The forward path checks fragments one at a time:
ip6_forward() -> xfrm6_policy_check(XFRM_POLICY_FWD), then
xfrm6_route_forward(). Could a port-scoped selector match the first
fragment but not the rest, giving fragments of one datagram different
policy and routing decisions?

Before this patch PARSE_1ST_FRAG was never passed, so both dissectors
stopped at the Fragment header. That conflicts with this part of the
commit message:

  "Keep GRE and ICMPv6 selector fields unset for fragmented packets,
   matching the old decoder's behavior."

Would putting the port assignment in decode_session6() under the same
FLOW_DIS_IS_FRAGMENT check used for GRE/ICMPv6 remove this dependency on
the dissector?

>  
>  	switch (family) {
>  	case AF_INET:

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261101230745.2043474-2-Jeremy.Jean%40oss.cyber.gouv.fr
Technical Details
Message-ID: <179366096529.3131.16773351906482343613@kernel.org>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-355096-linux-kernel-netdev=dewy.ru
References: <20261101230745.2043474-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-355096-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net] xfrm: fix IPv6 first-fragment protocol decode
Date: Mon, 02 Nov 2026 23:09:25 +0000
Organization: Usenet Network
Message-ID: <179366096529.3131.16773351906482343613@kernel.org>
References: <20261101230745.2043474-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="3052710"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:J76Ou/5WGnCOhv2wTHh9n6DaN80= sha256:IaYy6N6ICtb5dFZsV7gGWtERqq6KkzxyOL5pC5z2byI=
	sha1:RwdQUiRMrvs3QkEP+RRp+oJezuA= sha256:LvPmh1N/WzoM1uX74ULQMvejwpm1BW2ic2vHP6bujfc=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 82BEC1126CD; Tue,  3 Nov 2026 02:10:24 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.4
X-Spam-Status: No, score=-3.4 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, DKIM_VALID_EF=-0.1,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
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 u7kI86iRhhmW;
	Tue,  3 Nov 2026 02:10:20 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-355096-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
	by mail.dewy.ru (Postfix) with ESMTPS id 062D71126CB; Tue,  3 Nov 2026 02:10:11 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by tor.lore.kernel.org (Postfix) with ESMTP id 5EAAD2AA83; Mon,  2 Nov 2026 23:09:39 +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=1793660977;
	b=NDSrkq/1XWPL+66fFpDFgWbB/xY94qlyo0IEpxWivAfrYQ/yvXhN9XxI8APh100LQkeA
	 TwpJmD63jbQMduPhPO3Fc5xPQZgM7iCIyFzJ5160tMOLv4XNFlW47ZDIG7+IF2eX4vVBN
	 +y38DBAIC/R4fmUydlt8P67B9J9Uzh7NzaAtvJI5rp4bPZE5Qe3lpCMb4AX08qRY8H5Mg
	 ny/HR7hYaQpF9n/nhvXFkwAqAaI+hTkeEOFTOIqCeXDmWQgJc4iLc5h/k3gnzEyYmFfs9
	 K8GTnudPCvCZHK4PyMoPYQvX5RjZflaImkNzGcWBciy4KlpM8wXu1oot5wtMzXgNtbw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793660977;
	h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc:
	 Date:Message-ID:In-Reply-To:References:X-sashiko-severity:
	 Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version;
	bh=RfIi8e/km/yTMqBDj5BNJrvMDAONuazl+6BSjcWIbRI=;
	b=OKFd+CtdbZ1+wPmD9NKT8DZ94xbGEt+nKr1xQRLKEc2/U5A3jYNbK5dpPBrg2vtXyh61
	 zmRiFK8ReJYmxx5Mkc9xS3YWuen4JNHnZn7HB/gMTn3knXCjSr+bF8kVLJfPLAN61n7Dt
	 y6ibqkw/7Jw0jtEb21qK9kirBSWyQ3wyYFWixDAGyi+KMKVxK7No62mO7Weov4oxdSvTH
	 3vWYGMsVxbhpJWCPrauOsgWF45G/xibEka7cgUjlAssGChElgiQxjGvXO0kIjF7iPrPnj
	 1mIQDRmojWrKuxchKnptJJyoehQEtYfMfLLLVp5kqZmfehUhlRONM4DZ9vDuEM0mnRA==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=GtNk3ZMJ;
	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 7C446606A326;
	Mon,  2 Nov 2026 23:09:37 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=GtNk3ZMJ
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1793660966;
	b=VOJ7WtTej0sRT3uTzNxME0KzP/4axNrYFl6AzpCedwhqfNtYQ4zTgniAq8cQlvsb6EiV
	 EyU0JcznK7SWM25TrS9PfVuNkS6URHuqIPXqTlG5nSaKj2JPD4bndmYuX468BIcH6AjuF
	 X9BULOF39nnLUE1w0GdauDcikf3qsutGc3r7VXSxEYrKgAKCq5/FnyvpOBfyGsKe9u5SL
	 KOAcLSaj3hSpOco7Mz7x/rjpzKiVed2F/v8Ki+dvBhqpWlsfTna0CxH/5TNH4eEvdY2y/
	 Kk3D7SVtFkLNzIfLGOqYtrHqsVykSX3XRpbeeOrESo8KTMYOHQRcGU9YOcpHN/e/CMg==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793660966;
	h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID:
	 In-Reply-To:References:X-sashiko-severity:Content-Type:
	 Content-Transfer-Encoding:MIME-Version;
	bh=RfIi8e/km/yTMqBDj5BNJrvMDAONuazl+6BSjcWIbRI=;
	b=kwu2VFBy0askTt4Cufw+Gg7zaPqoQgUqCDYgCRd6iF8TpywYU25Vta8Xfv0DZgv4xR4f
	 UFfhHetsxxDOC8J910KnOWN9PjvAs/34al52nb5rBxOORbaChQri0+E9hyIhZIOLPvJGD
	 aDOaghekPl+pmrZO9MlnmQfT8AeglGyP4Z2zF9ZDBJX3xaNVCnnL2rFVr6cKcVWm1GKj1
	 dDmcLpGe2+SW7lKVtAo1H5ei+KkslzqNflMyEAAwZEkakx11mWvWU2NIrV/1nqL/lKGxD
	 R3kDA8APmH61RuODFFU3axR88HIvFastuZR+3fVhdNCKgxK0sOhaEaG2VJB5gkZ4ycQ==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=GtNk3ZMJ;
	arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 52AB1606A324;
	Mon,  2 Nov 2026 23:09:26 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id BF9D31F00A17;
	Mon,  2 Nov 2026 23:09:25 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1793660966;
	bh=RfIi8e/km/yTMqBDj5BNJrvMDAONuazl+6BSjcWIbRI=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=GtNk3ZMJOF9f7TWz3ZWYjuU12IriyRO0lKLjVq+cRwhGjTk0TLKG4XDs4nZRPPTEY
	 BV5rV43ArkF4rFvpQl7z4RYsdiWAZQhivmz+2uyeB0QCZXCYLE+H8MDvMBUYdjbjCW
	 ERoPFs4hOlVks3qbIR98ULsCqyhFsW/95cTytVTktghwOz8oNTxl+KRN9oEWOEoPnl
	 kFHkNMXwujVZfrsSHhhoPxMnrUGPHEebIfXJPlo1d+wQ7JOK9dir07isJ15NVDkFgO
	 pnH22AtizzXySuTRAt8LEP95DDppfGnbfAC0nlk8R5IQPrIYwoqtLqegQvCqUcmlGT
	 2Fk+puIWDrvNA==
X-Cc: steffen.klassert@secunet.com, herbert@gondor.apana.org.au,
 davem@davemloft.net, netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
 stable@vger.kernel.org, kuba@kernel.org
X-In-Reply-To: <20261101230745.2043474-2-Jeremy.Jean@oss.cyber.gouv.fr>
X-sashiko-severity: Medium
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