All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ALSA: emu8000: sync the PCM emulation timer before freeing snd_emu8k_pcm (uaf from the in-flight softirq callback)
@ 2026-12-01 18:20 Hanxiang Xu
  2026-12-02  8:48 ` Takashi Iwai
  0 siblings, 1 reply; 3+ messages in thread
From: Hanxiang Xu @ 2026-12-01 18:20 UTC (permalink / raw)
  To: Takashi Iwai, Jaroslav Kysela; +Cc: linux-sound, linux-kernel

The emu8000 PCM emulation drives its period handling from a timer
that re-arms itself every jiffie (emu8k_pcm_timer_func() ->
mod_timer() inside the rec->timer_lock section).  Stopping the stream
uses the non-synchronizing timer_delete() (stop_voice()), which
cannot affect a callback instance that is already executing in
softirq context, and emu8k_pcm_close() then kfree()s rec with no
timer_delete_sync() and nothing stops a running instance from
re-arming.  An in-flight emu8k_pcm_timer_func() therefore continues
on freed memory: it dereferences rec->emu, locks the freed
rec->timer_lock, writes rec->period_pos, re-arms the freed timer (a
ghost timer firing every tick), and reads rec->substream for
snd_pcm_period_elapsed().  stop_voice() runs under the stream
spinlock, so the sync cannot be added there - but close() is process
context.

Gate the re-arm on rec->timer_running (under the rec->timer_lock that
stop_voice() already clears) and wait for an in-flight callback with
timer_delete_sync() before kfree(rec) in emu8k_pcm_close().

Cc: <stable@vger.kernel.org>
Signed-off-by: Hanxiang Xu <xuhx@hust.edu.cn>
---

 1 file changed, 4 insertions(+), 0 deletions(-)

diff --git a/sound/isa/sb/emu8000_pcm.c b/sound/isa/sb/emu8000_pcm.c
index d2ca70a..ec26705 100644
--- a/sound/isa/sb/emu8000_pcm.c
+++ b/sound/isa/sb/emu8000_pcm.c
@@ -187,6 +187,8 @@
 	bool period_elapsed = false;
 
 	scoped_guard(spinlock, &rec->timer_lock) {
+		if (!rec->timer_running)
+			return;
 		/* update the current pointer */
 		ptr = emu8k_get_curpos(rec, 0);
 		if (ptr < rec->last_ptr)
@@ -246,6 +248,8 @@
 static int emu8k_pcm_close(struct snd_pcm_substream *subs)
 {
 	struct snd_emu8k_pcm *rec = subs->runtime->private_data;
+
+	timer_delete_sync(&rec->timer);
 	kfree(rec);
 	subs->runtime->private_data = NULL;
 	return 0;
-- 
2.43.0


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

end of thread, other threads:[~2026-12-02  8:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-01 18:20 [PATCH] ALSA: emu8000: sync the PCM emulation timer before freeing snd_emu8k_pcm (uaf from the in-flight softirq callback) Hanxiang Xu
2026-12-02  8:48 ` Takashi Iwai
2026-12-02  8:52   ` Takashi Iwai

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.