Skip to content

Commit 29fe3a6

Browse files
Minwoo Raklassert
authored andcommitted
xfrm: prevent policy_hthresh.work from racing with netns teardown
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: 880a6fa ("xfrm: configure policy hash table thresholds by netlink") Signed-off-by: Minwoo Ra <[email protected]> Signed-off-by: Steffen Klassert <[email protected]>
1 parent daf8e3b commit 29fe3a6

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

net/xfrm/xfrm_policy.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4282,6 +4282,8 @@ static void xfrm_policy_fini(struct net *net)
42824282
unsigned int sz;
42834283
int dir;
42844284

4285+
disable_work_sync(&net->xfrm.policy_hthresh.work);
4286+
42854287
flush_work(&net->xfrm.policy_hash_work);
42864288
#ifdef CONFIG_XFRM_SUB_POLICY
42874289
xfrm_policy_flush(net, XFRM_POLICY_TYPE_SUB, false);

0 commit comments

Comments
 (0)