From: Felix Fietkau <nbd@nbd.name>
To: linux-wireless@vger.kernel.org
Subject: [PATCH mt76-next 03/20] wifi: mt76: remove a replayed station from the driver before the add
Date: Fri, 20 Nov 2026 18:44:42 +0100 [thread overview]
Message-ID: <20261120174459.1657382-3-nbd@nbd.name> (raw)
In-Reply-To: <20261120174459.1657382-1-nbd@nbd.name>
A write to the mac80211 debugfs file "reset" leaves the stations of
every interface other than a managed one in place.
ieee80211_reconfig() then adds them again on their old drv_priv, and
the sta_add of most drivers allocates a new WLAN index for them. The
old index leaks, and its dev->wcid[] entry still points at the station
after the station is freed.
Treat the replay of a station that the driver still holds as a removal
followed by a fresh add. The driver holds a station whose sta flag is
set or whose wcid is published, since a new station has a zeroed
drv_priv. Unpublish the wcid for an RCU grace period first, as for a
station that mac80211 destroys. The station keeps its count, since
mac80211 removes it through the driver later, also if the add fails.
mt76x0 and mt76x2 opt out, since their sta_add restores a replayed
station.
Fixes: c8846e101502 ("mt76: add driver for MT7603E and MT7628/7688")
Signed-off-by: Felix Fietkau <nbd@nbd.name>
---
drivers/net/wireless/mediatek/mt76/mac80211.c | 58 ++++++++++++++-----
drivers/net/wireless/mediatek/mt76/mt76.h | 1 +
.../net/wireless/mediatek/mt76/mt76x0/pci.c | 3 +-
.../net/wireless/mediatek/mt76/mt76x0/usb.c | 3 +-
.../net/wireless/mediatek/mt76/mt76x2/pci.c | 3 +-
.../net/wireless/mediatek/mt76/mt76x2/usb.c | 3 +-
6 files changed, 52 insertions(+), 19 deletions(-)
diff --git a/drivers/net/wireless/mediatek/mt76/mac80211.c b/drivers/net/wireless/mediatek/mt76/mac80211.c
index 2957f5694dc2..b8a568e0ae27 100644
--- a/drivers/net/wireless/mediatek/mt76/mac80211.c
+++ b/drivers/net/wireless/mediatek/mt76/mac80211.c
@@ -1713,6 +1713,42 @@ void mt76_rx_poll_complete(struct mt76_dev *dev, enum mt76_rxq_id q,
}
EXPORT_SYMBOL_GPL(mt76_rx_poll_complete);
+static void
+mt76_sta_teardown(struct mt76_phy *phy, struct ieee80211_vif *vif,
+ struct ieee80211_sta *sta)
+{
+ struct mt76_dev *dev = phy->dev;
+ struct mt76_wcid *wcid = (struct mt76_wcid *)sta->drv_priv;
+ int i, idx = wcid->idx;
+
+ for (i = 0; i < ARRAY_SIZE(wcid->aggr); i++)
+ mt76_rx_aggr_stop(dev, wcid, i);
+
+ if (dev->drv->sta_remove)
+ dev->drv->sta_remove(dev, vif, sta);
+
+ mt76_wcid_cleanup(dev, wcid);
+
+ mt76_wcid_mask_clear(dev->wcid_mask, idx);
+}
+
+static void
+mt76_sta_replay_drop(struct mt76_phy *phy, struct ieee80211_vif *vif,
+ struct ieee80211_sta *sta)
+{
+ struct mt76_wcid *wcid = (struct mt76_wcid *)sta->drv_priv;
+ struct mt76_dev *dev = phy->dev;
+
+ spin_lock_bh(&dev->status_lock);
+ if (rcu_access_pointer(dev->wcid[wcid->idx]) == wcid)
+ rcu_assign_pointer(dev->wcid[wcid->idx], NULL);
+ spin_unlock_bh(&dev->status_lock);
+ synchronize_net();
+
+ mt76_sta_teardown(phy, vif, sta);
+ wcid->sta = 0;
+}
+
static int
mt76_sta_add(struct mt76_phy *phy, struct ieee80211_vif *vif,
struct ieee80211_sta *sta)
@@ -1726,8 +1762,12 @@ mt76_sta_add(struct mt76_phy *phy, struct ieee80211_vif *vif,
mutex_lock(&dev->mutex);
- /* drv_priv of a new station is zeroed, so only a replay has it set */
- registered = wcid->sta;
+ published = rcu_dereference_protected(dev->wcid[wcid->idx],
+ lockdep_is_held(&dev->mutex));
+ registered = wcid->sta || published == wcid;
+ if (registered && !(dev->drv->drv_flags & MT_DRV_KEEP_REPLAYED_STA))
+ mt76_sta_replay_drop(phy, vif, sta);
+
ret = dev->drv->sta_add(dev, vif, sta);
if (ret)
goto out;
@@ -1765,19 +1805,7 @@ mt76_sta_add(struct mt76_phy *phy, struct ieee80211_vif *vif,
void __mt76_sta_remove(struct mt76_phy *phy, struct ieee80211_vif *vif,
struct ieee80211_sta *sta)
{
- struct mt76_dev *dev = phy->dev;
- struct mt76_wcid *wcid = (struct mt76_wcid *)sta->drv_priv;
- int i, idx = wcid->idx;
-
- for (i = 0; i < ARRAY_SIZE(wcid->aggr); i++)
- mt76_rx_aggr_stop(dev, wcid, i);
-
- if (dev->drv->sta_remove)
- dev->drv->sta_remove(dev, vif, sta);
-
- mt76_wcid_cleanup(dev, wcid);
-
- mt76_wcid_mask_clear(dev->wcid_mask, idx);
+ mt76_sta_teardown(phy, vif, sta);
phy->num_sta--;
}
EXPORT_SYMBOL_GPL(__mt76_sta_remove);
diff --git a/drivers/net/wireless/mediatek/mt76/mt76.h b/drivers/net/wireless/mediatek/mt76/mt76.h
index 548632fe884a..ddada6834170 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76.h
+++ b/drivers/net/wireless/mediatek/mt76/mt76.h
@@ -541,6 +541,7 @@ struct mt76_hw_cap {
#define MT_DRV_AMSDU_OFFLOAD BIT(5)
#define MT_DRV_IGNORE_TXS_FAILED BIT(6)
#define MT_DRV_HW_PS_BUFFERING BIT(7)
+#define MT_DRV_KEEP_REPLAYED_STA BIT(8)
struct mt76_driver_ops {
u32 drv_flags;
diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/pci.c b/drivers/net/wireless/mediatek/mt76/mt76x0/pci.c
index 3c4948522c5b..49ff52fe2ccb 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x0/pci.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76x0/pci.c
@@ -158,7 +158,8 @@ mt76x0e_probe(struct pci_dev *pdev, const struct pci_device_id *id)
.txwi_size = sizeof(struct mt76x02_txwi),
.drv_flags = MT_DRV_TX_ALIGNED4_SKBS |
MT_DRV_SW_RX_AIRTIME |
- MT_DRV_IGNORE_TXS_FAILED,
+ MT_DRV_IGNORE_TXS_FAILED |
+ MT_DRV_KEEP_REPLAYED_STA,
.survey_flags = SURVEY_INFO_TIME_TX,
.update_survey = mt76x02_update_channel,
.set_channel = mt76x0_set_channel,
diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/usb.c b/drivers/net/wireless/mediatek/mt76/mt76x0/usb.c
index 2acce121fb14..f51a7e0d147f 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x0/usb.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76x0/usb.c
@@ -215,7 +215,8 @@ static int mt76x0u_probe(struct usb_interface *usb_intf,
{
static const struct mt76_driver_ops drv_ops = {
.drv_flags = MT_DRV_SW_RX_AIRTIME |
- MT_DRV_IGNORE_TXS_FAILED,
+ MT_DRV_IGNORE_TXS_FAILED |
+ MT_DRV_KEEP_REPLAYED_STA,
.survey_flags = SURVEY_INFO_TIME_TX,
.update_survey = mt76x02_update_channel,
.set_channel = mt76x0_set_channel,
diff --git a/drivers/net/wireless/mediatek/mt76/mt76x2/pci.c b/drivers/net/wireless/mediatek/mt76/mt76x2/pci.c
index 491a32921a06..6df9f5110b7b 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x2/pci.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76x2/pci.c
@@ -23,7 +23,8 @@ mt76x2e_probe(struct pci_dev *pdev, const struct pci_device_id *id)
.txwi_size = sizeof(struct mt76x02_txwi),
.drv_flags = MT_DRV_TX_ALIGNED4_SKBS |
MT_DRV_SW_RX_AIRTIME |
- MT_DRV_IGNORE_TXS_FAILED,
+ MT_DRV_IGNORE_TXS_FAILED |
+ MT_DRV_KEEP_REPLAYED_STA,
.survey_flags = SURVEY_INFO_TIME_TX,
.update_survey = mt76x02_update_channel,
.set_channel = mt76x2e_set_channel,
diff --git a/drivers/net/wireless/mediatek/mt76/mt76x2/usb.c b/drivers/net/wireless/mediatek/mt76/mt76x2/usb.c
index ade15bddefc5..23b4e020c5b7 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x2/usb.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76x2/usb.c
@@ -34,7 +34,8 @@ static int mt76x2u_probe(struct usb_interface *intf,
{
static const struct mt76_driver_ops drv_ops = {
.drv_flags = MT_DRV_SW_RX_AIRTIME |
- MT_DRV_IGNORE_TXS_FAILED,
+ MT_DRV_IGNORE_TXS_FAILED |
+ MT_DRV_KEEP_REPLAYED_STA,
.survey_flags = SURVEY_INFO_TIME_TX,
.update_survey = mt76x02_update_channel,
.set_channel = mt76x2u_set_channel,
--
2.47.3
next prev 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 ` Felix Fietkau [this message]
2026-11-20 17:44 ` [PATCH mt76-next 04/20] wifi: mt76: mt7925: run the reset link replay under the wiphy lock Felix Fietkau
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-3-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