Skip to contentSkip to conversation

ath9k: delete channel-context timers on deinit

PATCH Superseded Rosen Penev 3 participants 3 messages Sep 4 – Sep 11 Qualcomm Atheros ATH9K wireless driver

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ath9k: delete channel-context timers on deinit

ath9k_deinit_channel_context() cancels chanctx_work but does not delete the offchannel and sched timers set up by ath9k_init_channel_context(). If either timer fires after deinit (e.g. during driver unload or suspend), it accesses sc->sc_ah which may already be freed by ath9k_hw_deinit(), causing a use-after-free.

Delete both timers with timer_delete_sync() before cancelling the work item.

Assisted-by opencode:big-pickle
---
 drivers/net/wireless/ath/ath9k/channel.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/net/wireless/ath/ath9k/channel.c +2 -0
index 8b27d8cc086a..92241c24a0a4 100644
@@ -1363,6 +1363,8 @@ void ath9k_init_channel_context(struct ath_softc *sc)
 
 void ath9k_deinit_channel_context(struct ath_softc *sc)
 {
+	timer_delete_sync(&sc->sched.timer);
+	timer_delete_sync(&sc->offchannel.timer);
 	cancel_work_sync(&sc->chanctx_work);
 }
 
Signature · 1 line
2.55.0
#1 lore raw
Quoted 8 lines · Rosen Penev

ath9k_deinit_channel_context() cancels chanctx_work but does not delete the offchannel and sched timers set up by ath9k_init_channel_context(). If either timer fires after deinit (e.g. during driver unload or suspend), it accesses sc->sc_ah which may already be freed by ath9k_hw_deinit(), causing a use-after-free.

Delete both timers with timer_delete_sync() before cancelling the work item.

From the documentation of that function:

* This function cannot guarantee that the timer is not rearmed again by
* some concurrent or preempting code, right after it dropped the base
* lock. If there is the possibility of a concurrent rearm then the return
* value of the function is meaningless.
*
* If such a guarantee is needed, e.g. for teardown situations then use
* timer_shutdown_sync() instead.

AFAICT, the timer callbacks can re-arm the timer, so this should be using timer_shutdown_sync() instead.

-Toke

#2 lore raw
In reply to Rosen Penev
Quoted 10 lines · Rosen Penev

ath9k_deinit_channel_context() cancels chanctx_work but does not delete the offchannel and sched timers set up by ath9k_init_channel_context(). If either timer fires after deinit (e.g. during driver unload or suspend), it accesses sc->sc_ah which may already be freed by ath9k_hw_deinit(), causing a use-after-free.

Delete both timers with timer_delete_sync() before cancelling the work item.

Assisted-by opencode:big-pickle

Current guidance is to just have Assisted-by: LLM
https://docs.kernel.org/process/coding-assistants.html#attribution