Netdev List
 help / color / mirror / Atom feed
From: Steffen Klassert <steffen.klassert@secunet.com>
To: <netdev-bot+sashiko@kernel.org>
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>
Subject: Re: [PATCH 11/22] xfrm: fix selector matching for IPv6 atomic fragments
Date: Thu, 3 Dec 2026 08:15:37 +0100	[thread overview]
Message-ID: <axEXGf9BuBWH4IO8@gauss4> (raw)
In-Reply-To: <179621714961.3146.8801090367833323429@kernel.org>

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

  reply	other threads:[~2026-12-03  7:15 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01 12:41 [PATCH 0/22] pull request (net): ipsec 2026-12-01 Steffen Klassert
2026-12-01 12:41 ` [PATCH 01/22] xfrm: ipcomp: account full fragment pages in truesize Steffen Klassert
2026-12-01 13:36   ` bot+bpf-ci
2026-12-01 12:41 ` [PATCH 02/22] xfrm: esp: reset outer TCP GSO metadata on espintcp input Steffen Klassert
2026-12-01 12:41 ` [PATCH 03/22] xfrm: keep the mode module pinned until destroy_state returns Steffen Klassert
2026-12-01 12:41 ` [PATCH 04/22] xfrm: serialize SA activation with state deletion Steffen Klassert
2026-12-01 12:41 ` [PATCH 05/22] xfrm: keep old state references until migration deletion completes Steffen Klassert
2026-12-01 12:41 ` [PATCH 06/22] xfrm: hold migrated states through rollback Steffen Klassert
2026-12-01 12:41 ` [PATCH 07/22] xfrm: check inner family via skb_dst for small_ipv6 DF clearing Steffen Klassert
2026-12-02 13:12   ` netdev-bot+sashiko
2026-12-03  6:58     ` Steffen Klassert
2026-12-01 12:41 ` [PATCH 08/22] xfrm: account XFRMA_MARK in xfrm_sa_len() Steffen Klassert
2026-12-01 12:41 ` [PATCH 09/22] xfrm: replay: Fix late packet handling with ESN crypto offload Steffen Klassert
2026-12-02 13:12   ` netdev-bot+sashiko
2026-12-03  7:08     ` Steffen Klassert
2026-12-01 12:41 ` [PATCH 10/22] xfrm: fix IPv6 first-fragment protocol decode Steffen Klassert
2026-12-02 13:12   ` netdev-bot+sashiko
2026-12-01 12:41 ` [PATCH 11/22] xfrm: fix selector matching for IPv6 atomic fragments Steffen Klassert
2026-12-02 13:12   ` netdev-bot+sashiko
2026-12-03  7:15     ` Steffen Klassert [this message]
2026-12-01 12:41 ` [PATCH 12/22] xfrm: espintcp: read the socket error queue for MSG_ERRQUEUE Steffen Klassert
2026-12-01 12:41 ` [PATCH 13/22] xfrm: iptfs: force a dst reference before queueing an skb Steffen Klassert
2026-12-01 13:36   ` bot+bpf-ci
2026-12-01 12:41 ` [PATCH 14/22] xfrm: espintcp: select receive path by skb protocol Steffen Klassert
2026-12-01 12:41 ` [PATCH 15/22] net: xfrm: interface: restore dst_orig on every xfrm interface Steffen Klassert
2026-12-02 13:12   ` netdev-bot+sashiko
2026-12-01 12:41 ` [PATCH 16/22] xfrm: iptfs: make room before copying a continuation in reassembly Steffen Klassert
2026-12-01 12:41 ` [PATCH 17/22] xfrm/compat: pass on the translated length of a socket policy Steffen Klassert
2026-12-01 12:41 ` [PATCH 18/22] xfrm: Give GC list nodes their own storage Steffen Klassert
2026-12-02 13:12   ` netdev-bot+sashiko
2026-12-01 12:41 ` [PATCH 19/22] xfrm: Serialize device state teardown Steffen Klassert
2026-12-02 13:12   ` netdev-bot+sashiko
2026-12-03  7:24     ` Steffen Klassert
2026-12-01 12:41 ` [PATCH 20/22] xfrm: Wait for an RCU grace period before freeing device state Steffen Klassert
2026-12-02 13:12   ` netdev-bot+sashiko
2026-12-01 12:41 ` [PATCH 21/22] Revert "xfrm: serialize state GC with device state flush" Steffen Klassert
2026-12-02 13:12   ` netdev-bot+sashiko
2026-12-01 12:41 ` [PATCH 22/22] xfrm: Serialize offload stats updates with x->lock Steffen Klassert
2026-12-02 16:06 ` [PATCH 0/22] pull request (net): ipsec 2026-12-01 Paolo Abeni

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=axEXGf9BuBWH4IO8@gauss4 \
    --to=steffen.klassert@secunet.com \
    --cc=Jeremy.Jean@oss.cyber.gouv.fr \
    --cc=davem@davemloft.net \
    --cc=herbert@gondor.apana.org.au \
    --cc=kuba@kernel.org \
    --cc=netdev-bot+sashiko@kernel.org \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox