* [PATCH 1/2 4.19.y] ALSA: usb-audio: Sanity checks for each pipe and EP types
[not found] <76c0ef6b-f4bf-41f7-ad36-55f5b4b3180a@stanley.mountain>
@ 2024-09-05 12:38 ` Takashi Iwai
2024-09-05 13:34 ` Dan Carpenter
2024-09-05 12:38 ` [PATCH 2/2 4.19.y] ALSA: usb-audio: Fix gpf in snd_usb_pipe_sanity_check Hillf Danton
1 sibling, 1 reply; 6+ messages in thread
From: Takashi Iwai @ 2024-09-05 12:38 UTC (permalink / raw)
To: Jaroslav Kysela; +Cc: Takashi Iwai, Hillf Danton, alsa-devel, stable
[ Upstream commit 801ebf1043ae7b182588554cc9b9ad3c14bc2ab5 ]
The recent USB core code performs sanity checks for the given pipe and
EP types, and it can be hit by manipulated USB descriptors by syzbot.
For making syzbot happier, this patch introduces a local helper for a
sanity check in the driver side and calls it at each place before the
message handling, so that we can avoid the WARNING splats.
Reported-by: syzbot+d952e5e28f5fb7718d23@syzkaller.appspotmail.com
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
sound/usb/helper.c | 17 +++++++++++++++++
sound/usb/helper.h | 1 +
sound/usb/quirks.c | 14 +++++++++++---
3 files changed, 29 insertions(+), 3 deletions(-)
diff --git a/sound/usb/helper.c b/sound/usb/helper.c
index 7712e2b84183..b1cc9499c57e 100644
--- a/sound/usb/helper.c
+++ b/sound/usb/helper.c
@@ -76,6 +76,20 @@ void *snd_usb_find_csint_desc(void *buffer, int buflen, void *after, u8 dsubtype
return NULL;
}
+/* check the validity of pipe and EP types */
+int snd_usb_pipe_sanity_check(struct usb_device *dev, unsigned int pipe)
+{
+ static const int pipetypes[4] = {
+ PIPE_CONTROL, PIPE_ISOCHRONOUS, PIPE_BULK, PIPE_INTERRUPT
+ };
+ struct usb_host_endpoint *ep;
+
+ ep = usb_pipe_endpoint(dev, pipe);
+ if (usb_pipetype(pipe) != pipetypes[usb_endpoint_type(&ep->desc)])
+ return -EINVAL;
+ return 0;
+}
+
/*
* Wrapper for usb_control_msg().
* Allocates a temp buffer to prevent dmaing from/to the stack.
@@ -88,6 +102,9 @@ int snd_usb_ctl_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
void *buf = NULL;
int timeout;
+ if (snd_usb_pipe_sanity_check(dev, pipe))
+ return -EINVAL;
+
if (size > 0) {
buf = kmemdup(data, size, GFP_KERNEL);
if (!buf)
diff --git a/sound/usb/helper.h b/sound/usb/helper.h
index f5b4c6647e4d..5e8a18b4e7b9 100644
--- a/sound/usb/helper.h
+++ b/sound/usb/helper.h
@@ -7,6 +7,7 @@ unsigned int snd_usb_combine_bytes(unsigned char *bytes, int size);
void *snd_usb_find_desc(void *descstart, int desclen, void *after, u8 dtype);
void *snd_usb_find_csint_desc(void *descstart, int desclen, void *after, u8 dsubtype);
+int snd_usb_pipe_sanity_check(struct usb_device *dev, unsigned int pipe);
int snd_usb_ctl_msg(struct usb_device *dev, unsigned int pipe,
__u8 request, __u8 requesttype, __u16 value, __u16 index,
void *data, __u16 size);
diff --git a/sound/usb/quirks.c b/sound/usb/quirks.c
index 43cbaaff163f..087eef5e249d 100644
--- a/sound/usb/quirks.c
+++ b/sound/usb/quirks.c
@@ -743,11 +743,13 @@ static int snd_usb_novation_boot_quirk(struct usb_device *dev)
static int snd_usb_accessmusic_boot_quirk(struct usb_device *dev)
{
int err, actual_length;
-
/* "midi send" enable */
static const u8 seq[] = { 0x4e, 0x73, 0x52, 0x01 };
+ void *buf;
- void *buf = kmemdup(seq, ARRAY_SIZE(seq), GFP_KERNEL);
+ if (snd_usb_pipe_sanity_check(dev, usb_sndintpipe(dev, 0x05)))
+ return -EINVAL;
+ buf = kmemdup(seq, ARRAY_SIZE(seq), GFP_KERNEL);
if (!buf)
return -ENOMEM;
err = usb_interrupt_msg(dev, usb_sndintpipe(dev, 0x05), buf,
@@ -772,7 +774,11 @@ static int snd_usb_accessmusic_boot_quirk(struct usb_device *dev)
static int snd_usb_nativeinstruments_boot_quirk(struct usb_device *dev)
{
- int ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
+ int ret;
+
+ if (snd_usb_pipe_sanity_check(dev, usb_sndctrlpipe(dev, 0)))
+ return -EINVAL;
+ ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
0xaf, USB_TYPE_VENDOR | USB_RECIP_DEVICE,
1, 0, NULL, 0, 1000);
@@ -879,6 +885,8 @@ static int snd_usb_axefx3_boot_quirk(struct usb_device *dev)
dev_dbg(&dev->dev, "Waiting for Axe-Fx III to boot up...\n");
+ if (snd_usb_pipe_sanity_check(dev, usb_sndctrlpipe(dev, 0)))
+ return -EINVAL;
/* If the Axe-Fx III has not fully booted, it will timeout when trying
* to enable the audio streaming interface. A more generous timeout is
* used here to detect when the Axe-Fx III has finished booting as the
--
2.45.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/2 4.19.y] ALSA: usb-audio: Fix gpf in snd_usb_pipe_sanity_check
[not found] <76c0ef6b-f4bf-41f7-ad36-55f5b4b3180a@stanley.mountain>
2024-09-05 12:38 ` [PATCH 1/2 4.19.y] ALSA: usb-audio: Sanity checks for each pipe and EP types Takashi Iwai
@ 2024-09-05 12:38 ` Hillf Danton
1 sibling, 0 replies; 6+ messages in thread
From: Hillf Danton @ 2024-09-05 12:38 UTC (permalink / raw)
To: Takashi Iwai
Cc: Jaroslav Kysela, Takashi Iwai, Hillf Danton, alsa-devel, stable
[ Upstream commit 5d78e1c2b7f4be00bbe62141603a631dc7812f35 ]
syzbot found the following crash on:
general protection fault: 0000 [#1] SMP KASAN
RIP: 0010:snd_usb_pipe_sanity_check+0x80/0x130 sound/usb/helper.c:75
Call Trace:
snd_usb_motu_microbookii_communicate.constprop.0+0xa0/0x2fb sound/usb/quirks.c:1007
snd_usb_motu_microbookii_boot_quirk sound/usb/quirks.c:1051 [inline]
snd_usb_apply_boot_quirk.cold+0x163/0x370 sound/usb/quirks.c:1280
usb_audio_probe+0x2ec/0x2010 sound/usb/card.c:576
usb_probe_interface+0x305/0x7a0 drivers/usb/core/driver.c:361
really_probe+0x281/0x650 drivers/base/dd.c:548
....
It was introduced in commit 801ebf1043ae for checking pipe and endpoint
types. It is fixed by adding a check of the ep pointer in question.
BugLink: https://syzkaller.appspot.com/bug?extid=d59c4387bfb6eced94e2
Reported-by: syzbot <syzbot+d59c4387bfb6eced94e2@syzkaller.appspotmail.com>
Fixes: 801ebf1043ae ("ALSA: usb-audio: Sanity checks for each pipe and EP types")
Cc: Andrey Konovalov <andreyknvl@google.com>
Signed-off-by: Hillf Danton <hdanton@sina.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
sound/usb/helper.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/sound/usb/helper.c b/sound/usb/helper.c
index b1cc9499c57e..029489b490ca 100644
--- a/sound/usb/helper.c
+++ b/sound/usb/helper.c
@@ -85,7 +85,7 @@ int snd_usb_pipe_sanity_check(struct usb_device *dev, unsigned int pipe)
struct usb_host_endpoint *ep;
ep = usb_pipe_endpoint(dev, pipe);
- if (usb_pipetype(pipe) != pipetypes[usb_endpoint_type(&ep->desc)])
+ if (!ep || usb_pipetype(pipe) != pipetypes[usb_endpoint_type(&ep->desc)])
return -EINVAL;
return 0;
}
--
2.45.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2 4.19.y] ALSA: usb-audio: Sanity checks for each pipe and EP types
2024-09-05 12:38 ` [PATCH 1/2 4.19.y] ALSA: usb-audio: Sanity checks for each pipe and EP types Takashi Iwai
@ 2024-09-05 13:34 ` Dan Carpenter
2024-09-05 13:49 ` Greg KH
0 siblings, 1 reply; 6+ messages in thread
From: Dan Carpenter @ 2024-09-05 13:34 UTC (permalink / raw)
To: Jaroslav Kysela; +Cc: Takashi Iwai, Hillf Danton, alsa-devel, stable
Sorry,
I completely messed these emails up. It has Takashi Iwai and Hillf Danton's
names instead of mine in the From header. It still has my email address, but
just the names are wrong.
Also I should have used a From header in the body of the email.
Also the threading is messed up.
Will try again tomorrow.
regards,
dan carpenter
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2 4.19.y] ALSA: usb-audio: Sanity checks for each pipe and EP types
2024-09-05 13:34 ` Dan Carpenter
@ 2024-09-05 13:49 ` Greg KH
2024-09-05 15:11 ` Dan Carpenter
0 siblings, 1 reply; 6+ messages in thread
From: Greg KH @ 2024-09-05 13:49 UTC (permalink / raw)
To: Dan Carpenter
Cc: Jaroslav Kysela, Takashi Iwai, Hillf Danton, alsa-devel, stable
On Thu, Sep 05, 2024 at 04:34:45PM +0300, Dan Carpenter wrote:
> Sorry,
>
> I completely messed these emails up. It has Takashi Iwai and Hillf Danton's
> names instead of mine in the From header. It still has my email address, but
> just the names are wrong.
>
> Also I should have used a From header in the body of the email.
>
> Also the threading is messed up.
>
> Will try again tomorrow.
It looks good to me, now queued up.
thanks,
greg k-h
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2 4.19.y] ALSA: usb-audio: Sanity checks for each pipe and EP types
2024-09-05 13:49 ` Greg KH
@ 2024-09-05 15:11 ` Dan Carpenter
2024-09-05 16:29 ` Greg KH
0 siblings, 1 reply; 6+ messages in thread
From: Dan Carpenter @ 2024-09-05 15:11 UTC (permalink / raw)
To: Greg KH; +Cc: Jaroslav Kysela, Takashi Iwai, Hillf Danton, alsa-devel, stable
On Thu, Sep 05, 2024 at 03:49:14PM +0200, Greg KH wrote:
> On Thu, Sep 05, 2024 at 04:34:45PM +0300, Dan Carpenter wrote:
> > Sorry,
> >
> > I completely messed these emails up. It has Takashi Iwai and Hillf Danton's
> > names instead of mine in the From header. It still has my email address, but
> > just the names are wrong.
> >
> > Also I should have used a From header in the body of the email.
> >
> > Also the threading is messed up.
> >
> > Will try again tomorrow.
>
> It looks good to me, now queued up.
>
The code is okay but the Author header is messed up. It has my email address.
From: Hillf Danton <dan.carpenter@linaro.org>
From: Takashi Iwai <dan.carpenter@linaro.org>
regards,
dan carpenter
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2 4.19.y] ALSA: usb-audio: Sanity checks for each pipe and EP types
2024-09-05 15:11 ` Dan Carpenter
@ 2024-09-05 16:29 ` Greg KH
0 siblings, 0 replies; 6+ messages in thread
From: Greg KH @ 2024-09-05 16:29 UTC (permalink / raw)
To: Dan Carpenter
Cc: Jaroslav Kysela, Takashi Iwai, Hillf Danton, alsa-devel, stable
On Thu, Sep 05, 2024 at 06:11:49PM +0300, Dan Carpenter wrote:
> On Thu, Sep 05, 2024 at 03:49:14PM +0200, Greg KH wrote:
> > On Thu, Sep 05, 2024 at 04:34:45PM +0300, Dan Carpenter wrote:
> > > Sorry,
> > >
> > > I completely messed these emails up. It has Takashi Iwai and Hillf Danton's
> > > names instead of mine in the From header. It still has my email address, but
> > > just the names are wrong.
> > >
> > > Also I should have used a From header in the body of the email.
> > >
> > > Also the threading is messed up.
> > >
> > > Will try again tomorrow.
> >
> > It looks good to me, now queued up.
> >
>
> The code is okay but the Author header is messed up. It has my email address.
>
> From: Hillf Danton <dan.carpenter@linaro.org>
>
> From: Takashi Iwai <dan.carpenter@linaro.org>
Ah that's really odd, how did you do that? :)
Now fixed up in the patches, don't worry about it.
greg k-h
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2024-09-05 16:30 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <76c0ef6b-f4bf-41f7-ad36-55f5b4b3180a@stanley.mountain>
2024-09-05 12:38 ` [PATCH 1/2 4.19.y] ALSA: usb-audio: Sanity checks for each pipe and EP types Takashi Iwai
2024-09-05 13:34 ` Dan Carpenter
2024-09-05 13:49 ` Greg KH
2024-09-05 15:11 ` Dan Carpenter
2024-09-05 16:29 ` Greg KH
2024-09-05 12:38 ` [PATCH 2/2 4.19.y] ALSA: usb-audio: Fix gpf in snd_usb_pipe_sanity_check Hillf Danton
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox