From: Felix Fietkau <nbd@nbd.name>
To: linux-wireless@vger.kernel.org
Subject: [PATCH mt76-next 16/19] wifi: mt76: keep an unpublished wcid off the TX and poll lists
Date: Tue, 17 Nov 2026 19:01:31 +0100 [thread overview]
Message-ID: <20261117180134.2940930-16-nbd@nbd.name> (raw)
In-Reply-To: <20261117180134.2940930-1-nbd@nbd.name>
A TX or RX path that looked up a wcid before the driver unpublished it
can call mt76_tx() or mt76_wcid_add_poll() after mt76_wcid_cleanup().
This lists the wcid again, and where the driver frees the wcid after
the cleanup, the TX worker or the poll later uses freed memory.
Drop the frame and skip the poll for a wcid that dev->wcid[] no longer
holds, like mt76_tx_status_skb_add() does for a TX status request. Both
tests run under the lock that the cleanup takes to unlist the wcid. The
global wcid lives as long as the device, and mt76x02 never publishes
it, so its frames are always queued. mt7996 unpublishes a station link
that it removes outside of a station removal only after the cleanup, so
unpublish it before.
Fixes: 0335c034e726 ("wifi: mt76: fix race condition related to checking tx queue fill status")
Fixes: f520eceacd24 ("wifi: mt76: mt7996: Add mt7996_mac_sta_change_links callback")
Signed-off-by: Felix Fietkau <nbd@nbd.name>
---
drivers/net/wireless/mediatek/mt76/mac80211.c | 3 ++-
.../net/wireless/mediatek/mt76/mt7996/main.c | 4 +++-
drivers/net/wireless/mediatek/mt76/tx.c | 20 +++++++++++++------
3 files changed, 19 insertions(+), 8 deletions(-)
diff --git a/drivers/net/wireless/mediatek/mt76/mac80211.c b/drivers/net/wireless/mediatek/mt76/mac80211.c
index da1da160909a..12089dca01b2 100644
--- a/drivers/net/wireless/mediatek/mt76/mac80211.c
+++ b/drivers/net/wireless/mediatek/mt76/mac80211.c
@@ -1886,7 +1886,8 @@ void mt76_wcid_add_poll(struct mt76_dev *dev, struct mt76_wcid *wcid)
return;
spin_lock_bh(&dev->sta_poll_lock);
- if (list_empty(&wcid->poll_list))
+ if (rcu_access_pointer(dev->wcid[wcid->idx]) == wcid &&
+ list_empty(&wcid->poll_list))
list_add_tail(&wcid->poll_list, &dev->sta_poll_list);
spin_unlock_bh(&dev->sta_poll_lock);
}
diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/main.c b/drivers/net/wireless/mediatek/mt76/mt7996/main.c
index 90a074ffa7dc..ba7a0553e34a 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7996/main.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7996/main.c
@@ -1385,6 +1385,9 @@ void mt7996_mac_sta_remove_link(struct mt7996_dev *dev,
if (!msta_link)
return;
+ if (flush)
+ rcu_assign_pointer(dev->mt76.wcid[msta_link->wcid.idx], NULL);
+
spin_lock_bh(&dev->mt76.sta_poll_lock);
if (!list_empty(&msta_link->wcid.poll_list))
list_del_init(&msta_link->wcid.poll_list);
@@ -1411,7 +1414,6 @@ void mt7996_mac_sta_remove_link(struct mt7996_dev *dev,
phy->mt76->num_sta--;
rcu_assign_pointer(msta->link[link_id], NULL);
- rcu_assign_pointer(dev->mt76.wcid[msta_link->wcid.idx], NULL);
mt76_wcid_mask_clear(dev->mt76.wcid_mask, msta_link->wcid.idx);
if (msta_link != &msta->deflink)
kfree_rcu(msta_link, rcu_head);
diff --git a/drivers/net/wireless/mediatek/mt76/tx.c b/drivers/net/wireless/mediatek/mt76/tx.c
index 9eafc86ec288..84ab3d428001 100644
--- a/drivers/net/wireless/mediatek/mt76/tx.c
+++ b/drivers/net/wireless/mediatek/mt76/tx.c
@@ -365,6 +365,7 @@ mt76_tx(struct mt76_phy *phy, struct ieee80211_sta *sta,
{
struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
struct ieee80211_hdr *hdr = (void *)skb->data;
+ struct mt76_dev *dev = phy->dev;
struct sk_buff_head *head;
if (mt76_testmode_enabled(phy)) {
@@ -388,16 +389,23 @@ mt76_tx(struct mt76_phy *phy, struct ieee80211_sta *sta,
else
head = &wcid->tx_pending;
- spin_lock_bh(&head->lock);
- __skb_queue_tail(head, skb);
- spin_unlock_bh(&head->lock);
+ spin_lock_bh(&dev->tx_lock);
+ if (wcid != &dev->global_wcid &&
+ rcu_access_pointer(dev->wcid[wcid->idx]) != wcid) {
+ spin_unlock_bh(&dev->tx_lock);
+ ieee80211_free_txskb(phy->hw, skb);
+ return;
+ }
+
+ spin_lock(&head->lock);
+ __skb_queue_tail(head, skb);
+ spin_unlock(&head->lock);
- spin_lock_bh(&phy->dev->tx_lock);
if (list_empty(&wcid->tx_list))
list_add_tail(&wcid->tx_list, &phy->tx_list);
- spin_unlock_bh(&phy->dev->tx_lock);
+ spin_unlock_bh(&dev->tx_lock);
- mt76_worker_schedule(&phy->dev->tx_worker);
+ mt76_worker_schedule(&dev->tx_worker);
}
EXPORT_SYMBOL_GPL(mt76_tx);
--
2.47.3
next prev parent reply other threads:[~2026-11-17 18:01 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 18:01 [PATCH mt76-next 01/19] wifi: mt76: don't pin undrainable PS stations in the tx scheduler Felix Fietkau
2026-11-17 18:01 ` [PATCH mt76-next 02/19] wifi: mt76: mt7996: return a negative error for a firmware status Felix Fietkau
2026-11-17 18:01 ` [PATCH mt76-next 03/19] wifi: mt76: mt7996: use the default timeout for STA_REC and BSS_INFO Felix Fietkau
2026-11-18 8:22 ` Lorenzo Bianconi
2026-11-17 18:01 ` [PATCH mt76-next 04/19] wifi: mt76: mt7915: " Felix Fietkau
2026-11-18 8:23 ` Lorenzo Bianconi
2026-11-17 18:01 ` [PATCH mt76-next 05/19] wifi: mt76: delete only the RX NAPIs that were added Felix Fietkau
2026-11-18 8:32 ` Lorenzo Bianconi
2026-11-17 18:01 ` [PATCH mt76-next 06/19] wifi: mt76: mt7996: report radar on the channel context of its band Felix Fietkau
2026-11-17 18:01 ` [PATCH mt76-next 07/19] wifi: mt76: mt7996: stop WED before the DMA reset of a full reset Felix Fietkau
2026-11-18 8:38 ` Lorenzo Bianconi
2026-11-17 18:01 ` [PATCH mt76-next 08/19] wifi: mt76: skip the radiotap TLVs in mt76_skb_get_hdr() Felix Fietkau
2026-11-17 18:01 ` [PATCH mt76-next 09/19] wifi: mt76: find the first A-MSDU subframe behind the radiotap data Felix Fietkau
2026-11-18 8:43 ` Lorenzo Bianconi
2026-11-17 18:01 ` [PATCH mt76-next 10/19] wifi: mt76: mark all but the last subframe of an A-MSDU chain Felix Fietkau
2026-11-18 8:47 ` Lorenzo Bianconi
2026-11-17 18:01 ` [PATCH mt76-next 11/19] wifi: mt76: mt7996: set qos_ctl of a frame that hardware reordered Felix Fietkau
2026-11-18 8:50 ` Lorenzo Bianconi
2026-11-17 18:01 ` [PATCH mt76-next 12/19] wifi: mt76: check the PN of a BA session frame at its release Felix Fietkau
2026-11-18 8:55 ` Lorenzo Bianconi
2026-11-17 18:01 ` [PATCH mt76-next 13/19] wifi: mt76: check the RX PN of CCMP-256, GCMP and GCMP-256 keys Felix Fietkau
2026-11-17 18:01 ` [PATCH mt76-next 14/19] wifi: mt76: connac: return a negative error for a firmware status Felix Fietkau
2026-11-17 18:01 ` [PATCH mt76-next 15/19] wifi: mt76: guard the tx_list of every phy with one lock Felix Fietkau
2026-11-18 8:52 ` Lorenzo Bianconi
2026-11-17 18:01 ` Felix Fietkau [this message]
2026-11-17 18:01 ` [PATCH mt76-next 17/19] wifi: mt76: mt7925: do not take iflist_mtx under the mutex Felix Fietkau
2026-11-17 18:01 ` [PATCH mt76-next 18/19] wifi: mt76: mt7925: take each polled link under sta_poll_lock Felix Fietkau
2026-11-18 8:58 ` Lorenzo Bianconi
2026-11-17 18:01 ` [PATCH mt76-next 19/19] wifi: mt76: mt7615: take each polled station " Felix Fietkau
2026-11-18 8:57 ` Lorenzo Bianconi
2026-11-18 8:20 ` [PATCH mt76-next 01/19] wifi: mt76: don't pin undrainable PS stations in the tx scheduler Lorenzo Bianconi
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=20261117180134.2940930-16-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