]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
ALSA: usb-audio: fix race condition to UAF in snd_usbmidi_free
authorJeongjun Park <aha310510@gmail.com>
Sat, 27 Sep 2025 17:39:24 +0000 (02:39 +0900)
committerTakashi Iwai <tiwai@suse.de>
Sun, 28 Sep 2025 06:30:20 +0000 (08:30 +0200)
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>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
sound/usb/midi.c

index acb3bf92857c101ae672f601d0bc2ccc265a949a..97e7e7662b12de7f7f7d0d5eefb01bc47b0ca29f 100644 (file)
@@ -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);
 }