mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] ALSA: emux: expose the hwdep device only after ports are initialized
@ 2026-12-02  2:13 Hanxiang Xu
  2026-12-02  9:01 ` Takashi Iwai
  0 siblings, 1 reply; 2+ messages in thread
From: Hanxiang Xu @ 2026-12-02  2:13 UTC (permalink / raw)
  To: Takashi Iwai, Jaroslav Kysela; +Cc: linux-sound, linux-kernel

snd_emux_register() creates and registers the hwdep device
(snd_emux_init_hwdep() -> snd_card_register()) before
snd_emux_init_seq() fills emu->portptrs[], and ignores the init_seq()
return value.  A SNDRV_EMUX_IOCTL_MISC_MODE ioctl arriving inside that
window walks emu->portptrs[i]->ctrls[] with portptrs[i] == NULL and
causes a near-NULL kernel write (dynamically confirmed on v7.4-rc5);
a failed sequencer setup additionally leaves the already-registered
hwdep behind for the probe error path to free with possibly-open fds.

Initialize the ports (and OSS/virmidi) first and create the hwdep
device last, so the device only becomes visible to userspace after
everything its ioctls touch is initialized, and propagate the
snd_emux_init_seq() error.

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

 sound/synth/emux/emux.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/sound/synth/emux/emux.c b/sound/synth/emux/emux.c
index 4352c57..518019e 100644
--- a/sound/synth/emux/emux.c
+++ b/sound/synth/emux/emux.c
@@ -107,18 +107,19 @@ int snd_emux_register(struct snd_emux *emu, struct snd_card *card, int index, ch
 	if (emu->sflist == NULL)
 		return -ENOMEM;
 
-	err = snd_emux_init_hwdep(emu);
-	if (err < 0)
-		return err;
-
 	snd_emux_init_voices(emu);
 
-	snd_emux_init_seq(emu, card, index);
+	if (snd_emux_init_seq(emu, card, index) < 0)
+		return -ENODEV;
 #if IS_ENABLED(CONFIG_SND_SEQUENCER_OSS)
 	snd_emux_init_seq_oss(emu);
 #endif
 	snd_emux_init_virmidi(emu, card);
 
+	err = snd_emux_init_hwdep(emu);
+	if (err < 0)
+		return err;
+
 	snd_emux_proc_init(emu, card, index);
 	return 0;
 }
-- 
2.43.0


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

* Re: [PATCH] ALSA: emux: expose the hwdep device only after ports are initialized
  2026-12-02  2:13 [PATCH] ALSA: emux: expose the hwdep device only after ports are initialized Hanxiang Xu
@ 2026-12-02  9:01 ` Takashi Iwai
  0 siblings, 0 replies; 2+ messages in thread
From: Takashi Iwai @ 2026-12-02  9:01 UTC (permalink / raw)
  To: Hanxiang Xu; +Cc: Takashi Iwai, Jaroslav Kysela, linux-sound, linux-kernel

On Wed, 02 Dec 2026 03:13:02 +0100,
Hanxiang Xu wrote:
> 
> snd_emux_register() creates and registers the hwdep device
> (snd_emux_init_hwdep() -> snd_card_register()) before
> snd_emux_init_seq() fills emu->portptrs[], and ignores the init_seq()
> return value.  A SNDRV_EMUX_IOCTL_MISC_MODE ioctl arriving inside that
> window walks emu->portptrs[i]->ctrls[] with portptrs[i] == NULL and
> causes a near-NULL kernel write (dynamically confirmed on v7.4-rc5);
> a failed sequencer setup additionally leaves the already-registered
> hwdep behind for the probe error path to free with possibly-open fds.
> 
> Initialize the ports (and OSS/virmidi) first and create the hwdep
> device last, so the device only becomes visible to userspace after
> everything its ioctls touch is initialized, and propagate the
> snd_emux_init_seq() error.
> 
> Cc: <stable@vger.kernel.org>
> Signed-off-by: Hanxiang Xu <xuhx@hust.edu.cn>

Applied to for-next branch.  Thanks.


Takashi

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

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

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-02  2:13 [PATCH] ALSA: emux: expose the hwdep device only after ports are initialized Hanxiang Xu
2026-12-02  9:01 ` Takashi Iwai

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®