Skip to content

Commit 353d8c7

Browse files
name2965gregkh
authored andcommitted
ALSA: usb-audio: fix race condition to UAF in snd_usbmidi_free
commit 9f2c0ac1423d5f267e7f1d1940780fc764b0fee3 upstream. The previous commit 0718a78 ("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: <[email protected]> Reported-by: [email protected] Closes: https://syzkaller.appspot.com/bug?extid=f02665daa2abeef4a947 Fixes: 0718a78 ("ALSA: usb-audio: Kill timer properly at removal") Signed-off-by: Jeongjun Park <[email protected]> Signed-off-by: Takashi Iwai <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent a150275 commit 353d8c7

1 file changed

Lines changed: 4 additions & 5 deletions

File tree

sound/usb/midi.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1522,15 +1522,14 @@ static void snd_usbmidi_free(struct snd_usb_midi *umidi)
15221522
{
15231523
int i;
15241524

1525+
if (!umidi->disconnected)
1526+
snd_usbmidi_disconnect(&umidi->list);
1527+
15251528
for (i = 0; i < MIDI_MAX_ENDPOINTS; ++i) {
15261529
struct snd_usb_midi_endpoint *ep = &umidi->endpoints[i];
1527-
if (ep->out)
1528-
snd_usbmidi_out_endpoint_delete(ep->out);
1529-
if (ep->in)
1530-
snd_usbmidi_in_endpoint_delete(ep->in);
1530+
kfree(ep->out);
15311531
}
15321532
mutex_destroy(&umidi->mutex);
1533-
timer_shutdown_sync(&umidi->error_timer);
15341533
kfree(umidi);
15351534
}
15361535

0 commit comments

Comments
 (0)