public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] ALSA: usb-audio: fix race condition to UAF in snd_usbmidi_free
@ 2025-09-27 17:39 Jeongjun Park
  2025-09-28  6:31 ` Takashi Iwai
  0 siblings, 1 reply; 2+ messages in thread
From: Jeongjun Park @ 2025-09-27 17:39 UTC (permalink / raw)
  To: clemens, perex, tiwai
  Cc: hdanton, linux-sound, linux-kernel, stable,
	syzbot+f02665daa2abeef4a947, Jeongjun Park

The previous commit 0718a78f6a9f ("ALSA: usb-audio: Kill timer properly at
removal") patched a UAF issue caused by the error timer.

However, because the error timer kill added in this patch occurs after the
endpoint delete, a race condition to UAF still occurs, albeit rarely.

Additionally, since kill-cleanup for urb is also missing, freed memory can
be accessed in interrupt context related to urb, which can cause UAF.

Therefore, to prevent this, error timer and urb must be killed before
freeing the heap memory.

Cc: <stable@vger.kernel.org>
Reported-by: syzbot+f02665daa2abeef4a947@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=f02665daa2abeef4a947
Fixes: 0718a78f6a9f ("ALSA: usb-audio: Kill timer properly at removal")
Signed-off-by: Jeongjun Park <aha310510@gmail.com>
---
 sound/usb/midi.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/sound/usb/midi.c b/sound/usb/midi.c
index acb3bf92857c..97e7e7662b12 100644
--- a/sound/usb/midi.c
+++ b/sound/usb/midi.c
@@ -1522,15 +1522,14 @@ static void snd_usbmidi_free(struct snd_usb_midi *umidi)
 {
 	int i;
 
+	if (!umidi->disconnected)
+		snd_usbmidi_disconnect(&umidi->list);
+
 	for (i = 0; i < MIDI_MAX_ENDPOINTS; ++i) {
 		struct snd_usb_midi_endpoint *ep = &umidi->endpoints[i];
-		if (ep->out)
-			snd_usbmidi_out_endpoint_delete(ep->out);
-		if (ep->in)
-			snd_usbmidi_in_endpoint_delete(ep->in);
+		kfree(ep->out);
 	}
 	mutex_destroy(&umidi->mutex);
-	timer_shutdown_sync(&umidi->error_timer);
 	kfree(umidi);
 }
 
--

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

* Re: [PATCH v2] ALSA: usb-audio: fix race condition to UAF in snd_usbmidi_free
  2025-09-27 17:39 [PATCH v2] ALSA: usb-audio: fix race condition to UAF in snd_usbmidi_free Jeongjun Park
@ 2025-09-28  6:31 ` Takashi Iwai
  0 siblings, 0 replies; 2+ messages in thread
From: Takashi Iwai @ 2025-09-28  6:31 UTC (permalink / raw)
  To: Jeongjun Park
  Cc: clemens, perex, tiwai, hdanton, linux-sound, linux-kernel, stable,
	syzbot+f02665daa2abeef4a947

On Sat, 27 Sep 2025 19:39:24 +0200,
Jeongjun Park wrote:
> 
> The previous commit 0718a78f6a9f ("ALSA: usb-audio: Kill timer properly at
> removal") patched a UAF issue caused by the error timer.
> 
> However, because the error timer kill added in this patch occurs after the
> endpoint delete, a race condition to UAF still occurs, albeit rarely.
> 
> Additionally, since kill-cleanup for urb is also missing, freed memory can
> be accessed in interrupt context related to urb, which can cause UAF.
> 
> Therefore, to prevent this, error timer and urb must be killed before
> freeing the heap memory.
> 
> Cc: <stable@vger.kernel.org>
> Reported-by: syzbot+f02665daa2abeef4a947@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=f02665daa2abeef4a947
> Fixes: 0718a78f6a9f ("ALSA: usb-audio: Kill timer properly at removal")
> Signed-off-by: Jeongjun Park <aha310510@gmail.com>

Thanks, applied now.


Takashi

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

end of thread, other threads:[~2025-09-28  6:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-27 17:39 [PATCH v2] ALSA: usb-audio: fix race condition to UAF in snd_usbmidi_free Jeongjun Park
2025-09-28  6:31 ` Takashi Iwai

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