Skip to content

Commit a310b4b

Browse files
CassivsGabriellisgregkh
authored andcommitted
ALSA: usb-audio: Bound MIDI 2.0 endpoint descriptor scans
commit 918be51 upstream. The USB MIDI 2.0 endpoint parser has the same descriptor walking pattern as the legacy MIDI parser. It validates bLength against bNumGrpTrmBlock before reading baAssoGrpTrmBlkID[], but not against the remaining bytes in the endpoint-extra scan. A malformed device can therefore make later baAssoGrpTrmBlkID[] reads consume bytes past the walked descriptor. Reject zero-length and overlong descriptors while walking endpoint extras. Fixes: ff49d1d ("ALSA: usb-audio: USB MIDI 2.0 UMP support") Cc: stable@vger.kernel.org Signed-off-by: Cássio Gabriel <cassiogabrielcontato@gmail.com> Link: https://patch.msgid.link/20260507-usb-midi-endpoint-scan-bounds-v1-2-329d7348160e@gmail.com Signed-off-by: Takashi Iwai <tiwai@suse.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 0e52afd commit a310b4b

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

sound/usb/midi2.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -504,15 +504,17 @@ static void *find_usb_ms_endpoint_descriptor(struct usb_host_endpoint *hostep,
504504
while (extralen > 3) {
505505
struct usb_ms_endpoint_descriptor *ms_ep =
506506
(struct usb_ms_endpoint_descriptor *)extra;
507+
int length = ms_ep->bLength;
507508

508-
if (ms_ep->bLength > 3 &&
509+
if (!length || length > extralen)
510+
break;
511+
512+
if (length > 3 &&
509513
ms_ep->bDescriptorType == USB_DT_CS_ENDPOINT &&
510514
ms_ep->bDescriptorSubtype == subtype)
511515
return ms_ep;
512-
if (!extra[0])
513-
break;
514-
extralen -= extra[0];
515-
extra += extra[0];
516+
extralen -= length;
517+
extra += length;
516518
}
517519
return NULL;
518520
}

0 commit comments

Comments
 (0)