* [PATCH net] xfrm: prevent policy_hthresh.work from racing with netns teardown
@ 2026-03-13 15:58 Minwoo Ra
2026-03-17 10:41 ` Steffen Klassert
0 siblings, 1 reply; 2+ messages in thread
From: Minwoo Ra @ 2026-03-13 15:58 UTC (permalink / raw)
To: netdev
Cc: Steffen Klassert, Herbert Xu, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Simon Horman, Christophe Gouault,
Minwoo Ra
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>
---
net/xfrm/xfrm_policy.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
index 9e1a522ab1c5..6f0097cf28b3 100644
--- a/net/xfrm/xfrm_policy.c
+++ b/net/xfrm/xfrm_policy.c
@@ -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);
base-commit: 99600f79b28c83c68bae199a3d8e95049a758308
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH net] xfrm: prevent policy_hthresh.work from racing with netns teardown
2026-03-13 15:58 [PATCH net] xfrm: prevent policy_hthresh.work from racing with netns teardown Minwoo Ra
@ 2026-03-17 10:41 ` Steffen Klassert
0 siblings, 0 replies; 2+ messages in thread
From: Steffen Klassert @ 2026-03-17 10:41 UTC (permalink / raw)
To: Minwoo Ra
Cc: netdev, Herbert Xu, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Simon Horman, Christophe Gouault
On Sat, Mar 14, 2026 at 12:58:44AM +0900, Minwoo Ra wrote:
> 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>
Patch applied, thanks a lot!
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-03-17 10:41 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-13 15:58 [PATCH net] xfrm: prevent policy_hthresh.work from racing with netns teardown Minwoo Ra
2026-03-17 10:41 ` Steffen Klassert
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox