Skip to contentSkip to conversation

mwifiex: add mutex lock for call in mwifiex_dfs_chan_sw_work_queue

PATCH Superseded Niels Dossche 2 participants 3 messages Mar 19, 2022 – Mar 21, 2022 Marvell mwifiex wireless driver

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mwifiex: add mutex lock for call in mwifiex_dfs_chan_sw_work_queue

cfg80211_ch_switch_notify uses ASSERT_WDEV_LOCK to assert that net_device->ieee80211_ptr->mtx is held during the function's execution. mwifiex_dfs_chan_sw_work_queue is one of its callers, which does not hold that lock, therefore violating the assertion.
Add a lock around the call.

Disclaimer:
I am currently working on a static analyser to detect missing locks. This was a reported case. I manually verified the report by looking at the code, so that I do not send wrong information or patches. After concluding that this seems to be a true positive, I created this patch.
However, as I do not in fact have this particular hardware, I was unable to test it.

---
 drivers/net/wireless/marvell/mwifiex/11h.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/net/wireless/marvell/mwifiex/11h.c +6 -1
index d2ee6469e67b..f2cba764024e 100644
@@ -285,6 +285,7 @@ void mwifiex_dfs_chan_sw_work_queue(struct work_struct *work)
 	struct mwifiex_private *priv =
 			container_of(delayed_work, struct mwifiex_private,
 				     dfs_chan_sw_work);
+	struct net_device *netdev;
 
 	bss_cfg = &priv->bss_cfg;
 	if (!bss_cfg->beacon_period) {
@@ -301,7 +302,11 @@ void mwifiex_dfs_chan_sw_work_queue(struct work_struct *work)
 		return;
 	}
 
+	netdev = priv->netdev;
+
 	mwifiex_dbg(priv->adapter, MSG,
 		    "indicating channel switch completion to kernel\n");
-	cfg80211_ch_switch_notify(priv->netdev, &priv->dfs_chandef);
+	mutex_lock(&netdev->ieee80211_ptr->mtx);
+	cfg80211_ch_switch_notify(netdev, &priv->dfs_chandef);
+	mutex_unlock(&netdev->ieee80211_ptr->mtx);
 }
Signature · 1 line
2.35.1
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Niels Dossche
drivers/net/wireless/marvell/mwifiex/11h.c +1 -0
@@ -285,6 +285,7 @@ void mwifiex_dfs_chan_sw_work_queue(struct work_struct *work)
 	struct mwifiex_private *priv =
 			container_of(delayed_work, struct mwifiex_private,
 				     dfs_chan_sw_work);
+	struct net_device *netdev;
 
 	bss_cfg = &priv->bss_cfg;
 	if (!bss_cfg->beacon_period) {

drivers/net/wireless/marvell/mwifiex/11h.c void mwifiex_dfs_chan_sw_work_queue(struct work_struct *work) · line 309

Quoted 9 lines
drivers/net/wireless/marvell/mwifiex/11h.c +3 -1
@@ -301,7 +302,11 @@ void mwifiex_dfs_chan_sw_work_queue(struct work_struct *work)
 		return;
 	}
 
+	netdev = priv->netdev;
+
 	mwifiex_dbg(priv->adapter, MSG,
 		    "indicating channel switch completion to kernel\n");
-	cfg80211_ch_switch_notify(priv->netdev, &priv->dfs_chandef);
+	mutex_lock(&netdev->ieee80211_ptr->mtx);

A more appropriate route to this object might be priv->wdev.mtx. But otherwise, I think this makes sense, and matches what ath6kl_cfg80211_ch_switch_notify() and qtnf_event_handle_freq_change() do. With the suggested change:

Thanks.

Quoted 6 lines
drivers/net/wireless/marvell/mwifiex/11h.c +2 -0
+	cfg80211_ch_switch_notify(netdev, &priv->dfs_chandef);
+	mutex_unlock(&netdev->ieee80211_ptr->mtx);
 }
Signature · 1 line
2.35.1
#2 lore raw
Quoted 15 lines · Brian Norris
Quoted 14 lines · Niels Dossche
drivers/net/wireless/marvell/mwifiex/11h.c +1 -0
@@ -285,6 +285,7 @@ void mwifiex_dfs_chan_sw_work_queue(struct work_struct *work)
 	struct mwifiex_private *priv =
 			container_of(delayed_work, struct mwifiex_private,
 				     dfs_chan_sw_work);
+	struct net_device *netdev;
 
 	bss_cfg = &priv->bss_cfg;
 	if (!bss_cfg->beacon_period) {
@@ -301,7 +302,11 @@ void mwifiex_dfs_chan_sw_work_queue(struct work_struct *work)
 		return;
 	}
 
Quoted 11 lines

drivers/net/wireless/marvell/mwifiex/11h.c void mwifiex_dfs_chan_sw_work_queue(struct work_struct *work) · line 309

Quoted 6 lines
drivers/net/wireless/marvell/mwifiex/11h.c +3 -1
+	netdev = priv->netdev;
+
 	mwifiex_dbg(priv->adapter, MSG,
 		    "indicating channel switch completion to kernel\n");
-	cfg80211_ch_switch_notify(priv->netdev, &priv->dfs_chandef);
+	mutex_lock(&netdev->ieee80211_ptr->mtx);

A more appropriate route to this object might be priv->wdev.mtx. But otherwise, I think this makes sense, and matches what ath6kl_cfg80211_ch_switch_notify() and qtnf_event_handle_freq_change() do. With the suggested change:

Thanks for the review, will change that and send a v2.

Quoted 11 lines

Thanks.

Quoted 6 lines
drivers/net/wireless/marvell/mwifiex/11h.c +2 -0
+	cfg80211_ch_switch_notify(netdev, &priv->dfs_chandef);
+	mutex_unlock(&netdev->ieee80211_ptr->mtx);
 }
Signature · 1 line
2.35.1