Linux kernel -stable discussions
 help / color / mirror / Atom feed
* [PATCH 6.6.y] wifi: mt76: mt7915: clear wcid mask under mutex after RCU pointer clear
@ 2026-11-26 12:24 Dickson Wu via B4 Relay
  2026-11-27 17:01 ` Sasha Levin
  0 siblings, 1 reply; 2+ messages in thread
From: Dickson Wu via B4 Relay @ 2026-11-26 12:24 UTC (permalink / raw)
  To: stable; +Cc: Felix Fietkau, Lorenzo Bianconi, linux-wireless

From: Felix Fietkau <nbd@nbd.name>

commit 6486e11a6e2f679597af2d5bb48c3b07a2b2a7ba upstream.

mt7915_remove_interface() cleared the wcid mask bit with no lock held and
before clearing the RCU wcid pointer. The mask is a non-atomic RMW shared
with the allocators, which all run under dev->mt76.mutex; on DBDC the two
wiphys share one mt76_dev, so this raced add_interface/sta_add on the
other band and could leak or double-hand-out a wcid. Clearing the bit
before the RCU pointer also let a concurrent allocation reuse the index
and publish its wcid, which the subsequent NULL assignment then wiped.
Move the clear into the existing mutex section, after the RCU pointer is
cleared.

Fixes: f3049b88b2b3 ("wifi: mt76: mt7915: allocate vif wcid in the same range as stations")
Link: https://patch.msgid.link/20260722082610.2699628-8-nbd@nbd.name
Signed-off-by: Felix Fietkau <nbd@nbd.name>
[ adapted to 6.6.y: context only, older mt7915_mcu_add_sta() call ]
Signed-off-by: Dickson Wu <dickson.wu@certik.com>
---
6.12.y and newer already have this fix. The moved line is the same as
upstream; only the surrounding context differs on this branch.

Tested on v6.6.163:
- x86_64 allmodconfig W=1 build of
  drivers/net/wireless/mediatek/mt76/mt7915/main.o, base vs patched,
  no new warnings
- booted the patched kernel with CONFIG_MT7915E=y under QEMU/KVM. I
  don't have mt7915 hardware, so the remove path wasn't run.

The backport and the test runs were prepared with AI coding tools
(OpenAI Codex agents, with review by Claude). I went over the result
before signing off.
---
 drivers/net/wireless/mediatek/mt76/mt7915/main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/main.c b/drivers/net/wireless/mediatek/mt76/mt7915/main.c
index 864f636666e5..017181c1a2ea 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7915/main.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7915/main.c
@@ -306,7 +306,6 @@ static void mt7915_remove_interface(struct ieee80211_hw *hw,
 
 	mt7915_mcu_add_bss_info(phy, vif, false);
 	mt7915_mcu_add_sta(dev, vif, NULL, false);
-	mt76_wcid_mask_clear(dev->mt76.wcid_mask, mvif->sta.wcid.idx);
 
 	mutex_lock(&dev->mt76.mutex);
 	mt76_testmode_reset(phy->mt76, true);
@@ -322,6 +321,7 @@ static void mt7915_remove_interface(struct ieee80211_hw *hw,
 	mutex_lock(&dev->mt76.mutex);
 	dev->mt76.vif_mask &= ~BIT_ULL(mvif->mt76.idx);
 	phy->omac_mask &= ~BIT_ULL(mvif->mt76.omac_idx);
+	mt76_wcid_mask_clear(dev->mt76.wcid_mask, mvif->sta.wcid.idx);
 	mutex_unlock(&dev->mt76.mutex);
 
 	spin_lock_bh(&dev->mt76.sta_poll_lock);

---
base-commit: e2bb30811e063ce0db964484357973b855b06572
change-id: 20261126-so1-mt-66-a159fb8fb163

Best regards,
--  
Dickson Wu <dickson.wu@certik.com>



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH 6.6.y] wifi: mt76: mt7915: clear wcid mask under mutex after RCU pointer clear
  2026-11-26 12:24 [PATCH 6.6.y] wifi: mt76: mt7915: clear wcid mask under mutex after RCU pointer clear Dickson Wu via B4 Relay
@ 2026-11-27 17:01 ` Sasha Levin
  0 siblings, 0 replies; 2+ messages in thread
From: Sasha Levin @ 2026-11-27 17:01 UTC (permalink / raw)
  To: stable
  Cc: Sasha Levin, Felix Fietkau, Lorenzo Bianconi, linux-wireless,
	Dickson Wu via B4 Relay, Dickson Wu

> mt7915_remove_interface() cleared the wcid mask bit with no lock held and
> before clearing the RCU wcid pointer.

Queued for 6.6 and 6.1, thanks.

-- 
Thanks,
Sasha

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-27 17:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-26 12:24 [PATCH 6.6.y] wifi: mt76: mt7915: clear wcid mask under mutex after RCU pointer clear Dickson Wu via B4 Relay
2026-11-27 17:01 ` Sasha Levin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox