From: sashiko-bot@kernel.org
To: "Hanxiang Xu" <xuhx@hust.edu.cn>
Cc: linux-sound@vger.kernel.org
Subject: Re: [PATCH] ALSA: sb: wait for the period timer before freeing the pcm private data
Date: Wed, 02 Dec 2026 03:25:45 +0000 [thread overview]
Message-ID: <sashiko-outbox-244776@kernel.org> (raw)
In-Reply-To: <20261202101107.1-1-xuhx@hust.edu.cn>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] ALSA: sb: incomplete timer sync and re-arm race in
emu8k_pcm_timer_func()
--
commit 16e83ea6e63d3c55432a440185c92457f6a2eb84
Author: Hanxiang Xu <xuhx@hust.edu.cn>
ALSA: sb: wait for the period timer before freeing the pcm private data
This commit adds a timer_shutdown_sync() call in emu8k_pcm_close() before
freeing the struct snd_emu8k_pcm instance.
> diff --git a/sound/isa/sb/emu8000_pcm.c b/sound/isa/sb/emu8000_pcm.c
> index d2ca70aad1621..3aeef313665e8 100644
> --- a/sound/isa/sb/emu8000_pcm.c
> +++ b/sound/isa/sb/emu8000_pcm.c
> @@ -246,6 +246,7 @@ static int emu8k_pcm_open(struct snd_pcm_substream *subs)
> static int emu8k_pcm_close(struct snd_pcm_substream *subs)
> {
> struct snd_emu8k_pcm *rec = subs->runtime->private_data;
> + timer_shutdown_sync(&rec->timer);
> kfree(rec);
> subs->runtime->private_data = NULL;
> return 0;
[Severity: High]
Does synchronizing the timer only in emu8k_pcm_close() leave
emu8k_pcm_timer_func() racing with stop_voice(), emu8k_pcm_hw_free() and
driver removal?
emu8k_pcm_timer_func() unconditionally calls mod_timer() under
rec->timer_lock without checking rec->timer_running:
CPU0 CPU1
<softirq> emu8k_pcm_trigger(STOP)
emu8k_pcm_timer_func() stop_voice()
spin_lock(&rec->timer_lock) spin_lock_irqsave(&rec->timer_lock)
(waits for lock) timer_delete(&rec->timer)
rec->timer_running = 0
spin_unlock_irqrestore(...)
mod_timer(&rec->timer, ...)
spin_unlock(&rec->timer_lock)
snd_pcm_period_elapsed(...) emu8k_pcm_hw_free()
stop_voice()
if (rec->timer_running) <-- false!
emu8k_close_dram(rec->emu)
snd_util_mem_free(..., rec->block)
Once rec->timer is re-armed with rec->timer_running set to 0, later
stop_voice() calls skip timer_delete(&rec->timer). The 1-jiffy timer
keeps firing and polling EMU8000_CCCA_READ while the stream is stopped,
and runs concurrently with emu8k_pcm_hw_free() (which runs before
emu8k_pcm_close() even during snd_pcm_release_substream()) and
emu8k_pcm_prepare().
In addition, if the driver is removed while userspace holds an open PCM
file descriptor, snd_emu8000_remove() -> snd_device_free() runs
snd_pcm_dev_disconnect() (which calls snd_pcm_stop() and
snd_pcm_sync_stop(), not emu8k_pcm_close()) and then frees the substream
in snd_pcm_free_stream(), so an in-flight or self-rearmed
emu8k_pcm_timer_func() still hits a use-after-free on rec->substream.
Checking rec->timer_running before mod_timer() in emu8k_pcm_timer_func()
and wiring up a .sync_stop callback in emu8k_pcm_ops that calls
timer_delete_sync(&rec->timer) would cover non-closing stops, hw_free,
and device disconnect as well.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261202101107.1-1-xuhx@hust.edu.cn?part=1
prev parent reply other threads:[~2026-12-02 3:25 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 2:11 [PATCH] ALSA: sb: wait for the period timer before freeing the pcm private data Hanxiang Xu
2026-12-02 3:25 ` sashiko-bot [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=sashiko-outbox-244776@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=xuhx@hust.edu.cn \
/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