ieee80211_unregister_hw() removes the interfaces and drops the RTNL long before wiphy_unregister() marks the wiphy unregistered. In between, NL80211_CMD_NEW_INTERFACE still finds the wiphy, and ieee80211_add_iface() adds a new interface. wiphy_unregister() then warns that the wdev list is not empty, and the netdev outlives the wiphy, which the driver frees right after. Closing the netdev later uses the freed wiphy: WARNING: net/wireless/core.c:1383 at wiphy_unregister+0xa69/0xca0 ... BUG: KASAN: use-after-free in __mutex_lock Read of size 8 Call Trace: __mutex_lock (kernel/locking/mutex.c:625 kernel/locking/mutex.c:821) cfg80211_netdev_notifier_call (include/net/cfg80211.h:6989 net/wireless/core.c:1832) notifier_call_chain (kernel/notifier.c:86) unregister_netdevice_many_notify (net/core/dev.c:2353 net/core/dev.c:2367 net/core/dev.c:12776) default_device_exit_batch (net/core/dev.c:12847 net/core/dev.c:13570) ops_undo_list (net/core/net_namespace.c:206 net/core/net_namespace.c:253) cleanup_net (net/core/net_namespace.c:713) If the new interface is up already, wiphy_unregister() instead waits for it with the wiphy mutex taken inside wait_event() and warns "do not call blocking ops when !TASK_RUNNING". With mac80211_hwsim, a user in its own user and network namespace gets there by adding an interface while it deletes a radio. ieee80211_unregister_hw() frees the TX flows with ieee80211_txq_teardown_flows() right after removing the interfaces, under the same RTNL hold, and an interface added later would use the freed flows. Refuse new interfaces once the flows are gone. Fixes: f0706e828e96 ("[MAC80211]: Add mac80211 wireless stack.") Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Kyuwon Cho --- The issue was found by an LLM-guided test generator that we are developing as a research prototype. It reproduces as any user with mac80211_hwsim built in, in its own user and network namespace: one thread keeps creating a station interface on the wiphy of a new radio while another thread deletes the radio. The interface created after the radio's interfaces were removed is still there after HWSIM_CMD_DEL_RADIO returns, and leaving the namespace triggers the report above. With the patch, the creation fails with ENODEV and nothing is left over. The reproducer is available on request. Found and tested on mainline 9437ee8b6cf6 (v7.4-rc4-571, with KASAN); the patch is against wireless (35c42b20ac87) and also applies to wireless-next. net/mac80211/cfg.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c index 9d7c03b6a6f8..8103ac041b3e 100644 --- a/net/mac80211/cfg.c +++ b/net/mac80211/cfg.c @@ -227,6 +227,10 @@ static struct wireless_dev *ieee80211_add_iface(struct wiphy *wiphy, struct ieee80211_sub_if_data *sdata; int err; + /* the hardware is being unregistered and the TX flows are freed */ + if (!local->cvars) + return ERR_PTR(-ENODEV); + err = ieee80211_if_add(local, name, name_assign_type, &wdev, type, params); if (err) return ERR_PTR(err); -- 2.43.0