FAILED: patch "[PATCH] ALSA: emux: Fix UAF of soundfont zones at note-on" failed to apply to 6.12-stable tree
Subsystems (2)
Sasha Levin
maintainerThe patch below does not apply to the 6.12-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.12.y
git checkout FETCH_HEAD
git cherry-pick -x 34e3e04b8a1731a773797542f0781e99ce7cd755
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '[email protected]' --subject-prefix 'PATCH 6.12.y' 'HEAD^..'
Thanks,
Sasha
------------------ original commit in Linus's tree ------------------
From 34e3e04b8a1731a773797542f0781e99ce7cd755 Mon Sep 17 00:00:00 2001
From: Takashi Iwai <[email protected]>
Date: Tue, 20 Oct 2026 12:16:20 +0200
Subject: [PATCH] ALSA: emux: Fix UAF of soundfont zones at note-on
snd_emux_note_on() looks up the matching zones via snd_soundfont_search_zone(), which takes sflist->lock only during the lookup and returns the raw zone pointers after releasing it. The caller then stores them in vp->zone without any protection. Meanwhile, a concurrent SNDRV_EMUX_IOCTL_REMOVE_LAST_SAMPLES ioctl may unlink and free those zones in snd_soundfont_remove_unlocked(); this leads to a use-after-free in snd_emux_note_on(), and later at accessing the cached vp->zone, e.g. in snd_emux_send_effect().
Fix it by holding sflist->lock in snd_emux_note_on() over the whole zone lookup and voice setup, and let snd_soundfont_search_zone() require the caller to hold the lock, instead. snd_soundfont_lock_preset() takes sflist->lock for setting presets_locked, so the removal path now syncs with the note-on finish.
--- sound/synth/emux/emux_synth.c | 3 +++ sound/synth/emux/soundfont.c | 9 ++++++--- 2 files changed, 9 insertions(+), 3 deletions(-)
sound/synth/emux/emux_synth.c +3 -0
@@ -60,6 +60,9 @@ snd_emux_note_on(void *p, int note, int vel, struct snd_midi_channel *chan)return ; key = note;/* remember the original note */ + +/* hold sflist->lock for protecting against concurrent free */ +guard (spinlock_irqsave)(&emu->sflist->lock); nvoices =get_zone (emu, port, ¬e, vel, chan, table);if (! nvoices)return ;
sound/synth/emux/soundfont.c +6 -3
@@ -1225,6 +1225,9 @@ delete_preset(struct snd_sf_list *sflist, struct snd_sf_zone *zp)* The found zones are stored on 'table' array. max_layers defines * the maximum number of elements in this array. * This function returns the number of found zones. 0 if not found. +* +* The caller must hold sflist->lock, and keep holding it as long as +* the returned zones are accessed. */ int snd_soundfont_search_zone(struct snd_sf_list *sflist, int *notep, int vel,
@@ -1234,11 +1237,11 @@ snd_soundfont_search_zone(struct snd_sf_list *sflist, int *notep, int vel, {int nvoices; -/* this function is supposed to be called atomically, -* so we check the lock. if it's busy, just returns 0 to +lockdep_assert_held (&sflist->lock); + +/* if the presets are being modified, just returns 0 to * tell the caller the busy state */ -guard (spinlock_irqsave)(&sflist->lock);if (sflist->presets_locked)return 0 ; nvoices = search_zones(sflist, notep, vel, preset, bank,
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 1/2 ALSA: synth: Use guard() for spin locks
From: Takashi Iwai <[email protected]>
[ Upstream commit 59ede7178d402b3bfa0266cbd9ad348d5612c295 ]
Clean up the code using guard() for spin locks.
Merely code refactoring, and no behavior change.
Stable-dep-of: 34e3e04b8a17 ("ALSA: emux: Fix UAF of soundfont zones at note-on")
--- sound/synth/emux/emux_effect.c | 29 ++++++++-------- sound/synth/emux/emux_synth.c | 54 +++++++---------------------- sound/synth/emux/soundfont.c | 63 ++++++++++++---------------------- 3 files changed, 49 insertions(+), 97 deletions(-)
sound/synth/emux/emux_effect.c +14 -15
@@ -168,7 +168,6 @@ snd_emux_send_effect(struct snd_emux_port *port, struct snd_midi_channel *chan,unsigned char *srcp, *origp;struct snd_emux *emu;struct snd_emux_effect_table *fx; -unsigned long flags; emu = port->emu; fx = chan->private;
@@ -195,22 +194,22 @@ snd_emux_send_effect(struct snd_emux_port *port, struct snd_midi_channel *chan, offset++;#endif /* modify the register values */ -spin_lock_irqsave (&emu->voice_lock, flags); -for (i =0 ; i < emu->max_voices; i++) { -struct snd_emux_voice *vp = &emu->voices[i]; -if (!STATE_IS_PLAYING (vp->state) || vp->chan != chan) -continue ; - srcp = (unsigned char *)&vp->reg.parm + offset; - origp = (unsigned char *)&vp->zone->v.parm + offset; -if (parm_defs[i].type &PARM_IS_BYTE ) { - *srcp = *origp; -effect_set_byte (srcp, chan, type); - }else { - *(unsigned short *)srcp = *(unsigned short *)origp; -effect_set_word ((unsigned short *)srcp, chan, type); + scoped_guard(spinlock_irqsave, &emu->voice_lock) { +for (i =0 ; i < emu->max_voices; i++) { +struct snd_emux_voice *vp = &emu->voices[i]; +if (!STATE_IS_PLAYING (vp->state) || vp->chan != chan) +continue ; + srcp = (unsigned char *)&vp->reg.parm + offset; + origp = (unsigned char *)&vp->zone->v.parm + offset; +if (parm_defs[i].type &PARM_IS_BYTE ) { + *srcp = *origp; +effect_set_byte (srcp, chan, type); + }else { + *(unsigned short *)srcp = *(unsigned short *)origp; +effect_set_word ((unsigned short *)srcp, chan, type); + } } } -spin_unlock_irqrestore (&emu->voice_lock, flags);/* activate them */ snd_emux_update_channel (port, chan, parm_defs[type].update);
sound/synth/emux/emux_synth.c +13 -41
250 lines not on this page · raw message
sound/synth/emux/soundfont.c +22 -41
136 lines not on this page · raw message
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 2/2 ALSA: emux: Fix UAF of soundfont zones at note-on
From: Takashi Iwai <[email protected]>
[ Upstream commit 34e3e04b8a1731a773797542f0781e99ce7cd755 ]
snd_emux_note_on() looks up the matching zones via snd_soundfont_search_zone(), which takes sflist->lock only during the lookup and returns the raw zone pointers after releasing it. The caller then stores them in vp->zone without any protection. Meanwhile, a concurrent SNDRV_EMUX_IOCTL_REMOVE_LAST_SAMPLES ioctl may unlink and free those zones in snd_soundfont_remove_unlocked(); this leads to a use-after-free in snd_emux_note_on(), and later at accessing the cached vp->zone, e.g. in snd_emux_send_effect().
Fix it by holding sflist->lock in snd_emux_note_on() over the whole zone lookup and voice setup, and let snd_soundfont_search_zone() require the caller to hold the lock, instead. snd_soundfont_lock_preset() takes sflist->lock for setting presets_locked, so the removal path now syncs with the note-on finish.
--- sound/synth/emux/emux_synth.c | 3 +++ sound/synth/emux/soundfont.c | 9 ++++++--- 2 files changed, 9 insertions(+), 3 deletions(-)
sound/synth/emux/emux_synth.c +3 -0
@@ -60,6 +60,9 @@ snd_emux_note_on(void *p, int note, int vel, struct snd_midi_channel *chan)return ; key = note;/* remember the original note */ + +/* hold sflist->lock for protecting against concurrent free */ +guard (spinlock_irqsave)(&emu->sflist->lock); nvoices =get_zone (emu, port, ¬e, vel, chan, table);if (! nvoices)return ;
sound/synth/emux/soundfont.c +6 -3
@@ -1264,6 +1264,9 @@ delete_preset(struct snd_sf_list *sflist, struct snd_sf_zone *zp)* The found zones are stored on 'table' array. max_layers defines * the maximum number of elements in this array. * This function returns the number of found zones. 0 if not found. +* +* The caller must hold sflist->lock, and keep holding it as long as +* the returned zones are accessed. */ int snd_soundfont_search_zone(struct snd_sf_list *sflist, int *notep, int vel,
@@ -1273,11 +1276,11 @@ snd_soundfont_search_zone(struct snd_sf_list *sflist, int *notep, int vel, {int nvoices; -/* this function is supposed to be called atomically, -* so we check the lock. if it's busy, just returns 0 to +lockdep_assert_held (&sflist->lock); + +/* if the presets are being modified, just returns 0 to * tell the caller the busy state */ -guard (spinlock_irqsave)(&sflist->lock);if (sflist->presets_locked)return 0 ; nvoices = search_zones(sflist, notep, vel, preset, bank,
Signature · 1 line
2.53.0