From: Takashi Iwai <tiwai@suse.de>
To: Norbert Szetei <norbert@doyensec.com>
Cc: linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org,
Takashi Iwai <tiwai@suse.de>
Subject: Re: [PATCH 1/2] ALSA: timer: don't re-enter an instance callback that is still running
Date: Mon, 20 Jul 2026 10:18:43 +0200 [thread overview]
Message-ID: <87h5luqdjw.wl-tiwai@suse.de> (raw)
In-Reply-To: <6F9B6501-8E65-4265-B02C-7EFB240D1664@doyensec.com>
On Mon, 20 Jul 2026 09:09:55 +0200,
Norbert Szetei wrote:
>
> The userspace-driven timer (utimer) TRIGGER ioctl calls
> snd_timer_interrupt() directly with no serialization, so two threads
> triggering the same utimer can run snd_timer_interrupt() on one
> snd_timer concurrently.
>
> snd_timer_process_callbacks() drops timer->lock around each instance
> callback and marks the in-flight callback with the single
> SNDRV_TIMER_IFLG_CALLBACK bit; snd_timer_close_locked() waits on that
> bit to drain an in-flight callback before freeing the instance. The bit
> cannot represent two concurrent callbacks: when a second interrupt
> re-queues an instance whose callback is still running, both run at once,
> the first to finish clears the bit, and the close-path drain then frees
> the instance (and its callback_data) while the other callback is still
> live - a use-after-free reachable by any user able to open
> /dev/snd/timer, both via a user timer instance and via a sequencer queue
> timer bound to the utimer.
>
> snd_timer_interrupt() sets IFLG_CALLBACK before dropping timer->lock, so
> a concurrent interrupt already observes it under the lock. Skip
> re-queuing an instance (and its slaves) to the ack/sack list while its
> callback is in flight; the accumulated pticks are delivered on the next
> tick, so no event is lost.
>
> Fixes: 37745918e0e7 ("ALSA: timer: Introduce virtual userspace-driven timers")
> Cc: <stable@vger.kernel.org>
> Suggested-by: Takashi Iwai <tiwai@suse.de>
> Assisted-by: Claude:claude-opus-4-8
> Signed-off-by: Norbert Szetei <norbert@doyensec.com>
Applied both patches now. Thanks.
Takashi
prev parent reply other threads:[~2026-07-20 8:18 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-20 7:09 [PATCH 1/2] ALSA: timer: don't re-enter an instance callback that is still running Norbert Szetei
2026-07-20 7:14 ` [PATCH 2/2] ALSA: timer: drain a slave's callback before its master detaches it Norbert Szetei
2026-07-20 8:18 ` Takashi Iwai [this message]
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=87h5luqdjw.wl-tiwai@suse.de \
--to=tiwai@suse.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=norbert@doyensec.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