Skip to content

Commit 28412b4

Browse files
Radon10043tiwai
authored andcommitted
ALSA: usb-audio: Fix NULL pointer deference in try_to_register_card
In try_to_register_card(), the return value of usb_ifnum_to_if() is passed directly to usb_interface_claimed() without a NULL check, which will lead to a NULL pointer dereference when creating an invalid USB audio device. Fix this by adding a check to ensure the interface pointer is valid before passing it to usb_interface_claimed(). Fixes: 39efc9c ("ALSA: usb-audio: Fix last interface check for registration") Closes: https://lore.kernel.org/all/CANypQFYtQxHL5ghREs-BujZG413RPJGnO5TH=xjFBKpPts33tA@mail.gmail.com/ Signed-off-by: Jiaming Zhang <[email protected]> Signed-off-by: Takashi Iwai <[email protected]>
1 parent d41f68d commit 28412b4

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

sound/usb/card.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -891,10 +891,16 @@ get_alias_quirk(struct usb_device *dev, unsigned int id)
891891
*/
892892
static int try_to_register_card(struct snd_usb_audio *chip, int ifnum)
893893
{
894+
struct usb_interface *iface;
895+
894896
if (check_delayed_register_option(chip) == ifnum ||
895-
chip->last_iface == ifnum ||
896-
usb_interface_claimed(usb_ifnum_to_if(chip->dev, chip->last_iface)))
897+
chip->last_iface == ifnum)
898+
return snd_card_register(chip->card);
899+
900+
iface = usb_ifnum_to_if(chip->dev, chip->last_iface);
901+
if (iface && usb_interface_claimed(iface))
897902
return snd_card_register(chip->card);
903+
898904
return 0;
899905
}
900906

0 commit comments

Comments
 (0)