[PATCH] ALSA: usb-audio: Add the number of endpoints checked was 0

Edward Adam Davis posted 1 patch 1 month ago
sound/usb/mixer.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
[PATCH] ALSA: usb-audio: Add the number of endpoints checked was 0
Posted by Edward Adam Davis 1 month ago
The user constructed a corrupted USB device, causing the USB device
enumeration phase to fail to resolve any endpoints. This resulted in
a null pointer dereference reported in [1] when the USB sound card
driver executed probe to initialize the mixer. 

To avoid the problem reported in [1], a check was added to ensure that
the number of endpoints contained in the interface was 0 when checking
the mixer status.

[1]
KASAN: null-ptr-deref in range [0x0000000000000000-0x0000000000000007]
RIP: 0010:usb_endpoint_num include/uapi/linux/usb/ch9.h:479 [inline]
RIP: 0010:scarlett2_find_fc_interface sound/usb/mixer_scarlett2.c:8261 [inline]
RIP: 0010:scarlett2_init_private sound/usb/mixer_scarlett2.c:8295 [inline]
RIP: 0010:snd_scarlett2_controls_create sound/usb/mixer_scarlett2.c:8684 [inline]
RIP: 0010:snd_scarlett2_init.cold+0xbad/0x6c79 sound/usb/mixer_scarlett2.c:9407
Call Trace:
 snd_usb_mixer_apply_create_quirk+0x1c21/0x2b80 sound/usb/mixer_quirks.c:4446
 snd_usb_create_mixer+0x7a2/0x1910 sound/usb/mixer.c:3641
 usb_audio_probe+0xf6d/0x3a90 sound/usb/card.c:1033

Reported-by: syzbot+ae893a8901067fde2741@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=ae893a8901067fde2741 
Tested-by: syzbot+ae893a8901067fde2741@syzkaller.appspotmail.com
Signed-off-by: Edward Adam Davis <eadavis@qq.com>
---
 sound/usb/mixer.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/sound/usb/mixer.c b/sound/usb/mixer.c
index ac8c71ba9483..bd28caec3004 100644
--- a/sound/usb/mixer.c
+++ b/sound/usb/mixer.c
@@ -3563,8 +3563,12 @@ static int snd_usb_mixer_status_create(struct usb_mixer_interface *mixer)
 	int buffer_length;
 	unsigned int epnum;
 
+	epnum = get_iface_desc(mixer->hostif)->bNumEndpoints;
+	if (epnum == 0)
+		return -EINVAL;
+
 	/* we need one interrupt input endpoint */
-	if (get_iface_desc(mixer->hostif)->bNumEndpoints < 1)
+	if (epnum < 1)
 		return 0;
 	ep = get_endpoint(mixer->hostif, 0);
 	if (!usb_endpoint_dir_in(ep) || !usb_endpoint_xfer_int(ep))
-- 
2.43.0
Re: [PATCH] ALSA: usb-audio: Add the number of endpoints checked was 0
Posted by Takashi Iwai 1 month ago
On Mon, 09 Mar 2026 08:32:29 +0100,
Edward Adam Davis wrote:
> 
> The user constructed a corrupted USB device, causing the USB device
> enumeration phase to fail to resolve any endpoints. This resulted in
> a null pointer dereference reported in [1] when the USB sound card
> driver executed probe to initialize the mixer. 
> 
> To avoid the problem reported in [1], a check was added to ensure that
> the number of endpoints contained in the interface was 0 when checking
> the mixer status.
> 
> [1]
> KASAN: null-ptr-deref in range [0x0000000000000000-0x0000000000000007]
> RIP: 0010:usb_endpoint_num include/uapi/linux/usb/ch9.h:479 [inline]
> RIP: 0010:scarlett2_find_fc_interface sound/usb/mixer_scarlett2.c:8261 [inline]
> RIP: 0010:scarlett2_init_private sound/usb/mixer_scarlett2.c:8295 [inline]
> RIP: 0010:snd_scarlett2_controls_create sound/usb/mixer_scarlett2.c:8684 [inline]
> RIP: 0010:snd_scarlett2_init.cold+0xbad/0x6c79 sound/usb/mixer_scarlett2.c:9407
> Call Trace:
>  snd_usb_mixer_apply_create_quirk+0x1c21/0x2b80 sound/usb/mixer_quirks.c:4446
>  snd_usb_create_mixer+0x7a2/0x1910 sound/usb/mixer.c:3641
>  usb_audio_probe+0xf6d/0x3a90 sound/usb/card.c:1033
> 
> Reported-by: syzbot+ae893a8901067fde2741@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=ae893a8901067fde2741 
> Tested-by: syzbot+ae893a8901067fde2741@syzkaller.appspotmail.com
> Signed-off-by: Edward Adam Davis <eadavis@qq.com>
> ---
>  sound/usb/mixer.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/sound/usb/mixer.c b/sound/usb/mixer.c
> index ac8c71ba9483..bd28caec3004 100644
> --- a/sound/usb/mixer.c
> +++ b/sound/usb/mixer.c
> @@ -3563,8 +3563,12 @@ static int snd_usb_mixer_status_create(struct usb_mixer_interface *mixer)
>  	int buffer_length;
>  	unsigned int epnum;
>  
> +	epnum = get_iface_desc(mixer->hostif)->bNumEndpoints;
> +	if (epnum == 0)
> +		return -EINVAL;
> +
>  	/* we need one interrupt input endpoint */
> -	if (get_iface_desc(mixer->hostif)->bNumEndpoints < 1)
> +	if (epnum < 1)
>  		return 0;

