Re: [PATCH 0/2] ALSA: emux: fix use-after-free of soundfont zones/samples between snd_emux_note_on() and soundfont removal paths (UAF)
From: Takashi Iwai
Date: Tue Dec 01 2026 - 01:37:47 EST
On Tue, 01 Dec 2026 04:22:23 +0100,
徐晗翔 wrote:
>
> snd_emux_note_on() obtains raw struct snd_sf_zone pointers from
> snd_soundfont_search_zone(), which drops sflist->lock on return, and
> then consumes them (exclusive-class read, sample/block chaining, a
> 92-byte register copy) with no lock, no reference count and no RCU
> protection, while four user-reachable soundfont removal paths
> (hwdep SNDRV_EMUX_IOCTL_REMOVE_LAST_SAMPLES / RESET_SAMPLES /
> LOAD_PATCH(REMOVE_INFO) and OSS SNDCTL_SEQ_RESETSAMPLES) kfree() the
> very same zones, samples and util-mem blocks under a disjoint mutex.
> The two sides share no lock domain (presets_mutex vs voice_lock), and
> the emu10k1 backend additionally keeps already-playing voices pointed
> at freed blocks because emu10k1_ops has no .sample_reset callback.
>
> Verified on mainline 7.3 with a KASAN kernel and the real in-tree
> snd-emux-synth module driven through its exported API (harness
> attached): an uninstrumented natural hammer (userspace soundfont
> load/unload loop through the real hwdep ioctl path vs kernel note_on
> loop) produced 133 slab-use-after-free reports in 25s across four
> distinct read points inside snd_emux_note_on(), with a closed
> alloc/free/use chain (alloc = sf_zone_new <- load_info <-
> snd_soundfont_load <- snd_emux_hwdep_ioctl <- real userspace ioctl;
> free = kfree <- snd_soundfont_remove_unlocked; use = snd_emux_note_on
> +0x225/0x75f/0x772/0x7ab). A controlled one-shot that parks note_on
> inside its window reproduces deterministically (6 reports). The
> in-flight window needs no privileges beyond access to the sound
> devices; consequences are kernel memory corruption (UAF reads plus a
> UAF write through the block pointer) and crashes.
>
> The detailed description:
>
> * Test environment / affected version
>
> Linux version 7.3.0 (gcc 13.3.0, GNU ld 2.42) #6 SMP
> PREEMPT_DYNAMIC -- vanilla mainline 7.3 tree, unmodified sources;
> KASAN enabled, QEMU/KVM x86_64 guest. The audited files
> (sound/synth/emux/*, sound/synth/util_mem.c,
> sound/pci/emu10k1/emu10k1_callback.c) are byte-identical between the
> tested tree and the report baseline. The bug predates 7.3 by many
> years (the emux split-probe model and the unlocked search are
> essentially unchanged since the 2.6 emux import); line numbers below
> are from 7.3.
7.3.0 is way too old for this kind of bug hunts via AI.
Could you verify the whole series (and your other patches) at least
with 7.4-rc5? At best with the latest linux-next tree, as some fixes
are postponed to 7.5. This may save a waste of time for both of us.
thanks,
Takashi