* usb/sound/usx2y: WARNING in usb_stream_start
@ 2017-11-03 14:44 Andrey Konovalov
2017-11-03 19:52 ` Takashi Iwai
0 siblings, 1 reply; 6+ messages in thread
From: Andrey Konovalov @ 2017-11-03 14:44 UTC (permalink / raw)
To: Jaroslav Kysela, Takashi Iwai, Dave Jiang, Arnd Bergmann,
Mauro Carvalho Chehab, Andrew Morton, Markus Elfring,
Johan Hovold, Arvind Yadav, alsa-devel, LKML
Cc: Dmitry Vyukov, Kostya Serebryany, syzkaller
Hi!
I've got the following report while fuzzing the kernel with syzkaller.
On commit 3a99df9a3d14cd866b5516f8cba515a3bfd554ab (4.14-rc7+).
Looks like there's no check for the actual endpoint types.
usb 1-1: BOGUS urb xfer, pipe 0 != type 3
------------[ cut here ]------------
WARNING: CPU: 0 PID: 24 at drivers/usb/core/urb.c:471
usb_submit_urb+0x113e/0x1400
Modules linked in:
CPU: 0 PID: 24 Comm: kworker/0:1 Not tainted
4.14.0-rc7-44290-gf28444df2601-dirty #52
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Bochs 01/01/2011
Workqueue: usb_hub_wq hub_event
task: ffff88006bef5c00 task.stack: ffff88006bf60000
RIP: 0010:usb_submit_urb+0x113e/0x1400 drivers/usb/core/urb.c:470
RSP: 0018:ffff88006bf67440 EFLAGS: 00010286
RAX: 0000000000000029 RBX: ffff880064698c80 RCX: ffffffff812495b5
RDX: 0000000000000000 RSI: ffffffff8124d76a RDI: 0000000000000005
RBP: ffff88006bf674b0 R08: ffff88006bef5c00 R09: 0000000000000006
R10: 0000000000000000 R11: 0000000000000000 R12: 0000000000000000
R13: 0000000000000003 R14: ffff880069a25a20 R15: ffff880064698d04
FS: 0000000000000000(0000) GS:ffff88006ca00000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00007fe6fdba3000 CR3: 0000000068470000 CR4: 00000000000006f0
Call Trace:
usb_stream_start+0x48a/0x9f0 sound/usb/usx2y/usb_stream.c:690
us122l_start+0x116/0x290 sound/usb/usx2y/us122l.c:365
us122l_create_card sound/usb/usx2y/us122l.c:502
us122l_usb_probe sound/usb/usx2y/us122l.c:588
snd_us122l_probe+0x7de/0x10a0 sound/usb/usx2y/us122l.c:623
usb_probe_interface+0x324/0x940 drivers/usb/core/driver.c:361
really_probe drivers/base/dd.c:413
driver_probe_device+0x522/0x740 drivers/base/dd.c:557
__device_attach_driver+0x25d/0x2d0 drivers/base/dd.c:653
bus_for_each_drv+0xff/0x160 drivers/base/bus.c:463
__device_attach+0x1a8/0x2a0 drivers/base/dd.c:710
device_initial_probe+0x1f/0x30 drivers/base/dd.c:757
bus_probe_device+0x1fc/0x2a0 drivers/base/bus.c:523
device_add+0xc27/0x15a0 drivers/base/core.c:1835
usb_set_configuration+0xd4f/0x17a0 drivers/usb/core/message.c:1932
generic_probe+0xbb/0x120 drivers/usb/core/generic.c:174
usb_probe_device+0xab/0x100 drivers/usb/core/driver.c:266
really_probe drivers/base/dd.c:413
driver_probe_device+0x522/0x740 drivers/base/dd.c:557
__device_attach_driver+0x25d/0x2d0 drivers/base/dd.c:653
bus_for_each_drv+0xff/0x160 drivers/base/bus.c:463
__device_attach+0x1a8/0x2a0 drivers/base/dd.c:710
device_initial_probe+0x1f/0x30 drivers/base/dd.c:757
bus_probe_device+0x1fc/0x2a0 drivers/base/bus.c:523
device_add+0xc27/0x15a0 drivers/base/core.c:1835
usb_new_device+0x7fa/0x1090 drivers/usb/core/hub.c:2538
hub_port_connect drivers/usb/core/hub.c:4987
hub_port_connect_change drivers/usb/core/hub.c:5093
port_event drivers/usb/core/hub.c:5199
hub_event_impl+0x17b8/0x3440 drivers/usb/core/hub.c:5311
hub_event+0x38/0x50 drivers/usb/core/hub.c:5209
process_one_work+0x925/0x15d0 kernel/workqueue.c:2113
worker_thread+0xef/0x10d0 kernel/workqueue.c:2247
kthread+0x346/0x410 kernel/kthread.c:231
ret_from_fork+0x2a/0x40 arch/x86/entry/entry_64.S:431
Code: 75 aa fd 48 8b 45 d0 48 8d b8 98 00 00 00 e8 4a cf f4 fe 45 89
e8 44 89 e1 4c 89 f2 48 89 c6 48 c7 c7 10 62 20 86 e8 8c 3e 99 fd <0f>
ff e9 ce f4 ff ff e8 c6 75 aa fd 48 8b 45 d0 48 8d b8 e8 00
---[ end trace bcf7836f85bb5e85 ]---
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: usb/sound/usx2y: WARNING in usb_stream_start
2017-11-03 14:44 usb/sound/usx2y: WARNING in usb_stream_start Andrey Konovalov
@ 2017-11-03 19:52 ` Takashi Iwai
0 siblings, 0 replies; 6+ messages in thread
From: Takashi Iwai @ 2017-11-03 19:52 UTC (permalink / raw)
To: Andrey Konovalov
Cc: alsa-devel, Arnd Bergmann, Arvind Yadav, Dave Jiang,
Johan Hovold, Mauro Carvalho Chehab, Andrew Morton,
Jaroslav Kysela, Markus Elfring, LKML, Dmitry Vyukov,
Kostya Serebryany, syzkaller
On Fri, 03 Nov 2017 15:44:59 +0100,
Andrey Konovalov wrote:
>
> Hi!
>
> I've got the following report while fuzzing the kernel with syzkaller.
>
> On commit 3a99df9a3d14cd866b5516f8cba515a3bfd554ab (4.14-rc7+).
>
> Looks like there's no check for the actual endpoint types.
>
> usb 1-1: BOGUS urb xfer, pipe 0 != type 3
> ------------[ cut here ]------------
> WARNING: CPU: 0 PID: 24 at drivers/usb/core/urb.c:471
> usb_submit_urb+0x113e/0x1400
> Modules linked in:
> CPU: 0 PID: 24 Comm: kworker/0:1 Not tainted
> 4.14.0-rc7-44290-gf28444df2601-dirty #52
> Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Bochs 01/01/2011
> Workqueue: usb_hub_wq hub_event
> task: ffff88006bef5c00 task.stack: ffff88006bf60000
> RIP: 0010:usb_submit_urb+0x113e/0x1400 drivers/usb/core/urb.c:470
> RSP: 0018:ffff88006bf67440 EFLAGS: 00010286
> RAX: 0000000000000029 RBX: ffff880064698c80 RCX: ffffffff812495b5
> RDX: 0000000000000000 RSI: ffffffff8124d76a RDI: 0000000000000005
> RBP: ffff88006bf674b0 R08: ffff88006bef5c00 R09: 0000000000000006
> R10: 0000000000000000 R11: 0000000000000000 R12: 0000000000000000
> R13: 0000000000000003 R14: ffff880069a25a20 R15: ffff880064698d04
> FS: 0000000000000000(0000) GS:ffff88006ca00000(0000) knlGS:0000000000000000
> CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
> CR2: 00007fe6fdba3000 CR3: 0000000068470000 CR4: 00000000000006f0
> Call Trace:
> usb_stream_start+0x48a/0x9f0 sound/usb/usx2y/usb_stream.c:690
> us122l_start+0x116/0x290 sound/usb/usx2y/us122l.c:365
(snip)
OK, so this looks like another typical issue.
A totally untested patch is below. Could you check whether it covers?
thanks,
Takashi
---
diff --git a/sound/usb/usx2y/usb_stream.c b/sound/usb/usx2y/usb_stream.c
index e229abd21652..5c4311b6afd6 100644
--- a/sound/usb/usx2y/usb_stream.c
+++ b/sound/usb/usx2y/usb_stream.c
@@ -56,7 +56,7 @@ static void playback_prep_freqn(struct usb_stream_kernel *sk, struct urb *urb)
lb, s->period_size);
}
-static void init_pipe_urbs(struct usb_stream_kernel *sk, unsigned use_packsize,
+static int init_pipe_urbs(struct usb_stream_kernel *sk, unsigned use_packsize,
struct urb **urbs, char *transfer,
struct usb_device *dev, int pipe)
{
@@ -77,6 +77,8 @@ static void init_pipe_urbs(struct usb_stream_kernel *sk, unsigned use_packsize,
urb->interval = 1;
if (usb_pipeout(pipe))
continue;
+ if (usb_urb_ep_type_check(urb))
+ return -EINVAL;
urb->transfer_buffer_length = transfer_length;
desc = urb->iso_frame_desc;
@@ -87,9 +89,11 @@ static void init_pipe_urbs(struct usb_stream_kernel *sk, unsigned use_packsize,
desc[p].length = maxpacket;
}
}
+
+ return 0;
}
-static void init_urbs(struct usb_stream_kernel *sk, unsigned use_packsize,
+static int init_urbs(struct usb_stream_kernel *sk, unsigned use_packsize,
struct usb_device *dev, int in_pipe, int out_pipe)
{
struct usb_stream *s = sk->s;
@@ -103,9 +107,13 @@ static void init_urbs(struct usb_stream_kernel *sk, unsigned use_packsize,
sk->outurb[u] = usb_alloc_urb(sk->n_o_ps, GFP_KERNEL);
}
- init_pipe_urbs(sk, use_packsize, sk->inurb, indata, dev, in_pipe);
- init_pipe_urbs(sk, use_packsize, sk->outurb, sk->write_page, dev,
- out_pipe);
+ if (init_pipe_urbs(sk, use_packsize, sk->inurb, indata, dev, in_pipe))
+ return -EINVAL;
+ if (init_pipe_urbs(sk, use_packsize, sk->outurb, sk->write_page, dev,
+ out_pipe))
+ return -EINVAL;
+
+ return 0;
}
@@ -226,7 +234,11 @@ struct usb_stream *usb_stream_new(struct usb_stream_kernel *sk,
else
sk->freqn = get_usb_high_speed_rate(sample_rate);
- init_urbs(sk, use_packsize, dev, in_pipe, out_pipe);
+ if (init_urbs(sk, use_packsize, dev, in_pipe, out_pipe) < 0) {
+ usb_stream_free(sk);
+ return NULL;
+ }
+
sk->s->state = usb_stream_stopped;
out:
return sk->s;
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: usb/sound/usx2y: WARNING in usb_stream_start
@ 2017-11-03 19:52 ` Takashi Iwai
0 siblings, 0 replies; 6+ messages in thread
From: Takashi Iwai @ 2017-11-03 19:52 UTC (permalink / raw)
To: Andrey Konovalov
Cc: alsa-devel, Arnd Bergmann, Arvind Yadav, Dave Jiang,
Johan Hovold, Mauro Carvalho Chehab, Andrew Morton,
Jaroslav Kysela, Markus Elfring, LKML, Dmitry Vyukov,
Kostya Serebryany, syzkaller
On Fri, 03 Nov 2017 15:44:59 +0100,
Andrey Konovalov wrote:
>
> Hi!
>
> I've got the following report while fuzzing the kernel with syzkaller.
>
> On commit 3a99df9a3d14cd866b5516f8cba515a3bfd554ab (4.14-rc7+).
>
> Looks like there's no check for the actual endpoint types.
>
> usb 1-1: BOGUS urb xfer, pipe 0 != type 3
> ------------[ cut here ]------------
> WARNING: CPU: 0 PID: 24 at drivers/usb/core/urb.c:471
> usb_submit_urb+0x113e/0x1400
> Modules linked in:
> CPU: 0 PID: 24 Comm: kworker/0:1 Not tainted
> 4.14.0-rc7-44290-gf28444df2601-dirty #52
> Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Bochs 01/01/2011
> Workqueue: usb_hub_wq hub_event
> task: ffff88006bef5c00 task.stack: ffff88006bf60000
> RIP: 0010:usb_submit_urb+0x113e/0x1400 drivers/usb/core/urb.c:470
> RSP: 0018:ffff88006bf67440 EFLAGS: 00010286
> RAX: 0000000000000029 RBX: ffff880064698c80 RCX: ffffffff812495b5
> RDX: 0000000000000000 RSI: ffffffff8124d76a RDI: 0000000000000005
> RBP: ffff88006bf674b0 R08: ffff88006bef5c00 R09: 0000000000000006
> R10: 0000000000000000 R11: 0000000000000000 R12: 0000000000000000
> R13: 0000000000000003 R14: ffff880069a25a20 R15: ffff880064698d04
> FS: 0000000000000000(0000) GS:ffff88006ca00000(0000) knlGS:0000000000000000
> CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
> CR2: 00007fe6fdba3000 CR3: 0000000068470000 CR4: 00000000000006f0
> Call Trace:
> usb_stream_start+0x48a/0x9f0 sound/usb/usx2y/usb_stream.c:690
> us122l_start+0x116/0x290 sound/usb/usx2y/us122l.c:365
(snip)
OK, so this looks like another typical issue.
A totally untested patch is below. Could you check whether it covers?
thanks,
Takashi
---
diff --git a/sound/usb/usx2y/usb_stream.c b/sound/usb/usx2y/usb_stream.c
index e229abd21652..5c4311b6afd6 100644
--- a/sound/usb/usx2y/usb_stream.c
+++ b/sound/usb/usx2y/usb_stream.c
@@ -56,7 +56,7 @@ static void playback_prep_freqn(struct usb_stream_kernel *sk, struct urb *urb)
lb, s->period_size);
}
-static void init_pipe_urbs(struct usb_stream_kernel *sk, unsigned use_packsize,
+static int init_pipe_urbs(struct usb_stream_kernel *sk, unsigned use_packsize,
struct urb **urbs, char *transfer,
struct usb_device *dev, int pipe)
{
@@ -77,6 +77,8 @@ static void init_pipe_urbs(struct usb_stream_kernel *sk, unsigned use_packsize,
urb->interval = 1;
if (usb_pipeout(pipe))
continue;
+ if (usb_urb_ep_type_check(urb))
+ return -EINVAL;
urb->transfer_buffer_length = transfer_length;
desc = urb->iso_frame_desc;
@@ -87,9 +89,11 @@ static void init_pipe_urbs(struct usb_stream_kernel *sk, unsigned use_packsize,
desc[p].length = maxpacket;
}
}
+
+ return 0;
}
-static void init_urbs(struct usb_stream_kernel *sk, unsigned use_packsize,
+static int init_urbs(struct usb_stream_kernel *sk, unsigned use_packsize,
struct usb_device *dev, int in_pipe, int out_pipe)
{
struct usb_stream *s = sk->s;
@@ -103,9 +107,13 @@ static void init_urbs(struct usb_stream_kernel *sk, unsigned use_packsize,
sk->outurb[u] = usb_alloc_urb(sk->n_o_ps, GFP_KERNEL);
}
- init_pipe_urbs(sk, use_packsize, sk->inurb, indata, dev, in_pipe);
- init_pipe_urbs(sk, use_packsize, sk->outurb, sk->write_page, dev,
- out_pipe);
+ if (init_pipe_urbs(sk, use_packsize, sk->inurb, indata, dev, in_pipe))
+ return -EINVAL;
+ if (init_pipe_urbs(sk, use_packsize, sk->outurb, sk->write_page, dev,
+ out_pipe))
+ return -EINVAL;
+
+ return 0;
}
@@ -226,7 +234,11 @@ struct usb_stream *usb_stream_new(struct usb_stream_kernel *sk,
else
sk->freqn = get_usb_high_speed_rate(sample_rate);
- init_urbs(sk, use_packsize, dev, in_pipe, out_pipe);
+ if (init_urbs(sk, use_packsize, dev, in_pipe, out_pipe) < 0) {
+ usb_stream_free(sk);
+ return NULL;
+ }
+
sk->s->state = usb_stream_stopped;
out:
return sk->s;
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: usb/sound/usx2y: WARNING in usb_stream_start
2017-11-03 19:52 ` Takashi Iwai
@ 2017-11-06 9:56 ` Takashi Iwai
-1 siblings, 0 replies; 6+ messages in thread
From: Takashi Iwai @ 2017-11-06 9:56 UTC (permalink / raw)
To: Andrey Konovalov
Cc: alsa-devel, Arnd Bergmann, Arvind Yadav, Dave Jiang,
Johan Hovold, Mauro Carvalho Chehab, Andrew Morton,
Jaroslav Kysela, Markus Elfring, LKML, Dmitry Vyukov,
Kostya Serebryany, syzkaller
On Fri, 03 Nov 2017 20:52:49 +0100,
Takashi Iwai wrote:
>
> On Fri, 03 Nov 2017 15:44:59 +0100,
> Andrey Konovalov wrote:
> >
> > Hi!
> >
> > I've got the following report while fuzzing the kernel with syzkaller.
> >
> > On commit 3a99df9a3d14cd866b5516f8cba515a3bfd554ab (4.14-rc7+).
> >
> > Looks like there's no check for the actual endpoint types.
> >
> > usb 1-1: BOGUS urb xfer, pipe 0 != type 3
> > ------------[ cut here ]------------
> > WARNING: CPU: 0 PID: 24 at drivers/usb/core/urb.c:471
> > usb_submit_urb+0x113e/0x1400
> > Modules linked in:
> > CPU: 0 PID: 24 Comm: kworker/0:1 Not tainted
> > 4.14.0-rc7-44290-gf28444df2601-dirty #52
> > Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Bochs 01/01/2011
> > Workqueue: usb_hub_wq hub_event
> > task: ffff88006bef5c00 task.stack: ffff88006bf60000
> > RIP: 0010:usb_submit_urb+0x113e/0x1400 drivers/usb/core/urb.c:470
> > RSP: 0018:ffff88006bf67440 EFLAGS: 00010286
> > RAX: 0000000000000029 RBX: ffff880064698c80 RCX: ffffffff812495b5
> > RDX: 0000000000000000 RSI: ffffffff8124d76a RDI: 0000000000000005
> > RBP: ffff88006bf674b0 R08: ffff88006bef5c00 R09: 0000000000000006
> > R10: 0000000000000000 R11: 0000000000000000 R12: 0000000000000000
> > R13: 0000000000000003 R14: ffff880069a25a20 R15: ffff880064698d04
> > FS: 0000000000000000(0000) GS:ffff88006ca00000(0000) knlGS:0000000000000000
> > CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
> > CR2: 00007fe6fdba3000 CR3: 0000000068470000 CR4: 00000000000006f0
> > Call Trace:
> > usb_stream_start+0x48a/0x9f0 sound/usb/usx2y/usb_stream.c:690
> > us122l_start+0x116/0x290 sound/usb/usx2y/us122l.c:365
> (snip)
>
> OK, so this looks like another typical issue.
> A totally untested patch is below. Could you check whether it covers?
FYI, below is the patch with a proper description that I queued to
for-next branch.
Takashi
-- 8< --
From: Takashi Iwai <tiwai@suse.de>
Subject: [PATCH] ALSA: usx2y: Fix invalid stream URBs
The us122l driver creates URBs per the fixed endpoints, and this may
end up with URBs with inconsistent pipes when a fuzzer or a malicious
program deals with the manipulated endpoints. It ends up with a
kernel warning like:
usb 1-1: BOGUS urb xfer, pipe 0 != type 3
------------[ cut here ]------------
WARNING: CPU: 0 PID: 24 at drivers/usb/core/urb.c:471
usb_submit_urb+0x113e/0x1400
Call Trace:
usb_stream_start+0x48a/0x9f0 sound/usb/usx2y/usb_stream.c:690
us122l_start+0x116/0x290 sound/usb/usx2y/us122l.c:365
us122l_create_card sound/usb/usx2y/us122l.c:502
us122l_usb_probe sound/usb/usx2y/us122l.c:588
....
For avoiding the bad access, this patch adds a few sanity checks of
the validity of created URBs like previous similar fixes using the new
usb_urb_ep_type_check() helper function.
Reported-by: Andrey Konovalov <andreyknvl@google.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
sound/usb/usx2y/usb_stream.c | 23 +++++++++++++++++------
1 file changed, 17 insertions(+), 6 deletions(-)
diff --git a/sound/usb/usx2y/usb_stream.c b/sound/usb/usx2y/usb_stream.c
index e229abd21652..b0f8979ff2d2 100644
--- a/sound/usb/usx2y/usb_stream.c
+++ b/sound/usb/usx2y/usb_stream.c
@@ -56,7 +56,7 @@ static void playback_prep_freqn(struct usb_stream_kernel *sk, struct urb *urb)
lb, s->period_size);
}
-static void init_pipe_urbs(struct usb_stream_kernel *sk, unsigned use_packsize,
+static int init_pipe_urbs(struct usb_stream_kernel *sk, unsigned use_packsize,
struct urb **urbs, char *transfer,
struct usb_device *dev, int pipe)
{
@@ -77,6 +77,8 @@ static void init_pipe_urbs(struct usb_stream_kernel *sk, unsigned use_packsize,
urb->interval = 1;
if (usb_pipeout(pipe))
continue;
+ if (usb_urb_ep_type_check(urb))
+ return -EINVAL;
urb->transfer_buffer_length = transfer_length;
desc = urb->iso_frame_desc;
@@ -87,9 +89,11 @@ static void init_pipe_urbs(struct usb_stream_kernel *sk, unsigned use_packsize,
desc[p].length = maxpacket;
}
}
+
+ return 0;
}
-static void init_urbs(struct usb_stream_kernel *sk, unsigned use_packsize,
+static int init_urbs(struct usb_stream_kernel *sk, unsigned use_packsize,
struct usb_device *dev, int in_pipe, int out_pipe)
{
struct usb_stream *s = sk->s;
@@ -103,9 +107,12 @@ static void init_urbs(struct usb_stream_kernel *sk, unsigned use_packsize,
sk->outurb[u] = usb_alloc_urb(sk->n_o_ps, GFP_KERNEL);
}
- init_pipe_urbs(sk, use_packsize, sk->inurb, indata, dev, in_pipe);
- init_pipe_urbs(sk, use_packsize, sk->outurb, sk->write_page, dev,
- out_pipe);
+ if (init_pipe_urbs(sk, use_packsize, sk->inurb, indata, dev, in_pipe) ||
+ init_pipe_urbs(sk, use_packsize, sk->outurb, sk->write_page, dev,
+ out_pipe))
+ return -EINVAL;
+
+ return 0;
}
@@ -226,7 +233,11 @@ struct usb_stream *usb_stream_new(struct usb_stream_kernel *sk,
else
sk->freqn = get_usb_high_speed_rate(sample_rate);
- init_urbs(sk, use_packsize, dev, in_pipe, out_pipe);
+ if (init_urbs(sk, use_packsize, dev, in_pipe, out_pipe) < 0) {
+ usb_stream_free(sk);
+ return NULL;
+ }
+
sk->s->state = usb_stream_stopped;
out:
return sk->s;
--
2.14.3
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: usb/sound/usx2y: WARNING in usb_stream_start
@ 2017-11-06 9:56 ` Takashi Iwai
0 siblings, 0 replies; 6+ messages in thread
From: Takashi Iwai @ 2017-11-06 9:56 UTC (permalink / raw)
To: Andrey Konovalov
Cc: alsa-devel, Arnd Bergmann, Arvind Yadav, Dave Jiang,
Johan Hovold, Mauro Carvalho Chehab, Andrew Morton,
Jaroslav Kysela, Markus Elfring, LKML, Dmitry Vyukov,
Kostya Serebryany, syzkaller
On Fri, 03 Nov 2017 20:52:49 +0100,
Takashi Iwai wrote:
>
> On Fri, 03 Nov 2017 15:44:59 +0100,
> Andrey Konovalov wrote:
> >
> > Hi!
> >
> > I've got the following report while fuzzing the kernel with syzkaller.
> >
> > On commit 3a99df9a3d14cd866b5516f8cba515a3bfd554ab (4.14-rc7+).
> >
> > Looks like there's no check for the actual endpoint types.
> >
> > usb 1-1: BOGUS urb xfer, pipe 0 != type 3
> > ------------[ cut here ]------------
> > WARNING: CPU: 0 PID: 24 at drivers/usb/core/urb.c:471
> > usb_submit_urb+0x113e/0x1400
> > Modules linked in:
> > CPU: 0 PID: 24 Comm: kworker/0:1 Not tainted
> > 4.14.0-rc7-44290-gf28444df2601-dirty #52
> > Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Bochs 01/01/2011
> > Workqueue: usb_hub_wq hub_event
> > task: ffff88006bef5c00 task.stack: ffff88006bf60000
> > RIP: 0010:usb_submit_urb+0x113e/0x1400 drivers/usb/core/urb.c:470
> > RSP: 0018:ffff88006bf67440 EFLAGS: 00010286
> > RAX: 0000000000000029 RBX: ffff880064698c80 RCX: ffffffff812495b5
> > RDX: 0000000000000000 RSI: ffffffff8124d76a RDI: 0000000000000005
> > RBP: ffff88006bf674b0 R08: ffff88006bef5c00 R09: 0000000000000006
> > R10: 0000000000000000 R11: 0000000000000000 R12: 0000000000000000
> > R13: 0000000000000003 R14: ffff880069a25a20 R15: ffff880064698d04
> > FS: 0000000000000000(0000) GS:ffff88006ca00000(0000) knlGS:0000000000000000
> > CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
> > CR2: 00007fe6fdba3000 CR3: 0000000068470000 CR4: 00000000000006f0
> > Call Trace:
> > usb_stream_start+0x48a/0x9f0 sound/usb/usx2y/usb_stream.c:690
> > us122l_start+0x116/0x290 sound/usb/usx2y/us122l.c:365
> (snip)
>
> OK, so this looks like another typical issue.
> A totally untested patch is below. Could you check whether it covers?
FYI, below is the patch with a proper description that I queued to
for-next branch.
Takashi
-- 8< --
From: Takashi Iwai <tiwai@suse.de>
Subject: [PATCH] ALSA: usx2y: Fix invalid stream URBs
The us122l driver creates URBs per the fixed endpoints, and this may
end up with URBs with inconsistent pipes when a fuzzer or a malicious
program deals with the manipulated endpoints. It ends up with a
kernel warning like:
usb 1-1: BOGUS urb xfer, pipe 0 != type 3
------------[ cut here ]------------
WARNING: CPU: 0 PID: 24 at drivers/usb/core/urb.c:471
usb_submit_urb+0x113e/0x1400
Call Trace:
usb_stream_start+0x48a/0x9f0 sound/usb/usx2y/usb_stream.c:690
us122l_start+0x116/0x290 sound/usb/usx2y/us122l.c:365
us122l_create_card sound/usb/usx2y/us122l.c:502
us122l_usb_probe sound/usb/usx2y/us122l.c:588
....
For avoiding the bad access, this patch adds a few sanity checks of
the validity of created URBs like previous similar fixes using the new
usb_urb_ep_type_check() helper function.
Reported-by: Andrey Konovalov <andreyknvl@google.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
sound/usb/usx2y/usb_stream.c | 23 +++++++++++++++++------
1 file changed, 17 insertions(+), 6 deletions(-)
diff --git a/sound/usb/usx2y/usb_stream.c b/sound/usb/usx2y/usb_stream.c
index e229abd21652..b0f8979ff2d2 100644
--- a/sound/usb/usx2y/usb_stream.c
+++ b/sound/usb/usx2y/usb_stream.c
@@ -56,7 +56,7 @@ static void playback_prep_freqn(struct usb_stream_kernel *sk, struct urb *urb)
lb, s->period_size);
}
-static void init_pipe_urbs(struct usb_stream_kernel *sk, unsigned use_packsize,
+static int init_pipe_urbs(struct usb_stream_kernel *sk, unsigned use_packsize,
struct urb **urbs, char *transfer,
struct usb_device *dev, int pipe)
{
@@ -77,6 +77,8 @@ static void init_pipe_urbs(struct usb_stream_kernel *sk, unsigned use_packsize,
urb->interval = 1;
if (usb_pipeout(pipe))
continue;
+ if (usb_urb_ep_type_check(urb))
+ return -EINVAL;
urb->transfer_buffer_length = transfer_length;
desc = urb->iso_frame_desc;
@@ -87,9 +89,11 @@ static void init_pipe_urbs(struct usb_stream_kernel *sk, unsigned use_packsize,
desc[p].length = maxpacket;
}
}
+
+ return 0;
}
-static void init_urbs(struct usb_stream_kernel *sk, unsigned use_packsize,
+static int init_urbs(struct usb_stream_kernel *sk, unsigned use_packsize,
struct usb_device *dev, int in_pipe, int out_pipe)
{
struct usb_stream *s = sk->s;
@@ -103,9 +107,12 @@ static void init_urbs(struct usb_stream_kernel *sk, unsigned use_packsize,
sk->outurb[u] = usb_alloc_urb(sk->n_o_ps, GFP_KERNEL);
}
- init_pipe_urbs(sk, use_packsize, sk->inurb, indata, dev, in_pipe);
- init_pipe_urbs(sk, use_packsize, sk->outurb, sk->write_page, dev,
- out_pipe);
+ if (init_pipe_urbs(sk, use_packsize, sk->inurb, indata, dev, in_pipe) ||
+ init_pipe_urbs(sk, use_packsize, sk->outurb, sk->write_page, dev,
+ out_pipe))
+ return -EINVAL;
+
+ return 0;
}
@@ -226,7 +233,11 @@ struct usb_stream *usb_stream_new(struct usb_stream_kernel *sk,
else
sk->freqn = get_usb_high_speed_rate(sample_rate);
- init_urbs(sk, use_packsize, dev, in_pipe, out_pipe);
+ if (init_urbs(sk, use_packsize, dev, in_pipe, out_pipe) < 0) {
+ usb_stream_free(sk);
+ return NULL;
+ }
+
sk->s->state = usb_stream_stopped;
out:
return sk->s;
--
2.14.3
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: usb/sound/usx2y: WARNING in usb_stream_start
2017-11-06 9:56 ` Takashi Iwai
(?)
@ 2017-11-06 12:14 ` Andrey Konovalov
-1 siblings, 0 replies; 6+ messages in thread
From: Andrey Konovalov @ 2017-11-06 12:14 UTC (permalink / raw)
To: Takashi Iwai
Cc: alsa-devel, Arnd Bergmann, Arvind Yadav, Dave Jiang,
Johan Hovold, Mauro Carvalho Chehab, Andrew Morton,
Jaroslav Kysela, Markus Elfring, LKML, Dmitry Vyukov,
Kostya Serebryany, syzkaller
On Mon, Nov 6, 2017 at 10:56 AM, Takashi Iwai <tiwai@suse.de> wrote:
> On Fri, 03 Nov 2017 20:52:49 +0100,
> Takashi Iwai wrote:
>>
>> On Fri, 03 Nov 2017 15:44:59 +0100,
>> Andrey Konovalov wrote:
>> >
>> > Hi!
>> >
>> > I've got the following report while fuzzing the kernel with syzkaller.
>> >
>> > On commit 3a99df9a3d14cd866b5516f8cba515a3bfd554ab (4.14-rc7+).
>> >
>> > Looks like there's no check for the actual endpoint types.
>> >
>> > usb 1-1: BOGUS urb xfer, pipe 0 != type 3
>> > ------------[ cut here ]------------
>> > WARNING: CPU: 0 PID: 24 at drivers/usb/core/urb.c:471
>> > usb_submit_urb+0x113e/0x1400
>> > Modules linked in:
>> > CPU: 0 PID: 24 Comm: kworker/0:1 Not tainted
>> > 4.14.0-rc7-44290-gf28444df2601-dirty #52
>> > Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Bochs 01/01/2011
>> > Workqueue: usb_hub_wq hub_event
>> > task: ffff88006bef5c00 task.stack: ffff88006bf60000
>> > RIP: 0010:usb_submit_urb+0x113e/0x1400 drivers/usb/core/urb.c:470
>> > RSP: 0018:ffff88006bf67440 EFLAGS: 00010286
>> > RAX: 0000000000000029 RBX: ffff880064698c80 RCX: ffffffff812495b5
>> > RDX: 0000000000000000 RSI: ffffffff8124d76a RDI: 0000000000000005
>> > RBP: ffff88006bf674b0 R08: ffff88006bef5c00 R09: 0000000000000006
>> > R10: 0000000000000000 R11: 0000000000000000 R12: 0000000000000000
>> > R13: 0000000000000003 R14: ffff880069a25a20 R15: ffff880064698d04
>> > FS: 0000000000000000(0000) GS:ffff88006ca00000(0000) knlGS:0000000000000000
>> > CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
>> > CR2: 00007fe6fdba3000 CR3: 0000000068470000 CR4: 00000000000006f0
>> > Call Trace:
>> > usb_stream_start+0x48a/0x9f0 sound/usb/usx2y/usb_stream.c:690
>> > us122l_start+0x116/0x290 sound/usb/usx2y/us122l.c:365
>> (snip)
>>
>> OK, so this looks like another typical issue.
>> A totally untested patch is below. Could you check whether it covers?
>
> FYI, below is the patch with a proper description that I queued to
> for-next branch.
This patch fixes the issue.
Thanks!
Tested-by: Andrey Konovalov <andreyknvl@google.com>
>
>
> Takashi
>
> -- 8< --
> From: Takashi Iwai <tiwai@suse.de>
> Subject: [PATCH] ALSA: usx2y: Fix invalid stream URBs
>
> The us122l driver creates URBs per the fixed endpoints, and this may
> end up with URBs with inconsistent pipes when a fuzzer or a malicious
> program deals with the manipulated endpoints. It ends up with a
> kernel warning like:
>
> usb 1-1: BOGUS urb xfer, pipe 0 != type 3
> ------------[ cut here ]------------
> WARNING: CPU: 0 PID: 24 at drivers/usb/core/urb.c:471
> usb_submit_urb+0x113e/0x1400
> Call Trace:
> usb_stream_start+0x48a/0x9f0 sound/usb/usx2y/usb_stream.c:690
> us122l_start+0x116/0x290 sound/usb/usx2y/us122l.c:365
> us122l_create_card sound/usb/usx2y/us122l.c:502
> us122l_usb_probe sound/usb/usx2y/us122l.c:588
> ....
>
> For avoiding the bad access, this patch adds a few sanity checks of
> the validity of created URBs like previous similar fixes using the new
> usb_urb_ep_type_check() helper function.
>
> Reported-by: Andrey Konovalov <andreyknvl@google.com>
> Signed-off-by: Takashi Iwai <tiwai@suse.de>
> ---
> sound/usb/usx2y/usb_stream.c | 23 +++++++++++++++++------
> 1 file changed, 17 insertions(+), 6 deletions(-)
>
> diff --git a/sound/usb/usx2y/usb_stream.c b/sound/usb/usx2y/usb_stream.c
> index e229abd21652..b0f8979ff2d2 100644
> --- a/sound/usb/usx2y/usb_stream.c
> +++ b/sound/usb/usx2y/usb_stream.c
> @@ -56,7 +56,7 @@ static void playback_prep_freqn(struct usb_stream_kernel *sk, struct urb *urb)
> lb, s->period_size);
> }
>
> -static void init_pipe_urbs(struct usb_stream_kernel *sk, unsigned use_packsize,
> +static int init_pipe_urbs(struct usb_stream_kernel *sk, unsigned use_packsize,
> struct urb **urbs, char *transfer,
> struct usb_device *dev, int pipe)
> {
> @@ -77,6 +77,8 @@ static void init_pipe_urbs(struct usb_stream_kernel *sk, unsigned use_packsize,
> urb->interval = 1;
> if (usb_pipeout(pipe))
> continue;
> + if (usb_urb_ep_type_check(urb))
> + return -EINVAL;
>
> urb->transfer_buffer_length = transfer_length;
> desc = urb->iso_frame_desc;
> @@ -87,9 +89,11 @@ static void init_pipe_urbs(struct usb_stream_kernel *sk, unsigned use_packsize,
> desc[p].length = maxpacket;
> }
> }
> +
> + return 0;
> }
>
> -static void init_urbs(struct usb_stream_kernel *sk, unsigned use_packsize,
> +static int init_urbs(struct usb_stream_kernel *sk, unsigned use_packsize,
> struct usb_device *dev, int in_pipe, int out_pipe)
> {
> struct usb_stream *s = sk->s;
> @@ -103,9 +107,12 @@ static void init_urbs(struct usb_stream_kernel *sk, unsigned use_packsize,
> sk->outurb[u] = usb_alloc_urb(sk->n_o_ps, GFP_KERNEL);
> }
>
> - init_pipe_urbs(sk, use_packsize, sk->inurb, indata, dev, in_pipe);
> - init_pipe_urbs(sk, use_packsize, sk->outurb, sk->write_page, dev,
> - out_pipe);
> + if (init_pipe_urbs(sk, use_packsize, sk->inurb, indata, dev, in_pipe) ||
> + init_pipe_urbs(sk, use_packsize, sk->outurb, sk->write_page, dev,
> + out_pipe))
> + return -EINVAL;
> +
> + return 0;
> }
>
>
> @@ -226,7 +233,11 @@ struct usb_stream *usb_stream_new(struct usb_stream_kernel *sk,
> else
> sk->freqn = get_usb_high_speed_rate(sample_rate);
>
> - init_urbs(sk, use_packsize, dev, in_pipe, out_pipe);
> + if (init_urbs(sk, use_packsize, dev, in_pipe, out_pipe) < 0) {
> + usb_stream_free(sk);
> + return NULL;
> + }
> +
> sk->s->state = usb_stream_stopped;
> out:
> return sk->s;
> --
> 2.14.3
>
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2017-11-06 12:14 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-03 14:44 usb/sound/usx2y: WARNING in usb_stream_start Andrey Konovalov
2017-11-03 19:52 ` Takashi Iwai
2017-11-03 19:52 ` Takashi Iwai
2017-11-06 9:56 ` Takashi Iwai
2017-11-06 9:56 ` Takashi Iwai
2017-11-06 12:14 ` Andrey Konovalov
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.