From: Ralf Lici <ralf@mandelbit.com>
To: nicolas.dichtel@6wind.com
Cc: Steffen Klassert <steffen.klassert@secunet.com>,
Herbert Xu <herbert@gondor.apana.org.au>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@kernel.org>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Willem de Bruijn <willemb@google.com>,
Simon Horman <horms@kernel.org>, Shuah Khan <shuah@kernel.org>,
netdev@vger.kernel.org, ipsec@lists.linux.dev,
linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH ipsec v2 1/2] xfrm: advance the route generation when policies are removed
Date: Mon, 30 Nov 2026 17:51:02 +0100 [thread overview]
Message-ID: <20261130165103.526794-1-ralf@mandelbit.com> (raw)
In-Reply-To: <2027ff78-c342-4ab2-a289-c343f0c4a457@6wind.com>
On Mon, 30 Nov 2026 11:08:21 +0100, Nicolas Dichtel <nicolas.dichtel@6wind.com> wrote:
> Le 27/11/2026 à 17:48, Ralf Lici a écrit :> Only xfrm_policy_insert and
> xfrm_set_default advance the IPv4 and IPv6
> > route generations. Deleting, flushing or expiring a policy does not, so
> > a route that a socket cached while an allow policy without templates
> > matched its flow keeps validating after that policy is removed, and the
> > socket keeps sending in plaintext although a policy requiring IPsec now
> > matches. xfrm_policy_insert also advances the generation before
> > unlinking the policy that the new one replaces, which can still be
> > matched until then, since the new policy can be linked behind it.
> >
> > Advance the generation once a policy is unlinked by a delete or by its
> > expiry, once after all policies are unlinked by a flush, and after the
> > replaced policy is unlinked by an insert. Socket policies only apply to
> > their own socket and are left out.
> >
> > Fixes: ee8372dd1989 ("xfrm: invalidate dst on policy insertion/deletion")
> > Signed-off-by: Ralf Lici <ralf@mandelbit.com>
>
> Reviewed-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
>
Thanks Nicolas.
Sashiko raised three points on this patch [1]:
- The IPv6 cookie is still read after the policy lookup, so a lookup
that matched the allow policy before the unlink can store the new
serial. That is the late cookie sampling race in general, which the
writer side cannot close. "ipv6: validate cached dsts against the
netns route generation" [2] closes it by sampling the generation
before the lookup.
- rt_genid_bump_ipv4 is a plain atomic_inc, so the unlink is not
ordered before it on weakly ordered architectures. I'll add
smp_mb__before_atomic in v3.
- xfrm_policy_delete also runs from the policy timer, in softirq
context, and for IPv6 the bump is fib6_flush_trees, a walk of every
route. Policies that expire together would walk the FIB once each in a
single softirq, and both policies and routes only need CAP_NET_ADMIN
in the netns. [2] turns the IPv6 bump into a counter increment, but
that is net-next.
For the last one I see three options for net:
a) defer the bump in xfrm_policy_delete to a per-netns work item, like
policy_hash_work, so that expiries coalesce into one walk in process
context;
b) keep the bump synchronous, as in this version; or
c) leave expiry out of this fix.
The first option seems the right fix to me but let me know if you prefer
a more "minimalistic" approach for a bugfix commit.
[1] https://netdev-ai.bots.linux.dev/sashiko/#/patchset/cover.1795797791.git.ralf%40mandelbit.com
[2] https://lore.kernel.org/netdev/cover.1795642432.git.dahern@nvidia.com/
--
Ralf Lici
Mandelbit Srl
next prev parent reply other threads:[~2026-11-30 16:51 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-27 16:48 [PATCH ipsec v2 0/2] xfrm: advance the route generation when policies are removed Ralf Lici
2026-11-27 16:48 ` [PATCH ipsec v2 1/2] " Ralf Lici
2026-11-30 10:08 ` Nicolas Dichtel
2026-11-30 16:51 ` Ralf Lici [this message]
2026-11-27 16:48 ` [PATCH ipsec v2 2/2] selftests: net: add a test for xfrm policy removal Ralf Lici
2026-11-30 10:14 ` Nicolas Dichtel
2026-11-30 16:53 ` Ralf Lici
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=20261130165103.526794-1-ralf@mandelbit.com \
--to=ralf@mandelbit.com \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=herbert@gondor.apana.org.au \
--cc=horms@kernel.org \
--cc=ipsec@lists.linux.dev \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=nicolas.dichtel@6wind.com \
--cc=pabeni@redhat.com \
--cc=shuah@kernel.org \
--cc=steffen.klassert@secunet.com \
--cc=willemb@google.com \
/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