From: Shardul Bankar <shar…@mpiricsoftware.com> commit 60a25ef8dacb3566b1a8c4de00572a498e2a3bf9 upstream. wg_netns_pre_exit() manually acquires rtnl_lock() inside the pernet .pre_exit callback. This causes a hung task when another thread holds rtnl_mutex - the cleanup_net workqueue (or the setup_net failure rollback path) blocks indefinitely in wg_netns_pre_exit() waiting to acquire the lock. Convert to .exit_rtnl, introduced in commit 7a60d91c690b ("net: Add ->exit_rtnl() hook to struct pernet_operations."), where the framework already holds RTNL and batches all callbacks under a single rtnl_lock()/rtnl_unlock() pair, eliminating the contention window. The rcu_assign_pointer(wg->creating_net, NULL) is safe to move from .pre_exit to .exit_rtnl (which runs after synchronize_rcu()) because all RCU readers of creating_net either use maybe_get_net() - which returns NULL for a dying namespace with zero refcount - or access net->user_ns which remains valid throughout the entire ops_undo_list sequence. Reported-by: syzb…@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?id=cb64c22a492202ca929e18262fdb8cb89e635c70 Signed-off-by: Shardul Bankar <shar…@mpiricsoftware.com> [ Jason: added __net_exit and __read_mostly annotations that were missing. ] Fixes: 900575aa33a3 ("wireguard: device: avoid circular netns references") Cc: stab…@vger.kernel.org Signed-off-by: Jason A. Donenfeld <Jas…@zx2c4.com> Link: https://patch.msgid.link/2026…@zx2c4.com Signed-off-by: Jakub Kicinski <ku…@kernel.org> [ adapted to 6.6.y: use the existing exit_batch_rtnl hook ] Signed-off-by: Dickson Wu <dick…@certik.com> --- 6.12.y and 6.18.y already have this fix. 6.6.y has no exit_rtnl pernet hook, so the cleanup runs from the existing exit_batch_rtnl hook, which also runs after synchronize_rcu() with RTNL held, once per namespace in the batch. Tested on v6.6.163: - x86_64 W=1 build of drivers/net/wireguard/device.o, base vs patched, no new warnings - booted base and patched kernels under QEMU/KVM: the WireGuard built-in self-tests pass, and tracing shows the new hook running from cleanup_net() when a namespace that created a WireGuard device exits. I didn't run tools/testing/selftests/wireguard/ netns.sh, and I don't have a reproducer for the RTNL hang itself. The backport and the test runs were prepared with AI coding tools (OpenAI Codex agents, with review by Claude). I went over the result before signing off. --- drivers/net/wireguard/device.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/drivers/net/wireguard/device.c b/drivers/net/wireguard/device.c index deb9636b0ecf..8e259385258d 100644 --- a/drivers/net/wireguard/device.c +++ b/drivers/net/wireguard/device.c @@ -413,12 +413,11 @@ static struct rtnl_link_ops link_ops __read_mostly = { .newlink = wg_newlink, }; -static void wg_netns_pre_exit(struct net *net) +static void __net_exit wg_netns_exit_rtnl(struct net *net) { struct wg_device *wg; struct wg_peer *peer; - rtnl_lock(); list_for_each_entry(wg, &device_list, device_list) { if (rcu_access_pointer(wg->creating_net) == net) { pr_debug("%s: Creating namespace exiting\n", wg->dev->name); @@ -431,11 +430,19 @@ static void wg_netns_pre_exit(struct net *net) mutex_unlock(&wg->device_update_lock); } } - rtnl_unlock(); } -static struct pernet_operations pernet_ops = { - .pre_exit = wg_netns_pre_exit +static void __net_exit wg_netns_exit_batch_rtnl(struct list_head *net_exit_list, + struct list_head *dev_kill_list) +{ + struct net *net; + + list_for_each_entry(net, net_exit_list, exit_list) + wg_netns_exit_rtnl(net); +} + +static struct pernet_operations pernet_ops __read_mostly = { + .exit_batch_rtnl = wg_netns_exit_batch_rtnl }; int __init wg_device_init(void) --- base-commit: e2bb30811e063ce0db964484357973b855b06572 change-id: 20261204-wg-exitrtnl-66-6ea200bfb4b2 Best regards, -- Dickson Wu <dick…@certik.com>