On Mon, 30 Nov 2026 11:08:21 +0100, Nicolas Dichtel <nico…@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 <ra…@mandelbit.com>
> > Reviewed-by: Nicolas Dichtel <nico…@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/cove…%40mandelbit.com [2] https://lore.kernel.org/netdev/cove…@nvidia.com/
-- Ralf Lici Mandelbit Srl