The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] ALSA: ctxfi: Fix UAF when freeing a running system timer
@ 2026-11-26 11:20 徐晗翔
  2026-11-26 11:40 ` Takashi Iwai
  0 siblings, 1 reply; 2+ messages in thread
From: 徐晗翔 @ 2026-11-26 11:20 UTC (permalink / raw)
  To: Takashi Iwai, Jaroslav Kysela; +Cc: linux-sound, linux-kernel

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@vger.kernel.org>
Signed-off-by: Hanxiang Xu <xuhx@hust.edu.cn>
---
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
--- a/sound/pci/ctxfi/cttimer.c
+++ b/sound/pci/ctxfi/cttimer.c
@@ -111,11 +111,17 @@

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,

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

* Re: [PATCH] ALSA: ctxfi: Fix UAF when freeing a running system timer
  2026-11-26 11:20 [PATCH] ALSA: ctxfi: Fix UAF when freeing a running system timer 徐晗翔
@ 2026-11-26 11:40 ` Takashi Iwai
  0 siblings, 0 replies; 2+ messages in thread
From: Takashi Iwai @ 2026-11-26 11:40 UTC (permalink / raw)
  To: 徐晗翔
  Cc: Takashi Iwai, Jaroslav Kysela, linux-sound, linux-kernel

On Thu, 26 Nov 2026 12:20:28 +0100,
徐晗翔 wrote:
> 
> 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@vger.kernel.org>
> Signed-off-by: Hanxiang Xu <xuhx@hust.edu.cn>

Now better, but not quite yet.  You've put two blank lines in the
above, and it can be a single blank line.
Also, it'd be helpful if you use the same From: tag as Signed-off-by:
tag.

But, the biggest problem is ...

> ---
> 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
> --- a/sound/pci/ctxfi/cttimer.c
> +++ b/sound/pci/ctxfi/cttimer.c
> @@ -111,11 +111,17 @@
> 
> 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,

... your mailer broke the spaces and tabs completely, hence the patch
can't be applied cleanly at all.  Please try to fix your mailer setup
and resubmit.  Or, at best, use git send-email for submission.

It's better if you can test submission and verify in your side at
first; i.e. try to submit to yourself, and test whether your can apply
it via "git am".

Last but not least, at the next submission, use either "v2" or
"RESEND" prefix to indicate it's a resending to the subject, e.g.
  Subject: [PATCH RESEND] ALSA ctxfi: ....


thanks,

Takashi

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

end of thread, other threads:[~2026-11-26 11:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-26 11:20 [PATCH] ALSA: ctxfi: Fix UAF when freeing a running system timer 徐晗翔
2026-11-26 11:40 ` Takashi Iwai

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