Article View: linux.kernel.netdev
Article #26185Re: [PATCH 11/22] xfrm: fix selector matching for IPv6 atomic fragments
From: Steffen Klassert
Date: Thu, 03 Dec 2026 07:15
Date: Thu, 03 Dec 2026 07:15
181 lines
16488 bytes
16488 bytes
Ccing the author of the patch.
On Wed, Dec 02, 2026 at 01:12:29PM +0000, netdev-bot+sashiko@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 2 potential
> issue(s) to consider.
>
> Critical: 0 · High: 1 · Medium: 0 · Low: 1
>
> 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).
>
> - [High] The fix leaves the same IPv6 policy miss open for some atomic
> fragments.
> - [Low] The patch rewrites the default-offset (*offset == 0) path of the
> exported helper ipv6_find_hdr() in net/ipv6/exthdrs_core.c, and the…
>
> --
>
> xfrm: fix selector matching for IPv6 atomic fragments
>
> This patch makes ipv6_find_hdr() set a new IP6_FH_F_NON_ATOMIC flag when
> it finds a Fragment header with a non-zero offset or MF set. In
> __xfrm_decode_session(), IPv6 packets that the flow dissector flagged as
> fragments are parsed again with ipv6_find_hdr(). If every Fragment
> header is atomic, FLOW_DIS_IS_FRAGMENT is cleared and the ports are
> restored, so decode_session6() fills in the selector fields.
>
> > diff --git a/net/ipv6/exthdrs_core.c b/net/ipv6/exthdrs_core.c
> > index 764c694fb417a..bf4253426c732 100644
> > --- a/net/ipv6/exthdrs_core.c
> > +++ b/net/ipv6/exthdrs_core.c
>
> [ ... ]
>
> > @@ -192,23 +193,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);
>
> [Severity: Low]
> This isn't a bug, but this hunk changes the default *offset == 0 path of
> the exported ipv6_find_hdr(). That affects all of its callers (netfilter
> ip6t/nft, IPVS, OVS, act_ct, act_pedit, seg6, BPF and several drivers),
> and the commit message doesn't mention it.
>
> The old code read ipv6_hdr(skb)->nexthdr directly. The new code goes
> through skb_header_pointer() and can now return -EBADMSG on this path
> when the packet is shorter than skb_network_offset(skb) plus
> sizeof(struct ipv6hdr).
>
> The commit message says:
>
> Read with skb_header_pointer() so decoding does not pull or
> reallocate the skb.
>
> The old ipv6_find_hdr() did not pull or reallocate the skb either, so
> this sentence doesn't seem to describe this change.
>
> Since this is tagged for stable, could the commit message mention the
> change to the shared helper?
>
> [ ... ]
>
> > diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
> > index 6baff3f797f8c..d2e938d4db9aa 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)) {
>
> [Severity: High]
> Can atomic fragments with many extension headers still miss a policy
> here?
>
> The flow dissector walks up to MAX_FLOW_DISSECT_HDRS (15) headers when it
> sets FLOW_DIS_IS_FRAGMENT, ip_proto and thoff. ipv6_find_hdr() gives up
> earlier, after IP6_MAX_EXT_HDRS_CNT (12):
>
> net/ipv6/exthdrs_core.c:ipv6_find_hdr() {
> ...
> if (unlikely(exthdr_cnt++ >= IP6_MAX_EXT_HDRS_CNT))
> return -EBADMSG;
> ...
> }
>
> Take a packet with 13 to 15 extension headers in which every Fragment
> header is atomic, followed by UDP, TCP, ICMPv6 or GRE. The dissector
> reaches L4, but ipv6_find_hdr() returns -EBADMSG. The >= 0 test fails,
> FLOW_DIS_IS_FRAGMENT stays set, and decode_session6() drops the ports,
> the ICMPv6 type/code and the GRE key.
Might happen because IPv6 does not limit the number of extension
headers, but this is a bit artificial. A packet with 13 to 15 extension
headers has other problems as well. Can be fixed as a followup.
>
> Local delivery seems to be covered, because ip6_protocol_deliver_rcu()
> drops packets with more than IP6_MAX_EXT_HDRS_CNT extension headers
> before the transport-level policy check. The forwarding path has no such
> limit:
>
> ip6_forward()
> xfrm6_policy_check(NULL, XFRM_POLICY_FWD, skb)
> __xfrm_decode_session()
> __skb_flow_dissect() <- reaches L4, sets FLOW_DIS_IS_FRAGMENT
> ipv6_find_hdr() <- returns -EBADMSG
> decode_session6() <- ports and type/code left zero
>
> The xfrm6_route_forward() call in ip6_forward() takes the same route.
>
> Could a remote sender then get plaintext past a port-specific or
> ICMPv6-type-specific FWD policy on a gateway? That is the "Plaintext can
> then miss a matching policy" case the commit message describes as fixed.
>
> The same packet without the Fragment header is decoded correctly, so
> this only affects the atomic-fragment form the patch targets. None of
> ipv6_find_hdr(), the flow dissector or this hunk appears to change after
> this commit.
>
> Would it be more robust to record the non-atomic fragment state during
> the walk the flow dissector already does, instead of parsing again with
> a helper that has a different header limit?
>
> > + 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;
>
> --
> Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261201124252.1163254-2-steffen.klassert%40secunet.com
Technical Details
Message-ID:
<axEXGf9BuBWH4IO8@gauss4>Path:
mbox-mo1.pugleaf.net!news-lon.pugleaf.net!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-376364-linux-kernel-netdev=dewy.ruReferences:
<20261201124252.1163254-12-steffen.klassert@secunet.com> <179621714961.3146.8801090367833323429@kernel.org>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lon.pugleaf.net!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-376364-linux-kernel-netdev=dewy.ru From: steffen.klassert@secunet.com (Steffen Klassert) Newsgroups: linux.kernel.netdev Subject: Re: [PATCH 11/22] xfrm: fix selector matching for IPv6 atomic fragments Date: Thu, 3 Dec 2026 08:15:37 +0100 Organization: Usenet Network Message-ID: <axEXGf9BuBWH4IO8@gauss4> References: <20261201124252.1163254-12-steffen.klassert@secunet.com> <179621714961.3146.8801090367833323429@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="2402583"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:lUSDMhuc7vlz7i4aTb6dfN3DYRA= sha256:+y8dBvXZxLeu3SFc6ZyG18OFghOboe/EoxnTGi07My8= sha1:F2azTNrK0s81RdIUEJfyOMcCo6M= sha256:8OmcNG4gUm6vMQvZl9RnkqzgASYxexBwpDNAuhbR418= Content-Disposition: inline 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 038C711741B; Thu, 3 Dec 2026 10:16:03 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.051 X-Spam-Status: No, score=-3.051 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, 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=secunet.com 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 RlcLfs_9DCTQ; Thu, 3 Dec 2026 10:15:59 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-376364-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=secunet.com X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10]) by mail.dewy.ru (Postfix) with ESMTPS id 8A47D11785C; Thu, 3 Dec 2026 10:15:50 +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 8D2B12D789; Thu, 3 Dec 2026 07:15:44 +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=1796282144; b=p2jlL/HdfW38EPVMzjdtj9oVXhugcxqJjqRVA6VyK5eF9DxWWa4QB+IJqhKrvUw4jUcz cBSxNOazGM1F1NaXwlHzaGngYfHKQiQLvHRQtEKv6qq/HjIQNVTaBRpFuCHTDQCERjzVK TyxGYUF63EHC5mVk6jYCwn042ID34sQ+mD44tjdmnTcqH+eodaYwEzViv0m3RUBwyz7cS QbgDwyLq2KDVhEFlaru9qHsvVkkKVEt4BGOMMoeF4MEtPnEDErE7MSn0MNQnx32oHsRWc bBzdCOaF2dTwNB0OCK9+ZtYK881yul8zOcuBDyu/0Nv0smXHeGcQC6UEGTikGdm2W1g== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796282144; h=X-Original-To:Received:DMARC-Filter:Received:X-Virus-Scanned: Received:Received:DKIM-Filter:DKIM-Signature:Received:Received:Date: From:To:CC:Subject:Message-ID:References:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version:Content-Type:Content-Disposition: Content-Transfer-Encoding:In-Reply-To:X-ClientProxiedBy; bh=zKEdVZzz53CEHQ+O7LysnrqnXVFrHyZLYbT1V2U/XLs=; b=wzVNq37+7HxVE1uaRTewfnX5sIY+hva1TKI1/dLbnq2lCIKaNM6iUiBS/mFNLKq8Ae6g GiPDgWEO4gIa90OYa9Jr5aFXiSmWFR/J6/SgZVYuAhjSGA7rrfHJCDQ8oXc9vQpBGPuou nwuhrcRt+InMdiQoDeEj+0s/u6vbQ0ry3I7oBAcWY5NP750ELkznakeDrX66JotXVWueT +4kYuZbVN1pVuSoYL/Q7KA0Cx1aD/TEDkfnBZ1QYIUbaDB+uogvrZYP0hbEszY9BLwFZP 4BomfOHvs8z8DHGYm0mxui6LFIGyCdNoPw/ZwJfJPaZn6/YUXFAmGOe/51B0dJ8R+/w== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=secunet.com header.i=@secunet.com header.a=rsa-sha256 header.s=202301 header.b=eJqMCuiV; dmarc=pass header.from=secunet.com; spf=pass smtp.mailfrom=secunet.com; 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 65285606A336; Thu, 3 Dec 2026 07:15:44 +0000 (UTC) X-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=eJqMCuiV X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=62.96.220.36 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796282143; b=lXNSj+2CyIxzEC8uf70E9WLGrfwWP+R76m1+oPZuiwKU+Ai6OCPUqY1Nfjhtwwvj3suC qI/yq34f2LDg4DETTmH68hB8KQu+83iiIUFHoOLl5JZzK+dkpXh4jB5lr0JhuJxaESR0i Lo8trEOHxzeOqbvQTgfyHXEaF6bzKelMQwH/CxMXl+TCeq23TWhc/9JdL6WWP4avw0qTe kdT6cyDTUWVHAEU0C2fDNGuforxnYDXvvGb2Ol8wpVo1qO1l+kZioFm8eYevNmo2+se/p ueeswKqvo3PmXSPn6KD5gty71Z755LR0YdB2dx9UdedXkiQHzEYaK9orJLI6Q3JaOyw== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796282143; h=DMARC-Filter:Received:X-Virus-Scanned:Received:Received:DKIM-Filter: DKIM-Signature:Received:Received:Date:From:To:CC:Subject:Message-ID: References:MIME-Version:Content-Type:Content-Disposition: Content-Transfer-Encoding:In-Reply-To:X-ClientProxiedBy; bh=zKEdVZzz53CEHQ+O7LysnrqnXVFrHyZLYbT1V2U/XLs=; b=SJN2O1ifxobxLgEqqavLq8zdlwH1sPDwrSllwIiJVO4gMcZ2L59T5Xn1f2VZnzNqqbNS qBzonnPUFx+mA+iiUOl80VHSFjVFpTRRovRw8R52pMisfIs1EqsYD6ahZzCFy2qS9klpb Ah62V2vL8Dr8iNcm2UphDYwoYAsnadDFB4N9xpbgLi9vFeoRjup1D7Kt97WvzAvr62wQF 60cNgnGwVw2jmkHJw570wtKhlmuhUFSZk/siFp/zc2JIPXa01AHx96oCQEVYWW5m53pTV 2GEClITJ+0VJ7jiv3iC3oc4zmGTXeAQYWyokxyEtaPejGQyJiE619urkUbylPmwnj+w== X-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=eJqMCuiV; arc=none smtp.remote-ip=62.96.220.36 X-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 C13AA606A322 for <netdev@vger.kernel.org>; Thu, 3 Dec 2026 07:15:42 +0000 (UTC) X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org C13AA606A322 X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=secunet.com X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=secunet.com X-Received: from localhost (localhost [127.0.0.1]) by mx1.secunet.com (Postfix) with ESMTP id D7B71207E4; Thu, 3 Dec 2026 08:15:40 +0100 (CET) X-Virus-Scanned: by secunet X-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 IetmcqDUJWD9; Thu, 3 Dec 2026 08:15:39 +0100 (CET) X-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 A2FEE207C6; Thu, 3 Dec 2026 08:15:39 +0100 (CET) X-DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.secunet.com A2FEE207C6 X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=secunet.com; s=202301; t=1796282139; bh=zKEdVZzz53CEHQ+O7LysnrqnXVFrHyZLYbT1V2U/XLs=; h=Date:From:To:CC:Subject:References:In-Reply-To:From; b=eJqMCuiVEBNz4iaJ0b3dpgmfNmmUV0t1bWh9KMTXw7pruDId1rQ5yvVZpjNFtP4pj d9wBODvgcMQT74RuGI5H23YImaKw9TCTs4XpwE4oEjXivC1r3QF7p4lhK5TEE27jl0 zhCIBes1T/cusNAdEjYugC3mXLpkuFGp3otQfpooeZ5fQ9biEPlGOo+b9Jmx/1PU2R T01eQEsQMWXvV1vsBqffRHPR0Y6gaM4A2VuQ9SZ6gQ4u2wbGn8xUr2sS9C5BRfj/wG er1Du5R64GEpEkxWFCmH+nPkgHO7Hv+0QxQuGxzatt72VysSsWZKICcxOb/IFBMr85 8J1k436Lk1/Qg== X-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; Thu, 3 Dec 2026 08:15:38 +0100 X-Received: (nullmailer pid 1016990 invoked by uid 1000); Thu, 03 Dec 2026 07:15:37 -0000 X-CC: <davem@davemloft.net>, <kuba@kernel.org>, <herbert@gondor.apana.org.au>, <netdev@vger.kernel.org>, Jérémy Jean <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-In-Reply-To: <179621714961.3146.8801090367833323429@kernel.org> X-ClientProxiedBy: EXCH-04.secunet.de (10.32.0.184) To EXCH-01.secunet.de (10.32.0.171)