Skip to content

Commit 647d6b8

Browse files
name2965gregkh
authored andcommitted
ALSA: usb-audio: fix race condition to UAF in snd_usbmidi_free
commit 9f2c0ac 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: <stable@vger.kernel.org> Reported-by: syzbot+f02665daa2abeef4a947@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=f02665daa2abeef4a947 Fixes: 0718a78 ("ALSA: usb-audio: Kill timer properly at removal") Signed-off-by: Jeongjun Park <aha310510@gmail.com> Signed-off-by: Takashi Iwai <tiwai@suse.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent c611b9e commit 647d6b8

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

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)