* [PATCH] wifi: mt76: mt7925: fix NULL dereference in CSA worker
@ 2026-10-25 14:01 Gris Ge
0 siblings, 0 replies; only message in thread
From: Gris Ge @ 2026-10-25 14:01 UTC (permalink / raw)
To: Felix Fietkau, Lorenzo Bianconi, Ryder Lee, Matthias Brugger,
AngeloGioacchino Del Regno
Cc: Gris Ge, stable, Shayne Chen, Sean Wang, Ming Yen Hsieh,
Devin Wittmayer, Stella Liu, Leon Yen, linux-wireless,
linux-kernel, linux-arm-kernel, linux-mediatek
`mt7925_csa_work()` checks `dev->new_ctx` before taking `dev->mt76.mutex`,
but the pointer is re-read and dereferenced after
`mt792x_mutex_acquire()`. That check and the later use are not serialized
against a concurrent teardown, which can clear the pointer in between:
BUG: kernel NULL pointer dereference, address: 0000000000000000
RIP: 0010:mt7925_csa_work+0x83/0x160 [mt7925_common]
RAX: 0000000000000000
`mt7925_remove_chanctx()` clears `dev->new_ctx` without synchronization
against the worker. During a channel switch mac80211 frees the reserved
channel context (calling `drv_remove_chanctx()`) before
`drv_abort_channel_switch()`/unassign can cancel the worker, so it can run
with a context that was just cleared.
`mt7925_channel_switch_rx_beacon()` is serialized with the writers by the
wiphy mutex; the worker is not.
Protect `dev->new_ctx` with `dev->mt76.mutex` in add_chanctx() and
remove_chanctx(), and validate it under the lock in `mt7925_csa_work()`.
Keep a local pointer for both firmware calls so the context can neither
become NULL nor be freed while it is being used.
Reproduced the panic by injecting CSA-less "abort" beacon, works well
after patched.
Fixes: 7900da40e315 ("wifi: mt76: mt7925: introduce CSA support in non-MLO mode")
Cc: stable@vger.kernel.org # 7.1+
Signed-off-by: Gris Ge <cnfourt@gmail.com>
---
.../net/wireless/mediatek/mt76/mt7925/main.c | 30 +++++++++++--------
1 file changed, 18 insertions(+), 12 deletions(-)
diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/main.c b/drivers/net/wireless/mediatek/mt76/mt7925/main.c
index 15d95ad32636..fb5f9aa3534d 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7925/main.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7925/main.c
@@ -2020,7 +2020,9 @@ mt7925_add_chanctx(struct ieee80211_hw *hw,
{
struct mt792x_dev *dev = mt792x_hw_dev(hw);
+ mutex_lock(&dev->mt76.mutex);
dev->new_ctx = ctx;
+ mutex_unlock(&dev->mt76.mutex);
return 0;
}
@@ -2031,9 +2033,10 @@ mt7925_remove_chanctx(struct ieee80211_hw *hw,
{
struct mt792x_dev *dev = mt792x_hw_dev(hw);
+ mutex_lock(&dev->mt76.mutex);
if (dev->new_ctx == ctx)
dev->new_ctx = NULL;
-
+ mutex_unlock(&dev->mt76.mutex);
}
static void
@@ -2509,11 +2512,13 @@ static int mt7925_switch_vif_chanctx(struct ieee80211_hw *hw,
void mt7925_csa_work(struct work_struct *work)
{
+ struct ieee80211_chanctx_conf *ctx;
struct mt792x_vif *mvif;
struct mt792x_dev *dev;
struct ieee80211_vif *vif;
struct ieee80211_bss_conf *link_conf;
struct mt792x_bss_conf *mconf;
+ bool roc_started;
u8 link_id, roc_rtype;
int ret = 0;
@@ -2525,26 +2530,27 @@ void mt7925_csa_work(struct work_struct *work)
if (ieee80211_vif_is_mld(vif))
return;
- if (!dev->new_ctx)
- return;
-
link_id = 0;
mconf = &mvif->bss_conf;
link_conf = &vif->bss_conf;
roc_rtype = MT7925_ROC_REQ_JOIN;
mt792x_mutex_acquire(dev);
- ret = mt7925_set_roc(mvif->phy, mconf, dev->new_ctx->def.chan,
- 4000, roc_rtype);
- mt792x_mutex_release(dev);
- if (!ret) {
- mt792x_mutex_acquire(dev);
- ret = mt7925_mcu_set_chctx(mvif->phy->mt76, &mconf->mt76, link_conf,
- dev->new_ctx);
+ ctx = dev->new_ctx;
+ if (!ctx) {
mt792x_mutex_release(dev);
+ return;
+ }
+ ret = mt7925_set_roc(mvif->phy, mconf, ctx->def.chan, 4000, roc_rtype);
+ roc_started = !ret;
+ if (!ret)
+ ret = mt7925_mcu_set_chctx(mvif->phy->mt76, &mconf->mt76, link_conf,
+ ctx);
+ mt792x_mutex_release(dev);
+
+ if (roc_started)
mt7925_abort_roc(mvif->phy, mconf);
- }
ieee80211_chswitch_done(vif, !ret, link_id);
}
--
2.56.0
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-10-25 14:02 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-25 14:01 [PATCH] wifi: mt76: mt7925: fix NULL dereference in CSA worker Gris Ge
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®