Netdev List
 help / color / mirror / Atom feed
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>,
	Sabrina Dubroca <sd@queasysnail.net>,
	netdev@vger.kernel.org, ipsec@lists.linux.dev,
	linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH ipsec v3 1/2] xfrm: advance the route generation when policies are removed
Date: Thu,  3 Dec 2026 11:18:16 +0100	[thread overview]
Message-ID: <20261203101817.198835-1-ralf@mandelbit.com> (raw)
In-Reply-To: <273c02a9-4801-48f3-9341-2b115629d6a1@6wind.com>

On Thu, 03 Dec 2026 10:31:34 +0100, Nicolas Dichtel <nicolas.dichtel@6wind.com> wrote:
> Le 02/12/2026 à 09:52, 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, once after
> > all policies are unlinked by a flush, and after the replaced policy is
> > unlinked by an insert. xfrm_policy_delete also runs from the policy
> > timer, in softirq context, where the IPv6 bump, a walk of the FIB, would
> > run once for each expiring policy, so leave it to a work item, which
> > coalesces the expiries into one walk in process context. The IPv4 bump
> > is a plain atomic_inc, so order the unlink before it. 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>
>
> [snip]
>
> > @@ -2365,6 +2387,16 @@ int xfrm_policy_delete(struct xfrm_policy *pol, int dir)
> >  
> >  	spin_lock_bh(&net->xfrm.xfrm_policy_lock);
> >  	pol = __xfrm_policy_unlink(pol, dir);
> > +	/* The policy timer calls this in softirq context, so leave the IPv6
> > +	 * FIB walk to process context, once for all the policies that expire
> > +	 * together. Socket policies only apply to their own socket.
> > +	 */
> > +	if (pol && dir < XFRM_POLICY_MAX) {
> > +		if (pol->family == AF_INET)
> > +			xfrm_policy_bump_rt_genid(net, AF_INET);
> > +		else
> > +			schedule_work(&net->xfrm.policy_genid_ipv6_work);
> > +	}
> With this, an IPv6 socket can still send in plaintext after the policy is
> removed, until the work runs. This also applies to a hard XFRM_MSG_POLEXPIRE,
> which goes through xfrm_policy_delete() too. The window is probably short, and
> the selftest tolerates it, but given the nature of the bug, I think the commit
> log should mention it.
>

Right, I'll mention it in v4, together with the hard XFRM_MSG_POLEXPIRE
case. Thanks for the review!

-- 
Ralf Lici
Mandelbit Srl

  reply	other threads:[~2026-12-03 10:18 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02  8:52 [PATCH ipsec v3 0/2] xfrm: advance the route generation when policies are removed Ralf Lici
2026-12-02  8:52 ` [PATCH ipsec v3 1/2] " Ralf Lici
2026-12-03  9:31   ` Nicolas Dichtel
2026-12-03 10:18     ` Ralf Lici [this message]
2026-12-02  8:52 ` [PATCH ipsec v3 2/2] selftests: net: add a test for xfrm policy removal Ralf Lici
2026-12-03  9:40   ` Nicolas Dichtel

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=20261203101817.198835-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=sd@queasysnail.net \
    --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