The change looks wrong.  We don't want to return an error here, as
mixer->urb is optional.  And the second check introduced above is
utterly nonsense; epnum is an unsigned int, so epnum < 1 means only
epnum == 0.

The problem is rather in the scarlett2 side, and it should have a
check there, not in the core function.


thanks,

Takashi
[PATCH v2] ALSA: scarlett2: Add the number of endpoints checked was 0
Posted by Edward Adam Davis 1 month ago
The user constructed a corrupted USB device, causing the USB device
enumeration phase to fail to resolve any endpoints. This resulted in
a null pointer dereference reported in [1] when the USB sound card
driver executed probe to initialize the mixer. 

To avoid the problem reported in [1], a check was added to ensure that
the number of endpoints contained in the interface was 0 when creating
mixer controls for the Focusrite Scarlett 2nd/3rd Gen USB sound card.

[1]
KASAN: null-ptr-deref in range [0x0000000000000000-0x0000000000000007]
RIP: 0010:usb_endpoint_num include/uapi/linux/usb/ch9.h:479 [inline]
RIP: 0010:scarlett2_find_fc_interface sound/usb/mixer_scarlett2.c:8261 [inline]
RIP: 0010:scarlett2_init_private sound/usb/mixer_scarlett2.c:8295 [inline]
RIP: 0010:snd_scarlett2_controls_create sound/usb/mixer_scarlett2.c:8684 [inline]
RIP: 0010:snd_scarlett2_init.cold+0xbad/0x6c79 sound/usb/mixer_scarlett2.c:9407
Call Trace:
 snd_usb_mixer_apply_create_quirk+0x1c21/0x2b80 sound/usb/mixer_quirks.c:4446
 snd_usb_create_mixer+0x7a2/0x1910 sound/usb/mixer.c:3641
 usb_audio_probe+0xf6d/0x3a90 sound/usb/card.c:1033

Reported-by: syzbot+ae893a8901067fde2741@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=ae893a8901067fde2741 
Signed-off-by: Edward Adam Davis <eadavis@qq.com>
---
v1 -> v2: move the check to scarlett2

 sound/usb/mixer_scarlett2.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/sound/usb/mixer_scarlett2.c b/sound/usb/mixer_scarlett2.c
index ef3150581eab..4b300226f16c 100644
--- a/sound/usb/mixer_scarlett2.c
+++ b/sound/usb/mixer_scarlett2.c
@@ -9393,6 +9393,15 @@ int snd_scarlett2_init(struct usb_mixer_interface *mixer)
 		return 0;
 	}
 
