wifi: mac80211: acquire wiphy lock for unlisted sdata teardown
PATCH 1/1 wifi: mac80211: acquire wiphy lock for unlisted sdata teardown
When netdev registration fails or an interface cannot be moved out of a dying network namespace, the netdev core calls ->ndo_uninit() (ieee80211_uninit) with RTNL held.
However, ieee80211_uninit() calls ieee80211_teardown_sdata() without holding wiphy_lock. During teardown, ieee80211_free_keys() invokes wiphy_delayed_work_cancel(), which triggers a lockdep warning:
WARNING: CPU: 0 PID: 6112 at net/wireless/core.c:1839 wiphy_delayed_work_cancel+0x85/0xb0 ... Call Trace: ieee80211_free_keys+0x31a/0x3c0 net/mac80211/key.c:380 ieee80211_teardown_sdata+0x2b8/0x10f0 net/mac80211/iface.c:928 ieee80211_uninit+0x3f/0x50 net/mac80211/iface.c:954 rollback_registered_many+0xa5c/0xef0 net/core/dev.c:10065
In the normal deletion path (ieee80211_del_virtual_intf), both RTNL and wiphy_lock are held when ieee80211_teardown_sdata() runs, and the sdata is removed from local->interfaces.
Change ieee80211_unlist_sdata() to return a boolean indicating whether the sdata was present in the list, and acquire wiphy_lock in ieee80211_uninit() only if the interface is actually being unlisted here.
--- net/mac80211/iface.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
net/mac80211/iface.c +12 -3
@@ -931,7 +931,7 @@ static void ieee80211_teardown_sdata(struct ieee80211_sub_if_data *sdata)* core when cfg80211 couldn't move it out of a network namespace that's being * destroyed. Drop it from the interface list either way. */ -static void ieee80211_unlist_sdata (struct ieee80211_sub_if_data *sdata) +static bool ieee80211_unlist_sdata (struct ieee80211_sub_if_data *sdata) {struct ieee80211_local *local = sdata->local;struct ieee80211_sub_if_data *iter;
@@ -943,16 +943,25 @@ static void ieee80211_unlist_sdata(struct ieee80211_sub_if_data *sdata)continue ;guard (mutex)(&local->iflist_mtx);list_del_rcu (&sdata->list); -return ; +return true; } + +return false; }static void ieee80211_uninit (struct net_device *dev) {struct ieee80211_sub_if_data *sdata =IEEE80211_DEV_TO_SUB_IF (dev); +struct wiphy *wiphy = sdata->local->hw.wiphy; +bool unlisted =ieee80211_unlist_sdata (sdata); + +if (unlisted) +wiphy_lock (wiphy); -ieee80211_unlist_sdata (sdata);ieee80211_teardown_sdata (sdata); + +if (unlisted) +wiphy_unlock (wiphy); } static int ieee80211_netdev_setup_tc(struct net_device *dev,
Signature · 1 line
2.47.0.windows.1