Re: [PATCH] ALSA: emu8000: pin the module while an emu8k PCM runtime exists
From: Takashi Iwai
Date: Wed Dec 02 2026 - 03:48:19 EST
On Tue, 01 Dec 2026 19:19:39 +0100,
Hanxiang Xu wrote:
>
> snd_emu8000_pcm_new() creates a PCM device on the host sound card
> from the snd_emu8000_synth seq driver, and snd_emu8000_remove() frees
> it again with snd_device_free(dev->card, hw->pcm) unconditionally.
> An fd on /dev/snd/pcmC*D1p only pins the host card module
> (try_module_get(pcm->card->module) in snd_pcm_open), so
> `rmmod snd_emu8000_synth` runs snd_emu8000_remove() while the fd is
> open: snd_pcm_dev_disconnect() stops the streams and unregisters the
> device, snd_pcm_free() kfrees every substream and the snd_pcm itself,
> and the fd's final close() then walks the freed pcm_file->substream,
> substream->pcm and pcm->open_mutex (and calls substream->ops->close,
> which points into the unloaded module).
>
> Pin snd-emu8000-synth with try_module_get(THIS_MODULE) in
> emu8k_pcm_open() and drop it in emu8k_pcm_close(), so `rmmod` returns
> EBUSY instead of running snd_emu8000_remove() under an open fd.
>
> Also reproduced on 7.4.0-rc5: 12 reports (slab-use-after-free in
> snd_pcm_release, slab-out-of-bounds in snd_power_ref_and_wait) with a
> KASAN kernel; orderly teardown without an open fd is clean.
>
> Cc: <stable@xxxxxxxxxxxxxxx>
> Signed-off-by: Hanxiang Xu <xuhx@xxxxxxxxxxx>
Although this doesn't cover fully, it's still a bit of improvement on
safety, so I applied to for-next branch now.
thanks,
Takashi