+	if (get_iface_desc(mixer->hostif)->bNumEndpoints == 0) {
+		usb_audio_err(chip,
+			"%s: There are no endpoints for %04x:%04x\n",
+			__func__,
+			USB_ID_VENDOR(chip->usb_id),
+			USB_ID_PRODUCT(chip->usb_id));
+		return 0;
+	}
+
 	usb_audio_info(chip,
 		"Focusrite %s Mixer Driver enabled (pid=0x%04x); "
 		"report any issues to "
-- 
2.43.0
Re: [PATCH v2] ALSA: scarlett2: Add the number of endpoints checked was 0
Posted by Greg KH 1 month ago
On Mon, Mar 09, 2026 at 05:57:03PM +0800, Edward Adam Davis wrote:
> The user constructed a corrupted USB device, causing the USB device
> enumeration phase to fail to resolve any endpoints. This resulted in
> a null pointer dereference reported in [1] when the USB sound card
> driver executed probe to initialize the mixer. 
> 
> To avoid the problem reported in [1], a check was added to ensure that
> the number of endpoints contained in the interface was 0 when creating
> mixer controls for the Focusrite Scarlett 2nd/3rd Gen USB sound card.
> 
> [1]
> KASAN: null-ptr-deref in range [0x0000000000000000-0x0000000000000007]
> RIP: 0010:usb_endpoint_num include/uapi/linux/usb/ch9.h:479 [inline]
> RIP: 0010:scarlett2_find_fc_interface sound/usb/mixer_scarlett2.c:8261 [inline]
> RIP: 0010:scarlett2_init_private sound/usb/mixer_scarlett2.c:8295 [inline]
> RIP: 0010:snd_scarlett2_controls_create sound/usb/mixer_scarlett2.c:8684 [inline]
> RIP: 0010:snd_scarlett2_init.cold+0xbad/0x6c79 sound/usb/mixer_scarlett2.c:9407
> Call Trace:
>  snd_usb_mixer_apply_create_quirk+0x1c21/0x2b80 sound/usb/mixer_quirks.c:4446
>  snd_usb_create_mixer+0x7a2/0x1910 sound/usb/mixer.c:3641
>  usb_audio_probe+0xf6d/0x3a90 sound/usb/card.c:1033
> 
> Reported-by: syzbot+ae893a8901067fde2741@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=ae893a8901067fde2741 
> Signed-off-by: Edward Adam Davis <eadavis@qq.com>
> ---
> v1 -> v2: move the check to scarlett2
> 
>  sound/usb/mixer_scarlett2.c | 9 +++++++++
>  1 file changed, 9 insertions(+)
> 
> diff --git a/sound/usb/mixer_scarlett2.c b/sound/usb/mixer_scarlett2.c
> index ef3150581eab..4b300226f16c 100644
> --- a/sound/usb/mixer_scarlett2.c
> +++ b/sound/usb/mixer_scarlett2.c
> @@ -9393,6 +9393,15 @@ int snd_scarlett2_init(struct usb_mixer_interface *mixer)
>  		return 0;
>  	}
>  
> +	if (get_iface_desc(mixer->hostif)->bNumEndpoints == 0) {
> +		usb_audio_err(chip,
> +			"%s: There are no endpoints for %04x:%04x\n",
> +			__func__,
> +			USB_ID_VENDOR(chip->usb_id),
> +			USB_ID_PRODUCT(chip->usb_id));
> +		return 0;
> +	}

Why not use the "normal" functions to check a USB device for the exact
specific types and numbers of endpoints instead of hand-coding it all?

thanks,

