From: Gris Ge <cnfourt@gmail.com>
To: Felix Fietkau <nbd@nbd.name>,
Lorenzo Bianconi <lorenzo@kernel.org>,
Ryder Lee <ryder.lee@mediatek.com>,
Matthias Brugger <matthias.bgg@gmail.com>,
AngeloGioacchino Del Regno
<angelogioacchino.delregno@collabora.com>
Cc: Gris Ge <cnfourt@gmail.com>,
stable@vger.kernel.org, Shayne Chen <shayne.chen@mediatek.com>,
Sean Wang <sean.wang@mediatek.com>,
Ming Yen Hsieh <mingyen.hsieh@mediatek.com>,
Devin Wittmayer <lucid_duck@justthetip.ca>,
Stella Liu <yu-ching.liu@mediatek.com>,
Leon Yen <leon.yen@mediatek.com>,
linux-wireless@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-mediatek@lists.infradead.org
Subject: [PATCH] wifi: mt76: mt7925: fix NULL dereference in CSA worker
Date: Sun, 25 Oct 2026 22:01:18 +0800 [thread overview]
Message-ID: <20261025140123.12056-1-cnfourt@gmail.com> (raw)
`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
reply other threads:[~2026-10-25 14:02 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261025140123.12056-1-cnfourt@gmail.com \
--to=cnfourt@gmail.com \
--cc=angelogioacchino.delregno@collabora.com \
--cc=leon.yen@mediatek.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=linux-wireless@vger.kernel.org \
--cc=lorenzo@kernel.org \
--cc=lucid_duck@justthetip.ca \
--cc=matthias.bgg@gmail.com \
--cc=mingyen.hsieh@mediatek.com \
--cc=nbd@nbd.name \
--cc=ryder.lee@mediatek.com \
--cc=sean.wang@mediatek.com \
--cc=shayne.chen@mediatek.com \
--cc=stable@vger.kernel.org \
--cc=yu-ching.liu@mediatek.com \
/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
all inboxes | Powered by JetHome®