]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
xfrm: prevent policy_hthresh.work from racing with netns teardown
authorMinwoo Ra <raminwo0202@gmail.com>
Fri, 13 Mar 2026 15:58:44 +0000 (00:58 +0900)
committerSteffen Klassert <steffen.klassert@secunet.com>
Mon, 16 Mar 2026 09:58:21 +0000 (10:58 +0100)
A XFRM_MSG_NEWSPDINFO request can queue the per-net work item
policy_hthresh.work onto the system workqueue.

The queued callback, xfrm_hash_rebuild(), retrieves the enclosing
struct net via container_of(). If the net namespace is torn down
before that work runs, the associated struct net may already have
been freed, and xfrm_hash_rebuild() may then dereference stale memory.

xfrm_policy_fini() already flushes policy_hash_work during teardown,
but it does not synchronize policy_hthresh.work.

Synchronize policy_hthresh.work in xfrm_policy_fini() as well, so the
queued work cannot outlive the net namespace teardown and access a
freed struct net.

Fixes: 880a6fab8f6b ("xfrm: configure policy hash table thresholds by netlink")
Signed-off-by: Minwoo Ra <raminwo0202@gmail.com>
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
net/xfrm/xfrm_policy.c

index 66ac93e652647b92be51f10d776b83379d5cc2bb..2140ee7b102d20ce2d911dee595c05c52c4f157b 100644 (file)
@@ -4282,6 +4282,8 @@ static void xfrm_policy_fini(struct net *net)
        unsigned int sz;
        int dir;
 
+       disable_work_sync(&net->xfrm.policy_hthresh.work);
+
        flush_work(&net->xfrm.policy_hash_work);
 #ifdef CONFIG_XFRM_SUB_POLICY
        xfrm_policy_flush(net, XFRM_POLICY_TYPE_SUB, false);