greg k-h
Re: [PATCH v2] ALSA: scarlett2: Add the number of endpoints checked was 0
Posted by Takashi Iwai 1 month ago
On Mon, 09 Mar 2026 10:57:03 +0100,
Edward Adam Davis wrote:
> 
> The user constructed a corrupted USB device, causing the USB device
> enumeration phase to fail to resolve any endpoints. This resulted in
> a null pointer dereference reported in [1] when the USB sound card
> driver executed probe to initialize the mixer. 
> 
> To avoid the problem reported in [1], a check was added to ensure that
> the number of endpoints contained in the interface was 0 when creating
> mixer controls for the Focusrite Scarlett 2nd/3rd Gen USB sound card.
> 
> [1]
> KASAN: null-ptr-deref in range [0x0000000000000000-0x0000000000000007]
> RIP: 0010:usb_endpoint_num include/uapi/linux/usb/ch9.h:479 [inline]
> RIP: 0010:scarlett2_find_fc_interface sound/usb/mixer_scarlett2.c:8261 [inline]
> RIP: 0010:scarlett2_init_private sound/usb/mixer_scarlett2.c:8295 [inline]
> RIP: 0010:snd_scarlett2_controls_create sound/usb/mixer_scarlett2.c:8684 [inline]
> RIP: 0010:snd_scarlett2_init.cold+0xbad/0x6c79 sound/usb/mixer_scarlett2.c:9407
> Call Trace:
>  snd_usb_mixer_apply_create_quirk+0x1c21/0x2b80 sound/usb/mixer_quirks.c:4446
>  snd_usb_create_mixer+0x7a2/0x1910 sound/usb/mixer.c:3641
>  usb_audio_probe+0xf6d/0x3a90 sound/usb/card.c:1033
> 
> Reported-by: syzbot+ae893a8901067fde2741@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=ae893a8901067fde2741 
> Signed-off-by: Edward Adam Davis <eadavis@qq.com>
> ---
> v1 -> v2: move the check to scarlett2
> 
>  sound/usb/mixer_scarlett2.c | 9 +++++++++
>  1 file changed, 9 insertions(+)
> 
> diff --git a/sound/usb/mixer_scarlett2.c b/sound/usb/mixer_scarlett2.c
> index ef3150581eab..4b300226f16c 100644
> --- a/sound/usb/mixer_scarlett2.c
> +++ b/sound/usb/mixer_scarlett2.c
> @@ -9393,6 +9393,15 @@ int snd_scarlett2_init(struct usb_mixer_interface *mixer)
>  		return 0;
>  	}
>  
> +	if (get_iface_desc(mixer->hostif)->bNumEndpoints == 0) {
> +		usb_audio_err(chip,
> +			"%s: There are no endpoints for %04x:%04x\n",
> +			__func__,
> +			USB_ID_VENDOR(chip->usb_id),
> +			USB_ID_PRODUCT(chip->usb_id));
> +		return 0;

This should be an error.  It's obviously a broken descriptor, and this
is the code specific to the certain configuration.


Takashi
Re: [PATCH v2] ALSA: scarlett2: Add the number of endpoints checked was 0
Posted by Takashi Iwai 1 month ago
On Mon, 09 Mar 2026 11:03:46 +0100,
Takashi Iwai wrote:
> 
> On Mon, 09 Mar 2026 10:57:03 +0100,
> Edward Adam Davis wrote:
> > 
> > The user constructed a corrupted USB device, causing the USB device
> > enumeration phase to fail to resolve any endpoints. This resulted in
> > a null pointer dereference reported in [1] when the USB sound card
> > driver executed probe to initialize the mixer. 
> > 
> > To avoid the problem reported in [1], a check was added to ensure that
> > the number of endpoints contained in the interface was 0 when creating
> > mixer controls for the Focusrite Scarlett 2nd/3rd Gen USB sound card.
> > 
> > [1]
> > KASAN: null-ptr-deref in range [0x0000000000000000-0x0000000000000007]
> > RIP: 0010:usb_endpoint_num include/uapi/linux/usb/ch9.h:479 [inline]
> > RIP: 0010:scarlett2_find_fc_interface sound/usb/mixer_scarlett2.c:8261 [inline]
> > RIP: 0010:scarlett2_init_private sound/usb/mixer_scarlett2.c:8295 [inline]
> > RIP: 0010:snd_scarlett2_controls_create sound/usb/mixer_scarlett2.c:8684 [inline]
> > RIP: 0010:snd_scarlett2_init.cold+0xbad/0x6c79 sound/usb/mixer_scarlett2.c:9407
> > Call Trace:
> >  snd_usb_mixer_apply_create_quirk+0x1c21/0x2b80 sound/usb/mixer_quirks.c:4446
> >  snd_usb_create_mixer+0x7a2/0x1910 sound/usb/mixer.c:3641
> >  usb_audio_probe+0xf6d/0x3a90 sound/usb/card.c:1033
> > 
> > Reported-by: syzbot+ae893a8901067fde2741@syzkaller.appspotmail.com
> > Closes: https://syzkaller.appspot.com/bug?extid=ae893a8901067fde2741 
> > Signed-off-by: Edward Adam Davis <eadavis@qq.com>
> > ---
> > v1 -> v2: move the check to scarlett2
> > 
> >  sound/usb/mixer_scarlett2.c | 9 +++++++++
> >  1 file changed, 9 insertions(+)
> > 
> > diff --git a/sound/usb/mixer_scarlett2.c b/sound/usb/mixer_scarlett2.c
> > index ef3150581eab..4b300226f16c 100644
> > --- a/sound/usb/mixer_scarlett2.c
> > +++ b/sound/usb/mixer_scarlett2.c
> > @@ -9393,6 +9393,15 @@ int snd_scarlett2_init(struct usb_mixer_interface *mixer)
> >  		return 0;
> >  	}
> >  
> > +	if (get_iface_desc(mixer->hostif)->bNumEndpoints == 0) {
> > +		usb_audio_err(chip,
> > +			"%s: There are no endpoints for %04x:%04x\n",
> > +			__func__,
> > +			USB_ID_VENDOR(chip->usb_id),
> > +			USB_ID_PRODUCT(chip->usb_id));
> > +		return 0;
> 
> This should be an error.  It's obviously a broken descriptor, and this
> is the code specific to the certain configuration.

... and that check alone doesn't cover all cases, I'm afraid.  The
scarlett2 driver code parses over multiple interfaces.

I guess rather a patch like below should cover better.


thanks,

Takashi

--- a/sound/usb/mixer_scarlett2.c
+++ b/sound/usb/mixer_scarlett2.c
@@ -8251,6 +8251,8 @@ static int scarlett2_find_fc_interface(struct usb_device *dev,
 
 		if (desc->bInterfaceClass != 255)
 			continue;
+		if (desc->bNumEndpoints < 1)
+			continue;
 
 		epd = get_endpoint(intf->altsetting, 0);
 		private->bInterfaceNumber = desc->bInterfaceNumber;