]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
xfrm: Wait for RCU readers during policy netns exit
authorSteffen Klassert <steffen.klassert@secunet.com>
Thu, 2 Apr 2026 11:31:04 +0000 (13:31 +0200)
committerSteffen Klassert <steffen.klassert@secunet.com>
Tue, 7 Apr 2026 08:12:40 +0000 (10:12 +0200)
xfrm_policy_fini() frees the policy_bydst hash tables after flushing the
policy work items and deleting all policies, but it does not wait for
concurrent RCU readers to leave their read-side critical sections first.

The policy_bydst tables are published via rcu_assign_pointer() and are
looked up through rcu_dereference_check(), so netns teardown must also
wait for an RCU grace period before freeing the table memory.

Fix this by adding synchronize_rcu() before freeing the policy hash tables.

Fixes: e1e551bc5630 ("xfrm: policy: prepare policy_bydst hash for rcu lookups")
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
Reviewed-by: Florian Westphal <fw@strlen.de>
net/xfrm/xfrm_policy.c

index 362939aa56cfb7f7a8d27776d0e81c6ac47ed82a..8f0188e763c778da68623da42c9e39da1037fb09 100644 (file)
@@ -4290,6 +4290,8 @@ static void xfrm_policy_fini(struct net *net)
 #endif
        xfrm_policy_flush(net, XFRM_POLICY_TYPE_MAIN, false);
 
+       synchronize_rcu();
+
        WARN_ON(!list_empty(&net->xfrm.policy_all));
 
        for (dir = 0; dir < XFRM_POLICY_MAX; dir++) {