Re: [PATCH] ALSA: emu8000: sync the PCM emulation timer before freeing snd_emu8k_pcm (uaf from the in-flight softirq callback)
From: Takashi Iwai
Date: Wed Dec 02 2026 - 03:48:41 EST
On Tue, 01 Dec 2026 19:20:39 +0100,
Hanxiang Xu wrote:
>
> 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@xxxxxxxxxxxxxxx>
> Signed-off-by: Hanxiang Xu <xuhx@xxxxxxxxxxx>
Applied to for-next branch. Thanks.
Takashi