Linux wireless drivers development
 help / color / mirror / Atom feed
From: Felix Fietkau <nbd@nbd.name>
To: linux-wireless@vger.kernel.org
Subject: [PATCH mt76-next 04/20] wifi: mt76: mt7925: run the reset link replay under the wiphy lock
Date: Fri, 20 Nov 2026 18:44:43 +0100	[thread overview]
Message-ID: <20261120174459.1657382-4-nbd@nbd.name> (raw)
In-Reply-To: <20261120174459.1657382-1-nbd@nbd.name>

mt7925_mac_reset_work() replays the links of each interface without the
wiphy lock or dev->mt76.mutex, so a link can go while
mt7925_vif_connect_iter() still uses it. For a station, the replay
itself queues the disconnect that removes the links. The check that
commit bd8b2ec83818 ("wifi: mt76: mt7925: fix crash in reset link
replay") added only skips a link that is gone before the replay, so a
use after free remains.

Run the replay as a wiphy work, with the mutex held. Every link change
runs under the wiphy lock, so the links stay valid until the replay
ends. The reset work cannot take the wiphy lock itself, since
mt792x_stop() waits for it under that lock.

Fixes: 14061994184d ("wifi: mt76: mt7925: add link handling in mt7925_vif_connect_iter")
Signed-off-by: Felix Fietkau <nbd@nbd.name>
---
 .../net/wireless/mediatek/mt76/mt7925/init.c  |  1 +
 .../net/wireless/mediatek/mt76/mt7925/mac.c   | 20 +++++++++++++++----
 .../net/wireless/mediatek/mt76/mt7925/main.c  |  1 +
 .../wireless/mediatek/mt76/mt7925/mt7925.h    |  1 +
 .../net/wireless/mediatek/mt76/mt7925/pci.c   |  1 +
 .../net/wireless/mediatek/mt76/mt7925/usb.c   |  1 +
 drivers/net/wireless/mediatek/mt76/mt792x.h   | 10 ++++++++++
 .../net/wireless/mediatek/mt76/mt792x_usb.c   |  2 ++
 8 files changed, 33 insertions(+), 4 deletions(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/init.c b/drivers/net/wireless/mediatek/mt76/mt7925/init.c
index 5c81574e5283..ad51f71babd7 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7925/init.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7925/init.c
@@ -320,6 +320,7 @@ int mt7925_register_device(struct mt792x_dev *dev)
 	skb_queue_head_init(&dev->coredump.msg_list);
 
 	INIT_WORK(&dev->reset_work, mt7925_mac_reset_work);
+	wiphy_work_init(&dev->reset_vif_work, mt7925_mac_reset_vif_work);
 	INIT_WORK(&dev->init_work, mt7925_init_work);
 	INIT_WORK(&dev->nan_deferred_work, mt7925_nan_deferred_work);
 	spin_lock_init(&dev->nan_deferred_lock);
diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/mac.c b/drivers/net/wireless/mediatek/mt76/mt7925/mac.c
index c342559a133b..30deb675c5ff 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7925/mac.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7925/mac.c
@@ -1640,10 +1640,22 @@ void mt7925_mac_reset_work(struct work_struct *work)
 		return;
 
 	ieee80211_wake_queues(hw);
-	ieee80211_iterate_active_interfaces(hw,
-					    IEEE80211_IFACE_ITER_RESUME_ALL,
-					    mt7925_vif_connect_iter, NULL);
-	mt76_connac_power_save_sched(&dev->mt76.phy, pm);
+	wiphy_work_queue(hw->wiphy, &dev->reset_vif_work);
+}
+
+void mt7925_mac_reset_vif_work(struct wiphy *wiphy, struct wiphy_work *work)
+{
+	struct mt792x_dev *dev = container_of(work, struct mt792x_dev,
+					      reset_vif_work);
+
+	if (test_bit(MT76_REMOVED, &dev->mphy.state))
+		return;
+
+	mt792x_mutex_acquire(dev);
+	ieee80211_iterate_active_interfaces_mtx(mt76_hw(dev),
+						IEEE80211_IFACE_ITER_RESUME_ALL,
+						mt7925_vif_connect_iter, NULL);
+	mt792x_mutex_release(dev);
 
 	mt7925_regd_change(&dev->phy, "00");
 }
diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/main.c b/drivers/net/wireless/mediatek/mt76/mt7925/main.c
index 1fac66e8c50a..61dc02e8aa68 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7925/main.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7925/main.c
@@ -3063,6 +3063,7 @@ static void mt7925_stop(struct ieee80211_hw *hw, bool suspend)
 	cancel_delayed_work_sync(&dev->mlo_pm_work);
 
 	mt792x_stop(hw, suspend);
+	wiphy_work_cancel(hw->wiphy, &dev->reset_vif_work);
 }
 
 const struct ieee80211_ops mt7925_ops = {
diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/mt7925.h b/drivers/net/wireless/mediatek/mt76/mt7925/mt7925.h
index 1710d97c5d25..228b74721ed7 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7925/mt7925.h
+++ b/drivers/net/wireless/mediatek/mt76/mt7925/mt7925.h
@@ -333,6 +333,7 @@ int mt7925_mac_sta_event(struct mt76_dev *mdev, struct ieee80211_vif *vif,
 void mt7925_mac_sta_remove(struct mt76_dev *mdev, struct ieee80211_vif *vif,
 			   struct ieee80211_sta *sta);
 void mt7925_mac_reset_work(struct work_struct *work);
+void mt7925_mac_reset_vif_work(struct wiphy *wiphy, struct wiphy_work *work);
 int mt7925e_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr,
 			   enum mt76_txq_id qid, struct mt76_wcid *wcid,
 			   struct ieee80211_sta *sta,
diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/pci.c b/drivers/net/wireless/mediatek/mt76/mt7925/pci.c
index 736457aa10bb..a7877c408736 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7925/pci.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7925/pci.c
@@ -120,6 +120,7 @@ static void mt7925e_unregister_device(struct mt792x_dev *dev)
 	mt76_unregister_device(&dev->mt76);
 	set_bit(MT76_REMOVED, &dev->mphy.state);
 	cancel_work_sync(&dev->reset_work);
+	mt792x_reset_vif_work_cancel(dev);
 	mt76_for_each_q_rx(&dev->mt76, i)
 		napi_disable(&dev->mt76.napi[i]);
 	cancel_delayed_work_sync(&pm->ps_work);
diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/usb.c b/drivers/net/wireless/mediatek/mt76/mt7925/usb.c
index f97f787b2198..ee5306c29427 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7925/usb.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7925/usb.c
@@ -154,6 +154,7 @@ static void mt7925u_stop(struct ieee80211_hw *hw, bool suspend)
 	cancel_delayed_work_sync(&dev->mlo_pm_work);
 
 	mt792xu_stop(hw, suspend);
+	wiphy_work_cancel(hw->wiphy, &dev->reset_vif_work);
 }
 
 static int mt7925u_probe(struct usb_interface *usb_intf,
diff --git a/drivers/net/wireless/mediatek/mt76/mt792x.h b/drivers/net/wireless/mediatek/mt76/mt792x.h
index c2d6ebb2ca3a..8dfe10cbb6d1 100644
--- a/drivers/net/wireless/mediatek/mt76/mt792x.h
+++ b/drivers/net/wireless/mediatek/mt76/mt792x.h
@@ -374,6 +374,7 @@ struct mt792x_dev {
 	struct mt792x_phy phy;
 
 	struct work_struct reset_work;
+	struct wiphy_work reset_vif_work;
 	bool hw_full_reset:1;
 	bool hw_init_done:1;
 	bool fw_assert:1;
@@ -526,6 +527,15 @@ mt792x_hw_phy(struct ieee80211_hw *hw)
 	return phy->priv;
 }
 
+static inline void mt792x_reset_vif_work_cancel(struct mt792x_dev *dev)
+{
+	struct wiphy *wiphy = mt76_hw(dev)->wiphy;
+
+	wiphy_lock(wiphy);
+	wiphy_work_cancel(wiphy, &dev->reset_vif_work);
+	wiphy_unlock(wiphy);
+}
+
 static inline void
 mt792x_get_status_freq_info(struct mt76_rx_status *status, u8 chfreq)
 {
diff --git a/drivers/net/wireless/mediatek/mt76/mt792x_usb.c b/drivers/net/wireless/mediatek/mt76/mt792x_usb.c
index feedb66d4b6e..d5a6fe33d09c 100644
--- a/drivers/net/wireless/mediatek/mt76/mt792x_usb.c
+++ b/drivers/net/wireless/mediatek/mt76/mt792x_usb.c
@@ -524,6 +524,8 @@ void mt792xu_disconnect(struct usb_interface *usb_intf)
 	wake_up(&dev->mt76.mcu.wait);
 	skb_queue_purge(&dev->mt76.mcu.res_q);
 	cancel_work_sync(&dev->reset_work);
+	if (!is_connac2(&dev->mt76))
+		mt792x_reset_vif_work_cancel(dev);
 	mt792xu_cleanup(dev);
 	set_bit(MT76_REMOVED, &dev->mphy.state);
 
-- 
2.47.3


  parent reply	other threads:[~2026-11-20 17:45 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20 17:44 [PATCH mt76-next 01/20] wifi: mt76: mt7925: free the vif links when all links go Felix Fietkau
2026-11-20 17:44 ` [PATCH mt76-next 02/20] wifi: mt76: mt7925: free removed vif links after an RCU grace period Felix Fietkau
2026-11-20 17:44 ` [PATCH mt76-next 03/20] wifi: mt76: remove a replayed station from the driver before the add Felix Fietkau
2026-11-20 17:44 ` Felix Fietkau [this message]
2026-11-20 17:44 ` [PATCH mt76-next 05/20] wifi: mt76: mt7925: take the mutex before the link_info_changed lookup Felix Fietkau
2026-11-20 17:44 ` [PATCH mt76-next 06/20] wifi: mt76: mt7925: hold the mutex for the link lookup in conf_tx Felix Fietkau
2026-11-20 17:44 ` [PATCH mt76-next 07/20] wifi: mt76: mt7925: skip a polled link without a station Felix Fietkau
2026-11-20 17:44 ` [PATCH mt76-next 08/20] wifi: mt76: mt7925: skip a link without a link conf in the MLO PS update Felix Fietkau
2026-11-20 17:44 ` [PATCH mt76-next 09/20] wifi: mt76: mt7925: restore the beacon filter when monitor mode ends Felix Fietkau
2026-11-20 17:44 ` [PATCH mt76-next 10/20] wifi: mt76: usb: do not park the TX worker again under MT76_RESET Felix Fietkau
2026-11-20 17:44 ` [PATCH mt76-next 11/20] wifi: mt76: mt7925: keep the default link in the active links Felix Fietkau
2026-11-20 17:44 ` [PATCH mt76-next 12/20] wifi: mt76: mt7925: read the monitor state under the mutex for deep sleep Felix Fietkau
2026-11-20 17:44 ` [PATCH mt76-next 13/20] wifi: mt76: clear roc_link before the ROC link is freed Felix Fietkau
2026-11-20 17:44 ` [PATCH mt76-next 14/20] wifi: mt76: mt792x: handle all interfaces of a channel context Felix Fietkau
2026-11-20 17:44 ` [PATCH mt76-next 15/20] wifi: mt76: mt792x: set up the sniffer when a monitor gets its channel Felix Fietkau
2026-11-20 17:44 ` [PATCH mt76-next 16/20] wifi: mt76: buffer Disassociation frames for stations in power save Felix Fietkau
2026-11-20 17:44 ` [PATCH mt76-next 17/20] wifi: mt76: mt7921: read the monitor state under the mutex for deep sleep Felix Fietkau
2026-11-20 17:44 ` [PATCH mt76-next 18/20] wifi: mt76: mt7925: wake the device to unassign a channel context Felix Fietkau
2026-11-20 17:44 ` [PATCH mt76-next 19/20] wifi: mt76: mt7996: keep the firmware log settings across a reload Felix Fietkau
2026-11-20 17:44 ` [PATCH mt76-next 20/20] wifi: mt76: mt7915: " Felix Fietkau

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261120174459.1657382-4-nbd@nbd.name \
    --to=nbd@nbd.name \
    --cc=linux-wireless@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox