Re: [PATCH ipsec v3 1/2] xfrm: advance the route generation when policies are removed

From: Nicolas Dichtel

Date: Thu Dec 03 2026 - 04:31:51 EST


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@xxxxxxxxxxxxx>

[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.

Regards,
Nicolas