[PATCH v2] ALSA: ctxfi: wait for a running system-timer callback in the free path
From: Hanxiang Xu
Date: Thu Nov 26 2026 - 07:36:08 EST
Currently, ct_systimer_free is aliased to ct_systimer_prepare, which
calls timer_delete_sync_try(). While ct_systimer_prepare() must remain
non-sleeping because it can run under the PCM stream lock, using
timer_delete_sync_try() in the free path is unsafe: if the timer
callback is concurrently running on another CPU, timer_delete_sync_try()
returns -1 without waiting for completion. The caller then proceeds to
free the ct_timer_instance object, resulting in a use-after-free in the
still-running timer callback.
Replace the ct_systimer_free macro with a dedicated function that calls
timer_shutdown_sync(), which waits for any running callback to finish
and prevents the timer from being rearmed before the instance is freed.
Cc: <stable@xxxxxxxxxxxxxxx>
Signed-off-by: Hanxiang Xu <xuhx@xxxxxxxxxxx>
---
Changes in v2:
- Set From: to Hanxiang Xu <xuhx@xxxxxxxxxxx> matching Signed-off-by:
- Use a single blank line before Cc: <stable@xxxxxxxxxxxxxxx>
- Format cleanly with git format-patch to preserve tabs and spacing
sound/pci/ctxfi/cttimer.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/sound/pci/ctxfi/cttimer.c b/sound/pci/ctxfi/cttimer.c
index 9d6f5df..fea9d61 100644
--- a/sound/pci/ctxfi/cttimer.c
+++ b/sound/pci/ctxfi/cttimer.c
@@ -111,11 +111,17 @@ static void ct_systimer_stop(struct ct_timer_instance *ti)
static void ct_systimer_prepare(struct ct_timer_instance *ti)
{
+ /* non-sleeping: also runs under the PCM stream lock */
ct_systimer_stop(ti);
timer_delete_sync_try(&ti->timer);
}
-#define ct_systimer_free ct_systimer_prepare
+static void ct_systimer_free(struct ct_timer_instance *ti)
+{
+ /* may sleep: wait for a callback running on another CPU */
+ ct_systimer_stop(ti);
+ timer_shutdown_sync(&ti->timer);
+}
static const struct ct_timer_ops ct_systimer_ops = {
.init = ct_systimer_init,
--
2.43.0