linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* KASAN: use-after-free Read in usbvision_v4l2_open
@ 2019-12-09 22:15 syzbot
  2019-12-10 19:47 ` Alan Stern
  0 siblings, 1 reply; 30+ messages in thread
From: syzbot @ 2019-12-09 22:15 UTC (permalink / raw)
  To: andreyknvl, hverkuil, jrdr.linux, linux-kernel, linux-media,
	linux-usb, mchehab, rfontana, stern, syzkaller-bugs, tglx

Hello,

syzbot found the following crash on:

HEAD commit:    1f22d15c usb: gadget: add raw-gadget interface
git tree:       https://github.com/google/kasan.git usb-fuzzer
console output: https://syzkaller.appspot.com/x/log.txt?x=1296f42ae00000
kernel config:  https://syzkaller.appspot.com/x/.config?x=8ccee2968018adcb
dashboard link: https://syzkaller.appspot.com/bug?extid=c7b0ec009a216143df30
compiler:       gcc (GCC) 9.0.0 20181231 (experimental)

Unfortunately, I don't have any reproducer for this crash yet.

IMPORTANT: if you fix the bug, please add the following tag to the commit:
Reported-by: syzbot+c7b0ec009a216143df30@syzkaller.appspotmail.com

==================================================================
BUG: KASAN: use-after-free in __mutex_lock_common  
kernel/locking/mutex.c:1043 [inline]
BUG: KASAN: use-after-free in __mutex_lock+0x124d/0x1360  
kernel/locking/mutex.c:1106
Read of size 8 at addr ffff8881cad4d8b8 by task v4l_id/4526

CPU: 0 PID: 4526 Comm: v4l_id Not tainted 5.4.0-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS  
Google 01/01/2011
Call Trace:
  __dump_stack lib/dump_stack.c:77 [inline]
  dump_stack+0xef/0x16e lib/dump_stack.c:118
  print_address_description.constprop.0+0x36/0x50 mm/kasan/report.c:374
  __kasan_report.cold+0x1a/0x33 mm/kasan/report.c:506
  kasan_report+0xe/0x20 mm/kasan/common.c:638
  __mutex_lock_common kernel/locking/mutex.c:1043 [inline]
  __mutex_lock+0x124d/0x1360 kernel/locking/mutex.c:1106
  usbvision_v4l2_open+0x77/0x340  
drivers/media/usb/usbvision/usbvision-video.c:314
  v4l2_open+0x20f/0x3d0 drivers/media/v4l2-core/v4l2-dev.c:423
  chrdev_open+0x219/0x5c0 fs/char_dev.c:414
  do_dentry_open+0x494/0x1120 fs/open.c:797
  do_last fs/namei.c:3412 [inline]
  path_openat+0x142b/0x4030 fs/namei.c:3529
  do_filp_open+0x1a1/0x280 fs/namei.c:3559
  do_sys_open+0x3c0/0x580 fs/open.c:1097
  do_syscall_64+0xb7/0x5b0 arch/x86/entry/common.c:294
  entry_SYSCALL_64_after_hwframe+0x49/0xbe
RIP: 0033:0x7f70d3cab120
Code: 48 8b 15 1b 4d 2b 00 f7 d8 64 89 02 83 c8 ff c3 90 90 90 90 90 90 90  
90 90 90 83 3d d5 a4 2b 00 00 75 10 b8 02 00 00 00 0f 05 <48> 3d 01 f0 ff  
ff 73 31 c3 48 83 ec 08 e8 5e 8c 01 00 48 89 04 24
RSP: 002b:00007ffc46d40ca8 EFLAGS: 00000246 ORIG_RAX: 0000000000000002
RAX: ffffffffffffffda RBX: 00007ffc46d40e08 RCX: 00007f70d3cab120
RDX: 00007f70d3f60138 RSI: 0000000000000000 RDI: 00007ffc46d42f1d
RBP: 0000000000000000 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000400884
R13: 00007ffc46d40e00 R14: 0000000000000000 R15: 0000000000000000

Allocated by task 12:
  save_stack+0x1b/0x80 mm/kasan/common.c:71
  set_track mm/kasan/common.c:79 [inline]
  __kasan_kmalloc mm/kasan/common.c:512 [inline]
  __kasan_kmalloc.constprop.0+0xbf/0xd0 mm/kasan/common.c:485
  kmalloc include/linux/slab.h:556 [inline]
  kzalloc include/linux/slab.h:670 [inline]
  usbvision_alloc drivers/media/usb/usbvision/usbvision-video.c:1315 [inline]
  usbvision_probe.cold+0x5c5/0x1f1e  
drivers/media/usb/usbvision/usbvision-video.c:1469
  usb_probe_interface+0x305/0x7a0 drivers/usb/core/driver.c:361
  really_probe+0x281/0x6d0 drivers/base/dd.c:548
  driver_probe_device+0x104/0x210 drivers/base/dd.c:721
  __device_attach_driver+0x1c2/0x220 drivers/base/dd.c:828
  bus_for_each_drv+0x162/0x1e0 drivers/base/bus.c:430
  __device_attach+0x217/0x360 drivers/base/dd.c:894
  bus_probe_device+0x1e4/0x290 drivers/base/bus.c:490
  device_add+0x1480/0x1c20 drivers/base/core.c:2487
  usb_set_configuration+0xe67/0x1740 drivers/usb/core/message.c:2023
  generic_probe+0x9d/0xd5 drivers/usb/core/generic.c:210
  usb_probe_device+0x99/0x100 drivers/usb/core/driver.c:266
  really_probe+0x281/0x6d0 drivers/base/dd.c:548
  driver_probe_device+0x104/0x210 drivers/base/dd.c:721
  __device_attach_driver+0x1c2/0x220 drivers/base/dd.c:828
  bus_for_each_drv+0x162/0x1e0 drivers/base/bus.c:430
  __device_attach+0x217/0x360 drivers/base/dd.c:894
  bus_probe_device+0x1e4/0x290 drivers/base/bus.c:490
  device_add+0x1480/0x1c20 drivers/base/core.c:2487
  usb_new_device.cold+0x6a4/0xe79 drivers/usb/core/hub.c:2537
  hub_port_connect drivers/usb/core/hub.c:5184 [inline]
  hub_port_connect_change drivers/usb/core/hub.c:5324 [inline]
  port_event drivers/usb/core/hub.c:5470 [inline]
  hub_event+0x1e59/0x3860 drivers/usb/core/hub.c:5552
  process_one_work+0x92b/0x1530 kernel/workqueue.c:2264
  worker_thread+0x96/0xe20 kernel/workqueue.c:2410
  kthread+0x318/0x420 kernel/kthread.c:255
  ret_from_fork+0x24/0x30 arch/x86/entry/entry_64.S:352

Freed by task 3310:
  save_stack+0x1b/0x80 mm/kasan/common.c:71
  set_track mm/kasan/common.c:79 [inline]
  kasan_set_free_info mm/kasan/common.c:334 [inline]
  __kasan_slab_free+0x130/0x180 mm/kasan/common.c:473
  slab_free_hook mm/slub.c:1425 [inline]
  slab_free_freelist_hook mm/slub.c:1458 [inline]
  slab_free mm/slub.c:3005 [inline]
  kfree+0xdc/0x310 mm/slub.c:3957
  usbvision_release+0x181/0x1c0  
drivers/media/usb/usbvision/usbvision-video.c:1364
  usbvision_disconnect+0x171/0x1e0  
drivers/media/usb/usbvision/usbvision-video.c:1589
  usb_unbind_interface+0x1bd/0x8a0 drivers/usb/core/driver.c:423
  __device_release_driver drivers/base/dd.c:1134 [inline]
  device_release_driver_internal+0x42f/0x500 drivers/base/dd.c:1165
  bus_remove_device+0x2dc/0x4a0 drivers/base/bus.c:532
  device_del+0x481/0xd30 drivers/base/core.c:2664
  usb_disable_device+0x211/0x690 drivers/usb/core/message.c:1237
  usb_disconnect+0x284/0x8d0 drivers/usb/core/hub.c:2200
  hub_port_connect drivers/usb/core/hub.c:5035 [inline]
  hub_port_connect_change drivers/usb/core/hub.c:5324 [inline]
  port_event drivers/usb/core/hub.c:5470 [inline]
  hub_event+0x1753/0x3860 drivers/usb/core/hub.c:5552
  process_one_work+0x92b/0x1530 kernel/workqueue.c:2264
  worker_thread+0x96/0xe20 kernel/workqueue.c:2410
  kthread+0x318/0x420 kernel/kthread.c:255
  ret_from_fork+0x24/0x30 arch/x86/entry/entry_64.S:352

The buggy address belongs to the object at ffff8881cad4c000
  which belongs to the cache kmalloc-8k of size 8192
The buggy address is located 6328 bytes inside of
  8192-byte region [ffff8881cad4c000, ffff8881cad4e000)
The buggy address belongs to the page:
page:ffffea00072b5200 refcount:1 mapcount:0 mapping:ffff8881da40c500  
index:0x0 compound_mapcount: 0
raw: 0200000000010200 ffffea0007249a00 0000000200000002 ffff8881da40c500
raw: 0000000000000000 0000000080020002 00000001ffffffff 0000000000000000
page dumped because: kasan: bad access detected

Memory state around the buggy address:
  ffff8881cad4d780: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
  ffff8881cad4d800: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
> ffff8881cad4d880: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
                                         ^
  ffff8881cad4d900: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
  ffff8881cad4d980: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================


---
This bug is generated by a bot. It may contain errors.
See https://goo.gl/tpsmEJ for more information about syzbot.
syzbot engineers can be reached at syzkaller@googlegroups.com.

syzbot will keep track of this bug report. See:
https://goo.gl/tpsmEJ#status for how to communicate with syzbot.

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: KASAN: use-after-free Read in usbvision_v4l2_open
  2019-12-09 22:15 KASAN: use-after-free Read in usbvision_v4l2_open syzbot
@ 2019-12-10 19:47 ` Alan Stern
  2019-12-10 19:48   ` syzbot
                     ` (2 more replies)
  0 siblings, 3 replies; 30+ messages in thread
From: Alan Stern @ 2019-12-10 19:47 UTC (permalink / raw)
  To: syzbot
  Cc: andreyknvl, hverkuil, jrdr.linux, linux-kernel, linux-media,
	linux-usb, mchehab, rfontana, syzkaller-bugs, tglx

On Mon, 9 Dec 2019, syzbot wrote:

> Hello,
> 
> syzbot found the following crash on:
> 
> HEAD commit:    1f22d15c usb: gadget: add raw-gadget interface
> git tree:       https://github.com/google/kasan.git usb-fuzzer
> console output: https://syzkaller.appspot.com/x/log.txt?x=1296f42ae00000
> kernel config:  https://syzkaller.appspot.com/x/.config?x=8ccee2968018adcb
> dashboard link: https://syzkaller.appspot.com/bug?extid=c7b0ec009a216143df30
> compiler:       gcc (GCC) 9.0.0 20181231 (experimental)
> 
> Unfortunately, I don't have any reproducer for this crash yet.
> 
> IMPORTANT: if you fix the bug, please add the following tag to the commit:
> Reported-by: syzbot+c7b0ec009a216143df30@syzkaller.appspotmail.com
> 
> ==================================================================
> BUG: KASAN: use-after-free in __mutex_lock_common  
> kernel/locking/mutex.c:1043 [inline]
> BUG: KASAN: use-after-free in __mutex_lock+0x124d/0x1360  
> kernel/locking/mutex.c:1106
> Read of size 8 at addr ffff8881cad4d8b8 by task v4l_id/4526
> 
> CPU: 0 PID: 4526 Comm: v4l_id Not tainted 5.4.0-syzkaller #0
> Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS  
> Google 01/01/2011
> Call Trace:
>   __dump_stack lib/dump_stack.c:77 [inline]
>   dump_stack+0xef/0x16e lib/dump_stack.c:118
>   print_address_description.constprop.0+0x36/0x50 mm/kasan/report.c:374
>   __kasan_report.cold+0x1a/0x33 mm/kasan/report.c:506
>   kasan_report+0xe/0x20 mm/kasan/common.c:638
>   __mutex_lock_common kernel/locking/mutex.c:1043 [inline]
>   __mutex_lock+0x124d/0x1360 kernel/locking/mutex.c:1106
>   usbvision_v4l2_open+0x77/0x340  
> drivers/media/usb/usbvision/usbvision-video.c:314
>   v4l2_open+0x20f/0x3d0 drivers/media/v4l2-core/v4l2-dev.c:423
>   chrdev_open+0x219/0x5c0 fs/char_dev.c:414
>   do_dentry_open+0x494/0x1120 fs/open.c:797
>   do_last fs/namei.c:3412 [inline]
>   path_openat+0x142b/0x4030 fs/namei.c:3529
>   do_filp_open+0x1a1/0x280 fs/namei.c:3559
>   do_sys_open+0x3c0/0x580 fs/open.c:1097
>   do_syscall_64+0xb7/0x5b0 arch/x86/entry/common.c:294
>   entry_SYSCALL_64_after_hwframe+0x49/0xbe

This looks like a race in v4l2_open(): The function drops the
videodev_lock mutex before calling the video driver's open routine, and
the device can be unregistered during the short time between.

This patch tries to make the race much more likely to happen, for 
testing and verification.

Andrey, will syzbot run the same test with this patch, even though it 
says it doesn't have a reproducer?

Alan Stern

#syz test: https://github.com/google/kasan.git 1f22d15c

Index: usb-devel/drivers/media/usb/usbvision/usbvision-video.c
===================================================================
--- usb-devel.orig/drivers/media/usb/usbvision/usbvision-video.c
+++ usb-devel/drivers/media/usb/usbvision/usbvision-video.c
@@ -1585,6 +1585,7 @@ static void usbvision_disconnect(struct
 		wake_up_interruptible(&usbvision->wait_frame);
 		wake_up_interruptible(&usbvision->wait_stream);
 	} else {
+		msleep(100);
 		usbvision_release(usbvision);
 	}
 
Index: usb-devel/drivers/media/v4l2-core/v4l2-dev.c
===================================================================
--- usb-devel.orig/drivers/media/v4l2-core/v4l2-dev.c
+++ usb-devel/drivers/media/v4l2-core/v4l2-dev.c
@@ -419,9 +419,10 @@ static int v4l2_open(struct inode *inode
 	video_get(vdev);
 	mutex_unlock(&videodev_lock);
 	if (vdev->fops->open) {
-		if (video_is_registered(vdev))
+		if (video_is_registered(vdev)) {
+			msleep(200);
 			ret = vdev->fops->open(filp);
-		else
+		} else
 			ret = -ENODEV;
 	}
 


^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: Re: KASAN: use-after-free Read in usbvision_v4l2_open
  2019-12-10 19:47 ` Alan Stern
@ 2019-12-10 19:48   ` syzbot
  2019-12-10 20:17     ` Alan Stern
  2019-12-10 19:48   ` Re: KASAN: use-after-free Read in usbvision_v4l2_open syzbot
  2019-12-10 20:06   ` Andrey Konovalov
  2 siblings, 1 reply; 30+ messages in thread
From: syzbot @ 2019-12-10 19:48 UTC (permalink / raw)
  To: Alan Stern
  Cc: andreyknvl, hverkuil, jrdr.linux, linux-kernel, linux-media,
	linux-usb, mchehab, rfontana, stern, syzkaller-bugs, tglx

> On Mon, 9 Dec 2019, syzbot wrote:

>> Hello,

>> syzbot found the following crash on:

>> HEAD commit:    1f22d15c usb: gadget: add raw-gadget interface
>> git tree:       https://github.com/google/kasan.git usb-fuzzer
>> console output: https://syzkaller.appspot.com/x/log.txt?x=1296f42ae00000
>> kernel config:   
>> https://syzkaller.appspot.com/x/.config?x=8ccee2968018adcb
>> dashboard link:  
>> https://syzkaller.appspot.com/bug?extid=c7b0ec009a216143df30
>> compiler:       gcc (GCC) 9.0.0 20181231 (experimental)

>> Unfortunately, I don't have any reproducer for this crash yet.

>> IMPORTANT: if you fix the bug, please add the following tag to the  
>> commit:
>> Reported-by: syzbot+c7b0ec009a216143df30@syzkaller.appspotmail.com

>> ==================================================================
>> BUG: KASAN: use-after-free in __mutex_lock_common
>> kernel/locking/mutex.c:1043 [inline]
>> BUG: KASAN: use-after-free in __mutex_lock+0x124d/0x1360
>> kernel/locking/mutex.c:1106
>> Read of size 8 at addr ffff8881cad4d8b8 by task v4l_id/4526

>> CPU: 0 PID: 4526 Comm: v4l_id Not tainted 5.4.0-syzkaller #0
>> Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS
>> Google 01/01/2011
>> Call Trace:
>>    __dump_stack lib/dump_stack.c:77 [inline]
>>    dump_stack+0xef/0x16e lib/dump_stack.c:118
>>    print_address_description.constprop.0+0x36/0x50 mm/kasan/report.c:374
>>    __kasan_report.cold+0x1a/0x33 mm/kasan/report.c:506
>>    kasan_report+0xe/0x20 mm/kasan/common.c:638
>>    __mutex_lock_common kernel/locking/mutex.c:1043 [inline]
>>    __mutex_lock+0x124d/0x1360 kernel/locking/mutex.c:1106
>>    usbvision_v4l2_open+0x77/0x340
>> drivers/media/usb/usbvision/usbvision-video.c:314
>>    v4l2_open+0x20f/0x3d0 drivers/media/v4l2-core/v4l2-dev.c:423
>>    chrdev_open+0x219/0x5c0 fs/char_dev.c:414
>>    do_dentry_open+0x494/0x1120 fs/open.c:797
>>    do_last fs/namei.c:3412 [inline]
>>    path_openat+0x142b/0x4030 fs/namei.c:3529
>>    do_filp_open+0x1a1/0x280 fs/namei.c:3559
>>    do_sys_open+0x3c0/0x580 fs/open.c:1097
>>    do_syscall_64+0xb7/0x5b0 arch/x86/entry/common.c:294
>>    entry_SYSCALL_64_after_hwframe+0x49/0xbe

> This looks like a race in v4l2_open(): The function drops the
> videodev_lock mutex before calling the video driver's open routine, and
> the device can be unregistered during the short time between.

> This patch tries to make the race much more likely to happen, for
> testing and verification.

> Andrey, will syzbot run the same test with this patch, even though it
> says it doesn't have a reproducer?

> Alan Stern

> #syz test: https://github.com/google/kasan.git 1f22d15c

This crash does not have a reproducer. I cannot test it.


> Index: usb-devel/drivers/media/usb/usbvision/usbvision-video.c
> ===================================================================
> --- usb-devel.orig/drivers/media/usb/usbvision/usbvision-video.c
> +++ usb-devel/drivers/media/usb/usbvision/usbvision-video.c
> @@ -1585,6 +1585,7 @@ static void usbvision_disconnect(struct
>   		wake_up_interruptible(&usbvision->wait_frame);
>   		wake_up_interruptible(&usbvision->wait_stream);
>   	} else {
> +		msleep(100);
>   		usbvision_release(usbvision);
>   	}

> Index: usb-devel/drivers/media/v4l2-core/v4l2-dev.c
> ===================================================================
> --- usb-devel.orig/drivers/media/v4l2-core/v4l2-dev.c
> +++ usb-devel/drivers/media/v4l2-core/v4l2-dev.c
> @@ -419,9 +419,10 @@ static int v4l2_open(struct inode *inode
>   	video_get(vdev);
>   	mutex_unlock(&videodev_lock);
>   	if (vdev->fops->open) {
> -		if (video_is_registered(vdev))
> +		if (video_is_registered(vdev)) {
> +			msleep(200);
>   			ret = vdev->fops->open(filp);
> -		else
> +		} else
>   			ret = -ENODEV;
>   	}



^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: Re: KASAN: use-after-free Read in usbvision_v4l2_open
  2019-12-10 19:47 ` Alan Stern
  2019-12-10 19:48   ` syzbot
@ 2019-12-10 19:48   ` syzbot
  2019-12-10 20:06   ` Andrey Konovalov
  2 siblings, 0 replies; 30+ messages in thread
From: syzbot @ 2019-12-10 19:48 UTC (permalink / raw)
  To: Alan Stern
  Cc: andreyknvl, hverkuil, jrdr.linux, linux-kernel, linux-media,
	linux-usb, mchehab, rfontana, stern, syzkaller-bugs, tglx

> On Mon, 9 Dec 2019, syzbot wrote:

>> Hello,

>> syzbot found the following crash on:

>> HEAD commit:    1f22d15c usb: gadget: add raw-gadget interface
>> git tree:       https://github.com/google/kasan.git usb-fuzzer
>> console output: https://syzkaller.appspot.com/x/log.txt?x=1296f42ae00000
>> kernel config:   
>> https://syzkaller.appspot.com/x/.config?x=8ccee2968018adcb
>> dashboard link:  
>> https://syzkaller.appspot.com/bug?extid=c7b0ec009a216143df30
>> compiler:       gcc (GCC) 9.0.0 20181231 (experimental)

>> Unfortunately, I don't have any reproducer for this crash yet.

>> IMPORTANT: if you fix the bug, please add the following tag to the  
>> commit:
>> Reported-by: syzbot+c7b0ec009a216143df30@syzkaller.appspotmail.com

>> ==================================================================
>> BUG: KASAN: use-after-free in __mutex_lock_common
>> kernel/locking/mutex.c:1043 [inline]
>> BUG: KASAN: use-after-free in __mutex_lock+0x124d/0x1360
>> kernel/locking/mutex.c:1106
>> Read of size 8 at addr ffff8881cad4d8b8 by task v4l_id/4526

>> CPU: 0 PID: 4526 Comm: v4l_id Not tainted 5.4.0-syzkaller #0
>> Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS
>> Google 01/01/2011
>> Call Trace:
>>    __dump_stack lib/dump_stack.c:77 [inline]
>>    dump_stack+0xef/0x16e lib/dump_stack.c:118
>>    print_address_description.constprop.0+0x36/0x50 mm/kasan/report.c:374
>>    __kasan_report.cold+0x1a/0x33 mm/kasan/report.c:506
>>    kasan_report+0xe/0x20 mm/kasan/common.c:638
>>    __mutex_lock_common kernel/locking/mutex.c:1043 [inline]
>>    __mutex_lock+0x124d/0x1360 kernel/locking/mutex.c:1106
>>    usbvision_v4l2_open+0x77/0x340
>> drivers/media/usb/usbvision/usbvision-video.c:314
>>    v4l2_open+0x20f/0x3d0 drivers/media/v4l2-core/v4l2-dev.c:423
>>    chrdev_open+0x219/0x5c0 fs/char_dev.c:414
>>    do_dentry_open+0x494/0x1120 fs/open.c:797
>>    do_last fs/namei.c:3412 [inline]
>>    path_openat+0x142b/0x4030 fs/namei.c:3529
>>    do_filp_open+0x1a1/0x280 fs/namei.c:3559
>>    do_sys_open+0x3c0/0x580 fs/open.c:1097
>>    do_syscall_64+0xb7/0x5b0 arch/x86/entry/common.c:294
>>    entry_SYSCALL_64_after_hwframe+0x49/0xbe

> This looks like a race in v4l2_open(): The function drops the
> videodev_lock mutex before calling the video driver's open routine, and
> the device can be unregistered during the short time between.

> This patch tries to make the race much more likely to happen, for
> testing and verification.

> Andrey, will syzbot run the same test with this patch, even though it
> says it doesn't have a reproducer?

> Alan Stern

> #syz test: https://github.com/google/kasan.git 1f22d15c

This crash does not have a reproducer. I cannot test it.


> Index: usb-devel/drivers/media/usb/usbvision/usbvision-video.c
> ===================================================================
> --- usb-devel.orig/drivers/media/usb/usbvision/usbvision-video.c
> +++ usb-devel/drivers/media/usb/usbvision/usbvision-video.c
> @@ -1585,6 +1585,7 @@ static void usbvision_disconnect(struct
>   		wake_up_interruptible(&usbvision->wait_frame);
>   		wake_up_interruptible(&usbvision->wait_stream);
>   	} else {
> +		msleep(100);
>   		usbvision_release(usbvision);
>   	}

> Index: usb-devel/drivers/media/v4l2-core/v4l2-dev.c
> ===================================================================
> --- usb-devel.orig/drivers/media/v4l2-core/v4l2-dev.c
> +++ usb-devel/drivers/media/v4l2-core/v4l2-dev.c
> @@ -419,9 +419,10 @@ static int v4l2_open(struct inode *inode
>   	video_get(vdev);
>   	mutex_unlock(&videodev_lock);
>   	if (vdev->fops->open) {
> -		if (video_is_registered(vdev))
> +		if (video_is_registered(vdev)) {
> +			msleep(200);
>   			ret = vdev->fops->open(filp);
> -		else
> +		} else
>   			ret = -ENODEV;
>   	}



^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: KASAN: use-after-free Read in usbvision_v4l2_open
  2019-12-10 19:47 ` Alan Stern
  2019-12-10 19:48   ` syzbot
  2019-12-10 19:48   ` Re: KASAN: use-after-free Read in usbvision_v4l2_open syzbot
@ 2019-12-10 20:06   ` Andrey Konovalov
  2019-12-10 20:13     ` Alan Stern
  2 siblings, 1 reply; 30+ messages in thread
From: Andrey Konovalov @ 2019-12-10 20:06 UTC (permalink / raw)
  To: Alan Stern
  Cc: syzbot, Hans Verkuil, Souptick Joarder, LKML, linux-media,
	USB list, Mauro Carvalho Chehab, Richard Fontana, syzkaller-bugs,
	Thomas Gleixner

On Tue, Dec 10, 2019 at 8:48 PM Alan Stern <stern@rowland.harvard.edu> wrote:
>
> On Mon, 9 Dec 2019, syzbot wrote:
>
> > Hello,
> >
> > syzbot found the following crash on:
> >
> > HEAD commit:    1f22d15c usb: gadget: add raw-gadget interface
> > git tree:       https://github.com/google/kasan.git usb-fuzzer
> > console output: https://syzkaller.appspot.com/x/log.txt?x=1296f42ae00000
> > kernel config:  https://syzkaller.appspot.com/x/.config?x=8ccee2968018adcb
> > dashboard link: https://syzkaller.appspot.com/bug?extid=c7b0ec009a216143df30
> > compiler:       gcc (GCC) 9.0.0 20181231 (experimental)
> >
> > Unfortunately, I don't have any reproducer for this crash yet.
> >
> > IMPORTANT: if you fix the bug, please add the following tag to the commit:
> > Reported-by: syzbot+c7b0ec009a216143df30@syzkaller.appspotmail.com
> >
> > ==================================================================
> > BUG: KASAN: use-after-free in __mutex_lock_common
> > kernel/locking/mutex.c:1043 [inline]
> > BUG: KASAN: use-after-free in __mutex_lock+0x124d/0x1360
> > kernel/locking/mutex.c:1106
> > Read of size 8 at addr ffff8881cad4d8b8 by task v4l_id/4526
> >
> > CPU: 0 PID: 4526 Comm: v4l_id Not tainted 5.4.0-syzkaller #0
> > Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS
> > Google 01/01/2011
> > Call Trace:
> >   __dump_stack lib/dump_stack.c:77 [inline]
> >   dump_stack+0xef/0x16e lib/dump_stack.c:118
> >   print_address_description.constprop.0+0x36/0x50 mm/kasan/report.c:374
> >   __kasan_report.cold+0x1a/0x33 mm/kasan/report.c:506
> >   kasan_report+0xe/0x20 mm/kasan/common.c:638
> >   __mutex_lock_common kernel/locking/mutex.c:1043 [inline]
> >   __mutex_lock+0x124d/0x1360 kernel/locking/mutex.c:1106
> >   usbvision_v4l2_open+0x77/0x340
> > drivers/media/usb/usbvision/usbvision-video.c:314
> >   v4l2_open+0x20f/0x3d0 drivers/media/v4l2-core/v4l2-dev.c:423
> >   chrdev_open+0x219/0x5c0 fs/char_dev.c:414
> >   do_dentry_open+0x494/0x1120 fs/open.c:797
> >   do_last fs/namei.c:3412 [inline]
> >   path_openat+0x142b/0x4030 fs/namei.c:3529
> >   do_filp_open+0x1a1/0x280 fs/namei.c:3559
> >   do_sys_open+0x3c0/0x580 fs/open.c:1097
> >   do_syscall_64+0xb7/0x5b0 arch/x86/entry/common.c:294
> >   entry_SYSCALL_64_after_hwframe+0x49/0xbe
>
> This looks like a race in v4l2_open(): The function drops the
> videodev_lock mutex before calling the video driver's open routine, and
> the device can be unregistered during the short time between.
>
> This patch tries to make the race much more likely to happen, for
> testing and verification.
>
> Andrey, will syzbot run the same test with this patch, even though it
> says it doesn't have a reproducer?

Hi Alan,

No, unfortunately there's nothing to run if there's no reproducer.
It's technically possible to run the same program log that triggered
the bug initially, but since the bug wasn't reproduced with this log
even without the patch, there isn't much sense in running it with the
patch applied.

Thanks!

>
> Alan Stern
>
> #syz test: https://github.com/google/kasan.git 1f22d15c
>
> Index: usb-devel/drivers/media/usb/usbvision/usbvision-video.c
> ===================================================================
> --- usb-devel.orig/drivers/media/usb/usbvision/usbvision-video.c
> +++ usb-devel/drivers/media/usb/usbvision/usbvision-video.c
> @@ -1585,6 +1585,7 @@ static void usbvision_disconnect(struct
>                 wake_up_interruptible(&usbvision->wait_frame);
>                 wake_up_interruptible(&usbvision->wait_stream);
>         } else {
> +               msleep(100);
>                 usbvision_release(usbvision);
>         }
>
> Index: usb-devel/drivers/media/v4l2-core/v4l2-dev.c
> ===================================================================
> --- usb-devel.orig/drivers/media/v4l2-core/v4l2-dev.c
> +++ usb-devel/drivers/media/v4l2-core/v4l2-dev.c
> @@ -419,9 +419,10 @@ static int v4l2_open(struct inode *inode
>         video_get(vdev);
>         mutex_unlock(&videodev_lock);
>         if (vdev->fops->open) {
> -               if (video_is_registered(vdev))
> +               if (video_is_registered(vdev)) {
> +                       msleep(200);
>                         ret = vdev->fops->open(filp);
> -               else
> +               } else
>                         ret = -ENODEV;
>         }
>
>

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: KASAN: use-after-free Read in usbvision_v4l2_open
  2019-12-10 20:06   ` Andrey Konovalov
@ 2019-12-10 20:13     ` Alan Stern
  2019-12-11 14:22       ` Andrey Konovalov
  0 siblings, 1 reply; 30+ messages in thread
From: Alan Stern @ 2019-12-10 20:13 UTC (permalink / raw)
  To: Andrey Konovalov
  Cc: syzbot, Hans Verkuil, Souptick Joarder, LKML, linux-media,
	USB list, Mauro Carvalho Chehab, Richard Fontana, syzkaller-bugs,
	Thomas Gleixner

On Tue, 10 Dec 2019, Andrey Konovalov wrote:

> On Tue, Dec 10, 2019 at 8:48 PM Alan Stern <stern@rowland.harvard.edu> wrote:

> > This looks like a race in v4l2_open(): The function drops the
> > videodev_lock mutex before calling the video driver's open routine, and
> > the device can be unregistered during the short time between.
> >
> > This patch tries to make the race much more likely to happen, for
> > testing and verification.
> >
> > Andrey, will syzbot run the same test with this patch, even though it
> > says it doesn't have a reproducer?
> 
> Hi Alan,
> 
> No, unfortunately there's nothing to run if there's no reproducer.
> It's technically possible to run the same program log that triggered
> the bug initially, but since the bug wasn't reproduced with this log
> even without the patch, there isn't much sense in running it with the
> patch applied.

Actually it does make sense.  That bug was caused by a race, and the 
patch tries to make the race much more likely to happen, so the same 
test should fail again.

But never mind; I'll try a different approach.  There's another syzbot
bug report, one with a reproducer, and with this patch in place it
should trigger the same race.  I'll try submitting it that way.

By the way, do you know why syzbot sent _two_ reply messages?  One with 
message ID <00000000000031a0af05995eca0b@google.com> and the other with 
message ID <000000000000441a4205995eca11@google.com>?  It seems like 
overkill.

Alan Stern




^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: Re: KASAN: use-after-free Read in usbvision_v4l2_open
  2019-12-10 19:48   ` syzbot
@ 2019-12-10 20:17     ` Alan Stern
  2019-12-11 14:23       ` Andrey Konovalov
  2019-12-12 16:52       ` general protection fault in usb_set_interface Alan Stern
  0 siblings, 2 replies; 30+ messages in thread
From: Alan Stern @ 2019-12-10 20:17 UTC (permalink / raw)
  To: syzbot
  Cc: andreyknvl, hverkuil, jrdr.linux, Kernel development list,
	linux-media, USB list, mchehab, rfontana, syzkaller-bugs, tglx

On Tue, 10 Dec 2019, syzbot wrote:

> > On Mon, 9 Dec 2019, syzbot wrote:
> 
> >> Hello,
> 
> >> syzbot found the following crash on:
> 
> >> HEAD commit:    1f22d15c usb: gadget: add raw-gadget interface
> >> git tree:       https://github.com/google/kasan.git usb-fuzzer
> >> console output: https://syzkaller.appspot.com/x/log.txt?x=1296f42ae00000
> >> kernel config:   
> >> https://syzkaller.appspot.com/x/.config?x=8ccee2968018adcb
> >> dashboard link:  
> >> https://syzkaller.appspot.com/bug?extid=c7b0ec009a216143df30
> >> compiler:       gcc (GCC) 9.0.0 20181231 (experimental)
> 
> >> Unfortunately, I don't have any reproducer for this crash yet.
> 
> >> IMPORTANT: if you fix the bug, please add the following tag to the  
> >> commit:
> >> Reported-by: syzbot+c7b0ec009a216143df30@syzkaller.appspotmail.com
> 
> >> ==================================================================
> >> BUG: KASAN: use-after-free in __mutex_lock_common
> >> kernel/locking/mutex.c:1043 [inline]
> >> BUG: KASAN: use-after-free in __mutex_lock+0x124d/0x1360
> >> kernel/locking/mutex.c:1106
> >> Read of size 8 at addr ffff8881cad4d8b8 by task v4l_id/4526
> 
> >> CPU: 0 PID: 4526 Comm: v4l_id Not tainted 5.4.0-syzkaller #0
> >> Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS
> >> Google 01/01/2011
> >> Call Trace:
> >>    __dump_stack lib/dump_stack.c:77 [inline]
> >>    dump_stack+0xef/0x16e lib/dump_stack.c:118
> >>    print_address_description.constprop.0+0x36/0x50 mm/kasan/report.c:374
> >>    __kasan_report.cold+0x1a/0x33 mm/kasan/report.c:506
> >>    kasan_report+0xe/0x20 mm/kasan/common.c:638
> >>    __mutex_lock_common kernel/locking/mutex.c:1043 [inline]
> >>    __mutex_lock+0x124d/0x1360 kernel/locking/mutex.c:1106
> >>    usbvision_v4l2_open+0x77/0x340
> >> drivers/media/usb/usbvision/usbvision-video.c:314
> >>    v4l2_open+0x20f/0x3d0 drivers/media/v4l2-core/v4l2-dev.c:423
> >>    chrdev_open+0x219/0x5c0 fs/char_dev.c:414
> >>    do_dentry_open+0x494/0x1120 fs/open.c:797
> >>    do_last fs/namei.c:3412 [inline]
> >>    path_openat+0x142b/0x4030 fs/namei.c:3529
> >>    do_filp_open+0x1a1/0x280 fs/namei.c:3559
> >>    do_sys_open+0x3c0/0x580 fs/open.c:1097
> >>    do_syscall_64+0xb7/0x5b0 arch/x86/entry/common.c:294
> >>    entry_SYSCALL_64_after_hwframe+0x49/0xbe
> 
> > This looks like a race in v4l2_open(): The function drops the
> > videodev_lock mutex before calling the video driver's open routine, and
> > the device can be unregistered during the short time between.
> 
> > This patch tries to make the race much more likely to happen, for
> > testing and verification.
> 
> > Andrey, will syzbot run the same test with this patch, even though it
> > says it doesn't have a reproducer?
> 
> > Alan Stern
> 
> > #syz test: https://github.com/google/kasan.git 1f22d15c
> 
> This crash does not have a reproducer. I cannot test it.

Let's try the same patch with a different bug report -- one that has a
reproducer.  I assume that syzbot gets the bug identity from the
email's From: line (which has been updated acoordingly) rather than the 
Subject: line.

#syz test: https://github.com/google/kasan.git 1f22d15c

Index: usb-devel/drivers/media/usb/usbvision/usbvision-video.c
===================================================================
--- usb-devel.orig/drivers/media/usb/usbvision/usbvision-video.c
+++ usb-devel/drivers/media/usb/usbvision/usbvision-video.c
@@ -1585,6 +1585,7 @@ static void usbvision_disconnect(struct
 		wake_up_interruptible(&usbvision->wait_frame);
 		wake_up_interruptible(&usbvision->wait_stream);
 	} else {
+		msleep(100);
 		usbvision_release(usbvision);
 	}
 
Index: usb-devel/drivers/media/v4l2-core/v4l2-dev.c
===================================================================
--- usb-devel.orig/drivers/media/v4l2-core/v4l2-dev.c
+++ usb-devel/drivers/media/v4l2-core/v4l2-dev.c
@@ -419,9 +419,10 @@ static int v4l2_open(struct inode *inode
 	video_get(vdev);
 	mutex_unlock(&videodev_lock);
 	if (vdev->fops->open) {
-		if (video_is_registered(vdev))
+		if (video_is_registered(vdev)) {
+			msleep(200);
 			ret = vdev->fops->open(filp);
-		else
+		} else
 			ret = -ENODEV;
 	}
 


^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: KASAN: use-after-free Read in usbvision_v4l2_open
  2019-12-10 20:13     ` Alan Stern
@ 2019-12-11 14:22       ` Andrey Konovalov
  2019-12-11 15:30         ` Dmitry Vyukov
  0 siblings, 1 reply; 30+ messages in thread
From: Andrey Konovalov @ 2019-12-11 14:22 UTC (permalink / raw)
  To: Alan Stern, Dmitry Vyukov
  Cc: syzbot, Hans Verkuil, Souptick Joarder, LKML, linux-media,
	USB list, Mauro Carvalho Chehab, Richard Fontana, syzkaller-bugs,
	Thomas Gleixner

On Tue, Dec 10, 2019 at 9:13 PM Alan Stern <stern@rowland.harvard.edu> wrote:
>
> On Tue, 10 Dec 2019, Andrey Konovalov wrote:
>
> > On Tue, Dec 10, 2019 at 8:48 PM Alan Stern <stern@rowland.harvard.edu> wrote:
>
> > > This looks like a race in v4l2_open(): The function drops the
> > > videodev_lock mutex before calling the video driver's open routine, and
> > > the device can be unregistered during the short time between.
> > >
> > > This patch tries to make the race much more likely to happen, for
> > > testing and verification.
> > >
> > > Andrey, will syzbot run the same test with this patch, even though it
> > > says it doesn't have a reproducer?
> >
> > Hi Alan,
> >
> > No, unfortunately there's nothing to run if there's no reproducer.
> > It's technically possible to run the same program log that triggered
> > the bug initially, but since the bug wasn't reproduced with this log
> > even without the patch, there isn't much sense in running it with the
> > patch applied.
>
> Actually it does make sense.  That bug was caused by a race, and the
> patch tries to make the race much more likely to happen, so the same
> test should fail again.
>
> But never mind; I'll try a different approach.  There's another syzbot
> bug report, one with a reproducer, and with this patch in place it
> should trigger the same race.  I'll try submitting it that way.
>
> By the way, do you know why syzbot sent _two_ reply messages?  One with
> message ID <00000000000031a0af05995eca0b@google.com> and the other with
> message ID <000000000000441a4205995eca11@google.com>?  It seems like
> overkill.

Hm, I'm not sure. Dmitry?

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: Re: KASAN: use-after-free Read in usbvision_v4l2_open
  2019-12-10 20:17     ` Alan Stern
@ 2019-12-11 14:23       ` Andrey Konovalov
  2019-12-11 15:14         ` Alan Stern
  2019-12-12 16:52       ` general protection fault in usb_set_interface Alan Stern
  1 sibling, 1 reply; 30+ messages in thread
From: Andrey Konovalov @ 2019-12-11 14:23 UTC (permalink / raw)
  To: Alan Stern
  Cc: syzbot, Hans Verkuil, Souptick Joarder, Kernel development list,
	linux-media, USB list, Mauro Carvalho Chehab, Richard Fontana,
	syzkaller-bugs, Thomas Gleixner

On Tue, Dec 10, 2019 at 9:17 PM Alan Stern <stern@rowland.harvard.edu> wrote:
>
> On Tue, 10 Dec 2019, syzbot wrote:
>
> > > On Mon, 9 Dec 2019, syzbot wrote:
> >
> > >> Hello,
> >
> > >> syzbot found the following crash on:
> >
> > >> HEAD commit:    1f22d15c usb: gadget: add raw-gadget interface
> > >> git tree:       https://github.com/google/kasan.git usb-fuzzer
> > >> console output: https://syzkaller.appspot.com/x/log.txt?x=1296f42ae00000
> > >> kernel config:
> > >> https://syzkaller.appspot.com/x/.config?x=8ccee2968018adcb
> > >> dashboard link:
> > >> https://syzkaller.appspot.com/bug?extid=c7b0ec009a216143df30
> > >> compiler:       gcc (GCC) 9.0.0 20181231 (experimental)
> >
> > >> Unfortunately, I don't have any reproducer for this crash yet.
> >
> > >> IMPORTANT: if you fix the bug, please add the following tag to the
> > >> commit:
> > >> Reported-by: syzbot+c7b0ec009a216143df30@syzkaller.appspotmail.com
> >
> > >> ==================================================================
> > >> BUG: KASAN: use-after-free in __mutex_lock_common
> > >> kernel/locking/mutex.c:1043 [inline]
> > >> BUG: KASAN: use-after-free in __mutex_lock+0x124d/0x1360
> > >> kernel/locking/mutex.c:1106
> > >> Read of size 8 at addr ffff8881cad4d8b8 by task v4l_id/4526
> >
> > >> CPU: 0 PID: 4526 Comm: v4l_id Not tainted 5.4.0-syzkaller #0
> > >> Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS
> > >> Google 01/01/2011
> > >> Call Trace:
> > >>    __dump_stack lib/dump_stack.c:77 [inline]
> > >>    dump_stack+0xef/0x16e lib/dump_stack.c:118
> > >>    print_address_description.constprop.0+0x36/0x50 mm/kasan/report.c:374
> > >>    __kasan_report.cold+0x1a/0x33 mm/kasan/report.c:506
> > >>    kasan_report+0xe/0x20 mm/kasan/common.c:638
> > >>    __mutex_lock_common kernel/locking/mutex.c:1043 [inline]
> > >>    __mutex_lock+0x124d/0x1360 kernel/locking/mutex.c:1106
> > >>    usbvision_v4l2_open+0x77/0x340
> > >> drivers/media/usb/usbvision/usbvision-video.c:314
> > >>    v4l2_open+0x20f/0x3d0 drivers/media/v4l2-core/v4l2-dev.c:423
> > >>    chrdev_open+0x219/0x5c0 fs/char_dev.c:414
> > >>    do_dentry_open+0x494/0x1120 fs/open.c:797
> > >>    do_last fs/namei.c:3412 [inline]
> > >>    path_openat+0x142b/0x4030 fs/namei.c:3529
> > >>    do_filp_open+0x1a1/0x280 fs/namei.c:3559
> > >>    do_sys_open+0x3c0/0x580 fs/open.c:1097
> > >>    do_syscall_64+0xb7/0x5b0 arch/x86/entry/common.c:294
> > >>    entry_SYSCALL_64_after_hwframe+0x49/0xbe
> >
> > > This looks like a race in v4l2_open(): The function drops the
> > > videodev_lock mutex before calling the video driver's open routine, and
> > > the device can be unregistered during the short time between.
> >
> > > This patch tries to make the race much more likely to happen, for
> > > testing and verification.
> >
> > > Andrey, will syzbot run the same test with this patch, even though it
> > > says it doesn't have a reproducer?
> >
> > > Alan Stern
> >
> > > #syz test: https://github.com/google/kasan.git 1f22d15c
> >
> > This crash does not have a reproducer. I cannot test it.
>
> Let's try the same patch with a different bug report -- one that has a
> reproducer.  I assume that syzbot gets the bug identity from the
> email's From: line (which has been updated acoordingly) rather than the
> Subject: line.

Did you get a response for this test? I see the test attempt on the
dashboard (the patch failed to build), but I didn't get an email with
the result.

>
> #syz test: https://github.com/google/kasan.git 1f22d15c
>
> Index: usb-devel/drivers/media/usb/usbvision/usbvision-video.c
> ===================================================================
> --- usb-devel.orig/drivers/media/usb/usbvision/usbvision-video.c
> +++ usb-devel/drivers/media/usb/usbvision/usbvision-video.c
> @@ -1585,6 +1585,7 @@ static void usbvision_disconnect(struct
>                 wake_up_interruptible(&usbvision->wait_frame);
>                 wake_up_interruptible(&usbvision->wait_stream);
>         } else {
> +               msleep(100);
>                 usbvision_release(usbvision);
>         }
>
> Index: usb-devel/drivers/media/v4l2-core/v4l2-dev.c
> ===================================================================
> --- usb-devel.orig/drivers/media/v4l2-core/v4l2-dev.c
> +++ usb-devel/drivers/media/v4l2-core/v4l2-dev.c
> @@ -419,9 +419,10 @@ static int v4l2_open(struct inode *inode
>         video_get(vdev);
>         mutex_unlock(&videodev_lock);
>         if (vdev->fops->open) {
> -               if (video_is_registered(vdev))
> +               if (video_is_registered(vdev)) {
> +                       msleep(200);
>                         ret = vdev->fops->open(filp);
> -               else
> +               } else
>                         ret = -ENODEV;
>         }
>
>

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: Re: KASAN: use-after-free Read in usbvision_v4l2_open
  2019-12-11 14:23       ` Andrey Konovalov
@ 2019-12-11 15:14         ` Alan Stern
  2019-12-11 15:35           ` Dmitry Vyukov
  0 siblings, 1 reply; 30+ messages in thread
From: Alan Stern @ 2019-12-11 15:14 UTC (permalink / raw)
  To: Andrey Konovalov
  Cc: syzbot, Hans Verkuil, Souptick Joarder, Kernel development list,
	linux-media, USB list, Mauro Carvalho Chehab, Richard Fontana,
	syzkaller-bugs, Thomas Gleixner

On Wed, 11 Dec 2019, Andrey Konovalov wrote:

> On Tue, Dec 10, 2019 at 9:17 PM Alan Stern <stern@rowland.harvard.edu> wrote:
> >
> > On Tue, 10 Dec 2019, syzbot wrote:
> >
> > > > On Mon, 9 Dec 2019, syzbot wrote:
> > >
> > > >> Hello,
> > >
> > > >> syzbot found the following crash on:
> > >
> > > >> HEAD commit:    1f22d15c usb: gadget: add raw-gadget interface
> > > >> git tree:       https://github.com/google/kasan.git usb-fuzzer
> > > >> console output: https://syzkaller.appspot.com/x/log.txt?x=1296f42ae00000
> > > >> kernel config:
> > > >> https://syzkaller.appspot.com/x/.config?x=8ccee2968018adcb
> > > >> dashboard link:
> > > >> https://syzkaller.appspot.com/bug?extid=c7b0ec009a216143df30
> > > >> compiler:       gcc (GCC) 9.0.0 20181231 (experimental)
> > >
> > > >> Unfortunately, I don't have any reproducer for this crash yet.
> > >
> > > >> IMPORTANT: if you fix the bug, please add the following tag to the
> > > >> commit:
> > > >> Reported-by: syzbot+c7b0ec009a216143df30@syzkaller.appspotmail.com

> > > This crash does not have a reproducer. I cannot test it.
> >
> > Let's try the same patch with a different bug report -- one that has a
> > reproducer.  I assume that syzbot gets the bug identity from the
> > email's From: line (which has been updated acoordingly) rather than the
> > Subject: line.
> 
> Did you get a response for this test? I see the test attempt on the
> dashboard (the patch failed to build), but I didn't get an email with
> the result.

No response so far.  On the other hand, syzbot has been a bit slow to 
respond to my tests recently (typical turnaround time is several 
hours).  I don't know what's going on.

Alan Stern


^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: KASAN: use-after-free Read in usbvision_v4l2_open
  2019-12-11 14:22       ` Andrey Konovalov
@ 2019-12-11 15:30         ` Dmitry Vyukov
  2019-12-11 16:22           ` Alan Stern
  0 siblings, 1 reply; 30+ messages in thread
From: Dmitry Vyukov @ 2019-12-11 15:30 UTC (permalink / raw)
  To: Andrey Konovalov
  Cc: Alan Stern, syzbot, Hans Verkuil, Souptick Joarder, LKML,
	linux-media, USB list, Mauro Carvalho Chehab, Richard Fontana,
	syzkaller-bugs, Thomas Gleixner

On Wed, Dec 11, 2019 at 3:23 PM Andrey Konovalov <andreyknvl@google.com> wrote:
>
> On Tue, Dec 10, 2019 at 9:13 PM Alan Stern <stern@rowland.harvard.edu> wrote:
> >
> > On Tue, 10 Dec 2019, Andrey Konovalov wrote:
> >
> > > On Tue, Dec 10, 2019 at 8:48 PM Alan Stern <stern@rowland.harvard.edu> wrote:
> >
> > > > This looks like a race in v4l2_open(): The function drops the
> > > > videodev_lock mutex before calling the video driver's open routine, and
> > > > the device can be unregistered during the short time between.
> > > >
> > > > This patch tries to make the race much more likely to happen, for
> > > > testing and verification.
> > > >
> > > > Andrey, will syzbot run the same test with this patch, even though it
> > > > says it doesn't have a reproducer?
> > >
> > > Hi Alan,
> > >
> > > No, unfortunately there's nothing to run if there's no reproducer.
> > > It's technically possible to run the same program log that triggered
> > > the bug initially, but since the bug wasn't reproduced with this log
> > > even without the patch, there isn't much sense in running it with the
> > > patch applied.
> >
> > Actually it does make sense.  That bug was caused by a race, and the
> > patch tries to make the race much more likely to happen, so the same
> > test should fail again.
> >
> > But never mind; I'll try a different approach.  There's another syzbot
> > bug report, one with a reproducer, and with this patch in place it
> > should trigger the same race.  I'll try submitting it that way.
> >
> > By the way, do you know why syzbot sent _two_ reply messages?  One with
> > message ID <00000000000031a0af05995eca0b@google.com> and the other with
> > message ID <000000000000441a4205995eca11@google.com>?  It seems like
> > overkill.
>
> Hm, I'm not sure. Dmitry?

I would assume it received 2 emails (second from syzkaller-bugs@
mailing list) and deduplication logic did not work somehow. So it
replied to both.

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: Re: KASAN: use-after-free Read in usbvision_v4l2_open
  2019-12-11 15:14         ` Alan Stern
@ 2019-12-11 15:35           ` Dmitry Vyukov
  0 siblings, 0 replies; 30+ messages in thread
From: Dmitry Vyukov @ 2019-12-11 15:35 UTC (permalink / raw)
  To: Alan Stern
  Cc: Andrey Konovalov, syzbot, Hans Verkuil, Souptick Joarder,
	Kernel development list, linux-media, USB list,
	Mauro Carvalho Chehab, Richard Fontana, syzkaller-bugs,
	Thomas Gleixner

On Wed, Dec 11, 2019 at 4:15 PM Alan Stern <stern@rowland.harvard.edu> wrote
>
> On Wed, 11 Dec 2019, Andrey Konovalov wrote:
>
> > On Tue, Dec 10, 2019 at 9:17 PM Alan Stern <stern@rowland.harvard.edu> wrote:
> > >
> > > On Tue, 10 Dec 2019, syzbot wrote:
> > >
> > > > > On Mon, 9 Dec 2019, syzbot wrote:
> > > >
> > > > >> Hello,
> > > >
> > > > >> syzbot found the following crash on:
> > > >
> > > > >> HEAD commit:    1f22d15c usb: gadget: add raw-gadget interface
> > > > >> git tree:       https://github.com/google/kasan.git usb-fuzzer
> > > > >> console output: https://syzkaller.appspot.com/x/log.txt?x=1296f42ae00000
> > > > >> kernel config:
> > > > >> https://syzkaller.appspot.com/x/.config?x=8ccee2968018adcb
> > > > >> dashboard link:
> > > > >> https://syzkaller.appspot.com/bug?extid=c7b0ec009a216143df30
> > > > >> compiler:       gcc (GCC) 9.0.0 20181231 (experimental)
> > > >
> > > > >> Unfortunately, I don't have any reproducer for this crash yet.
> > > >
> > > > >> IMPORTANT: if you fix the bug, please add the following tag to the
> > > > >> commit:
> > > > >> Reported-by: syzbot+c7b0ec009a216143df30@syzkaller.appspotmail.com
>
> > > > This crash does not have a reproducer. I cannot test it.
> > >
> > > Let's try the same patch with a different bug report -- one that has a
> > > reproducer.  I assume that syzbot gets the bug identity from the
> > > email's From: line (which has been updated acoordingly) rather than the
> > > Subject: line.
> >
> > Did you get a response for this test? I see the test attempt on the
> > dashboard (the patch failed to build), but I didn't get an email with
> > the result.
>
> No response so far.  On the other hand, syzbot has been a bit slow to
> respond to my tests recently (typical turnaround time is several
> hours).  I don't know what's going on.

The system is busy with bisections. Patch testing takes precedence
over bisection, but only after the current one finished. Bisections
can take a long time, up to days. The way it all works is a total hack
that one can put together in a few days.

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: KASAN: use-after-free Read in usbvision_v4l2_open
  2019-12-11 15:30         ` Dmitry Vyukov
@ 2019-12-11 16:22           ` Alan Stern
  2019-12-12 16:08             ` Andrey Konovalov
  0 siblings, 1 reply; 30+ messages in thread
From: Alan Stern @ 2019-12-11 16:22 UTC (permalink / raw)
  To: Dmitry Vyukov
  Cc: Andrey Konovalov, syzbot, Hans Verkuil, Souptick Joarder, LKML,
	linux-media, USB list, Mauro Carvalho Chehab, Richard Fontana,
	syzkaller-bugs, Thomas Gleixner

On Wed, 11 Dec 2019, Dmitry Vyukov wrote:

> > > By the way, do you know why syzbot sent _two_ reply messages?  One with
> > > message ID <00000000000031a0af05995eca0b@google.com> and the other with
> > > message ID <000000000000441a4205995eca11@google.com>?  It seems like
> > > overkill.
> >
> > Hm, I'm not sure. Dmitry?
> 
> I would assume it received 2 emails (second from syzkaller-bugs@
> mailing list) and deduplication logic did not work somehow. So it
> replied to both.

Does that mean when I send in a test request, it's better to omit 
syzkaller-bugs from the CC: list?

Also, whatever did happen to the most recent test request (the one sent 
to syzbot+7fa38a608b1075dfd634 even though it was meant to test the 
bug reported by syzbot+c7b0ec009a216143df30)?  Did it truly fail to 
build?  I can't find anything about it in the dashboard link for either 
bug report, and I haven't gotten a reply from syzbot.

Alan Stern


^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: KASAN: use-after-free Read in usbvision_v4l2_open
  2019-12-11 16:22           ` Alan Stern
@ 2019-12-12 16:08             ` Andrey Konovalov
  0 siblings, 0 replies; 30+ messages in thread
From: Andrey Konovalov @ 2019-12-12 16:08 UTC (permalink / raw)
  To: Alan Stern
  Cc: Dmitry Vyukov, syzbot, Hans Verkuil, Souptick Joarder, LKML,
	linux-media, USB list, Mauro Carvalho Chehab, Richard Fontana,
	syzkaller-bugs, Thomas Gleixner

On Wed, Dec 11, 2019 at 5:22 PM Alan Stern <stern@rowland.harvard.edu> wrote:
>
> On Wed, 11 Dec 2019, Dmitry Vyukov wrote:
>
> > > > By the way, do you know why syzbot sent _two_ reply messages?  One with
> > > > message ID <00000000000031a0af05995eca0b@google.com> and the other with
> > > > message ID <000000000000441a4205995eca11@google.com>?  It seems like
> > > > overkill.
> > >
> > > Hm, I'm not sure. Dmitry?
> >
> > I would assume it received 2 emails (second from syzkaller-bugs@
> > mailing list) and deduplication logic did not work somehow. So it
> > replied to both.
>
> Does that mean when I send in a test request, it's better to omit
> syzkaller-bugs from the CC: list?
>
> Also, whatever did happen to the most recent test request (the one sent
> to syzbot+7fa38a608b1075dfd634 even though it was meant to test the
> bug reported by syzbot+c7b0ec009a216143df30)?  Did it truly fail to
> build?  I can't find anything about it in the dashboard link for either
> bug report, and I haven't gotten a reply from syzbot.

Yes, the patch failed due to msleep() being undefined in that source
file. I'm not sure why syzbot didn't send a response. Could you try
resending the patch as the reply to that other syzbot report?

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: general protection fault in usb_set_interface
  2019-12-10 20:17     ` Alan Stern
  2019-12-11 14:23       ` Andrey Konovalov
@ 2019-12-12 16:52       ` Alan Stern
  1 sibling, 0 replies; 30+ messages in thread
From: Alan Stern @ 2019-12-12 16:52 UTC (permalink / raw)
  To: syzbot
  Cc: andreyknvl, hverkuil, jrdr.linux, Kernel development list,
	linux-media, USB list, mchehab, rfontana

[CC: list trimmed slightly -- including syzkaller-bugs]

On Thu, 12 Dec 2019, Andrey Konovalov wrote:

> Yes, the patch failed due to msleep() being undefined in that source
> file. I'm not sure why syzbot didn't send a response. Could you try 
> resending the patch as the reply to that other syzbot report?

This isn't literally a reply to the other syzbot report because I no 
longer have any copies of it in my mailbox.  But it uses the same To: 
and Subject: lines, so hopefully it will be okay.

This version of the patch adds #include <linux/delay.h>, so now
msleep() should be declared and there won't be any build errors.

If you want me to send the old version that fails to build, let me 
know.

Alan Stern

#syz test: https://github.com/google/kasan.git 1f22d15c

Index: usb-devel/drivers/media/usb/usbvision/usbvision-video.c
===================================================================
--- usb-devel.orig/drivers/media/usb/usbvision/usbvision-video.c
+++ usb-devel/drivers/media/usb/usbvision/usbvision-video.c
@@ -49,6 +49,7 @@
 #include <media/tuner.h>
 
 #include <linux/workqueue.h>
+#include <linux/delay.h>
 
 #include "usbvision.h"
 #include "usbvision-cards.h"
@@ -1585,6 +1586,7 @@ static void usbvision_disconnect(struct
 		wake_up_interruptible(&usbvision->wait_frame);
 		wake_up_interruptible(&usbvision->wait_stream);
 	} else {
+		msleep(100);
 		usbvision_release(usbvision);
 	}
 
Index: usb-devel/drivers/media/v4l2-core/v4l2-dev.c
===================================================================
--- usb-devel.orig/drivers/media/v4l2-core/v4l2-dev.c
+++ usb-devel/drivers/media/v4l2-core/v4l2-dev.c
@@ -24,6 +24,7 @@
 #include <linux/kmod.h>
 #include <linux/slab.h>
 #include <linux/uaccess.h>
+#include <linux/delay.h>
 
 #include <media/v4l2-common.h>
 #include <media/v4l2-device.h>
@@ -419,9 +420,10 @@ static int v4l2_open(struct inode *inode
 	video_get(vdev);
 	mutex_unlock(&videodev_lock);
 	if (vdev->fops->open) {
-		if (video_is_registered(vdev))
+		if (video_is_registered(vdev)) {
+			msleep(200);
 			ret = vdev->fops->open(filp);
-		else
+		} else
 			ret = -ENODEV;
 	}
 



^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: general protection fault in usb_set_interface
  2019-09-16 13:29 general protection fault in usb_set_interface syzbot
  2019-09-16 20:51 ` Alan Stern
@ 2019-12-13 12:15 ` Andrey Konovalov
  1 sibling, 0 replies; 30+ messages in thread
From: Andrey Konovalov @ 2019-12-13 12:15 UTC (permalink / raw)
  To: syzbot, Alan Stern
  Cc: Greg Kroah-Hartman, Kai Heng Feng, LKML, USB list, mans,
	Oliver Neukum, syzkaller-bugs

[-- Attachment #1: Type: text/plain, Size: 5135 bytes --]

On Mon, Sep 16, 2019 at 3:29 PM syzbot
<syzbot+7fa38a608b1075dfd634@syzkaller.appspotmail.com> wrote:
>
> Hello,
>
> syzbot found the following crash on:
>
> HEAD commit:    f0df5c1b usb-fuzzer: main usb gadget fuzzer driver
> git tree:       https://github.com/google/kasan.git usb-fuzzer
> console output: https://syzkaller.appspot.com/x/log.txt?x=158b66f1600000
> kernel config:  https://syzkaller.appspot.com/x/.config?x=5c6633fa4ed00be5
> dashboard link: https://syzkaller.appspot.com/bug?extid=7fa38a608b1075dfd634
> compiler:       gcc (GCC) 9.0.0 20181231 (experimental)
> syz repro:      https://syzkaller.appspot.com/x/repro.syz?x=14f57db9600000
> C reproducer:   https://syzkaller.appspot.com/x/repro.c?x=127b61a5600000
>
> IMPORTANT: if you fix the bug, please add the following tag to the commit:
> Reported-by: syzbot+7fa38a608b1075dfd634@syzkaller.appspotmail.com
>
> usb 3-1: usbvision_write_reg: failed: error -2
> usbvision_set_audio: can't write iopin register for audio switching
> kasan: CONFIG_KASAN_INLINE enabled
> kasan: GPF could be caused by NULL-ptr deref or user memory access
> general protection fault: 0000 [#1] SMP KASAN
> CPU: 1 PID: 1955 Comm: v4l_id Not tainted 5.3.0-rc7+ #0
> Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS
> Google 01/01/2011
> RIP: 0010:usb_set_interface+0x34/0xa50 drivers/usb/core/message.c:1362
> Code: fc 55 53 48 83 ec 40 89 54 24 18 89 74 24 10 e8 22 1c ef fd 49 8d 7c
> 24 48 48 b8 00 00 00 00 00 fc ff df 48 89 fa 48 c1 ea 03 <80> 3c 02 00 0f
> 85 fb 08 00 00 49 8b 44 24 48 49 8d 7c 24 18 48 89
> RSP: 0018:ffff8881cb19fd50 EFLAGS: 00010206
> RAX: dffffc0000000000 RBX: 0000000000000000 RCX: 0000000000000000
> RDX: 0000000000000009 RSI: ffffffff834ebe7e RDI: 0000000000000048
> RBP: ffff8881cb8e4200 R08: ffffffff88d21878 R09: ffffed103971cb43
> R10: ffff8881cb19fdc8 R11: ffff8881cb8e5a17 R12: 0000000000000000
> R13: ffff8881cb8e5a10 R14: ffff8881cb8e4cc8 R15: ffff8881cb8e5178
> FS:  00007f4f60b6d700(0000) GS:ffff8881db300000(0000) knlGS:0000000000000000
> CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
> CR2: 00007f4f6060c330 CR3: 00000001cc3a8000 CR4: 00000000001406e0
> DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
> DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
> Call Trace:
>   usbvision_radio_close+0x105/0x250
> drivers/media/usb/usbvision/usbvision-video.c:1114
>   v4l2_release+0x2e7/0x390 drivers/media/v4l2-core/v4l2-dev.c:455
>   __fput+0x2d7/0x840 fs/file_table.c:280
>   task_work_run+0x13f/0x1c0 kernel/task_work.c:113
>   tracehook_notify_resume include/linux/tracehook.h:188 [inline]
>   exit_to_usermode_loop+0x1d2/0x200 arch/x86/entry/common.c:163
>   prepare_exit_to_usermode arch/x86/entry/common.c:194 [inline]
>   syscall_return_slowpath arch/x86/entry/common.c:274 [inline]
>   do_syscall_64+0x45f/0x580 arch/x86/entry/common.c:299
>   entry_SYSCALL_64_after_hwframe+0x49/0xbe
> RIP: 0033:0x7f4f6069b2b0
> Code: 40 75 0b 31 c0 48 83 c4 08 e9 0c ff ff ff 48 8d 3d c5 32 08 00 e8 c0
> 07 02 00 83 3d 45 a3 2b 00 00 75 10 b8 03 00 00 00 0f 05 <48> 3d 01 f0 ff
> ff 73 31 c3 48 83 ec 08 e8 ce 8a 01 00 48 89 04 24
> RSP: 002b:00007ffde2d50ee8 EFLAGS: 00000246 ORIG_RAX: 0000000000000003
> RAX: 0000000000000000 RBX: 0000000000000003 RCX: 00007f4f6069b2b0
> RDX: 00007f4f60951df0 RSI: 0000000000000001 RDI: 0000000000000003
> RBP: 0000000000000000 R08: 00007f4f60951df0 R09: 000000000000000a
> R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000400884
> R13: 00007ffde2d51040 R14: 0000000000000000 R15: 0000000000000000
> Modules linked in:
> ---[ end trace 62bd2b7512ab49ee ]---
> RIP: 0010:usb_set_interface+0x34/0xa50 drivers/usb/core/message.c:1362
> Code: fc 55 53 48 83 ec 40 89 54 24 18 89 74 24 10 e8 22 1c ef fd 49 8d 7c
> 24 48 48 b8 00 00 00 00 00 fc ff df 48 89 fa 48 c1 ea 03 <80> 3c 02 00 0f
> 85 fb 08 00 00 49 8b 44 24 48 49 8d 7c 24 18 48 89
> RSP: 0018:ffff8881cb19fd50 EFLAGS: 00010206
> RAX: dffffc0000000000 RBX: 0000000000000000 RCX: 0000000000000000
> RDX: 0000000000000009 RSI: ffffffff834ebe7e RDI: 0000000000000048
> RBP: ffff8881cb8e4200 R08: ffffffff88d21878 R09: ffffed103971cb43
> R10: ffff8881cb19fdc8 R11: ffff8881cb8e5a17 R12: 0000000000000000
> R13: ffff8881cb8e5a10 R14: ffff8881cb8e4cc8 R15: ffff8881cb8e5178
> FS:  00007f4f60b6d700(0000) GS:ffff8881db300000(0000) knlGS:0000000000000000
> CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
> CR2: 00007f4f6060c330 CR3: 00000001cc3a8000 CR4: 00000000001406e0
> DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
> DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
>
>
> ---
> This bug is generated by a bot. It may contain errors.
> See https://goo.gl/tpsmEJ for more information about syzbot.
> syzbot engineers can be reached at syzkaller@googlegroups.com.
>
> syzbot will keep track of this bug report. See:
> https://goo.gl/tpsmEJ#status for how to communicate with syzbot.
> syzbot can test patches for this bug, for details see:
> https://goo.gl/tpsmEJ#testing-patches

Let's retry here:

#syz test: https://github.com/google/kasan.git f0df5c1b

[-- Attachment #2: usbvision.patch --]
[-- Type: text/x-patch, Size: 1357 bytes --]

Index: usb-devel/drivers/media/usb/usbvision/usbvision-video.c
===================================================================
--- usb-devel.orig/drivers/media/usb/usbvision/usbvision-video.c
+++ usb-devel/drivers/media/usb/usbvision/usbvision-video.c
@@ -49,6 +49,7 @@
 #include <media/tuner.h>
 
 #include <linux/workqueue.h>
+#include <linux/delay.h>
 
 #include "usbvision.h"
 #include "usbvision-cards.h"
@@ -1585,6 +1586,7 @@ static void usbvision_disconnect(struct
 		wake_up_interruptible(&usbvision->wait_frame);
 		wake_up_interruptible(&usbvision->wait_stream);
 	} else {
+		msleep(100);
 		usbvision_release(usbvision);
 	}
 
Index: usb-devel/drivers/media/v4l2-core/v4l2-dev.c
===================================================================
--- usb-devel.orig/drivers/media/v4l2-core/v4l2-dev.c
+++ usb-devel/drivers/media/v4l2-core/v4l2-dev.c
@@ -24,6 +24,7 @@
 #include <linux/kmod.h>
 #include <linux/slab.h>
 #include <linux/uaccess.h>
+#include <linux/delay.h>
 
 #include <media/v4l2-common.h>
 #include <media/v4l2-device.h>
@@ -419,9 +420,10 @@ static int v4l2_open(struct inode *inode
 	video_get(vdev);
 	mutex_unlock(&videodev_lock);
 	if (vdev->fops->open) {
-		if (video_is_registered(vdev))
+		if (video_is_registered(vdev)) {
+			msleep(200);
 			ret = vdev->fops->open(filp);
-		else
+		} else
 			ret = -ENODEV;
 	}
 

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: general protection fault in usb_set_interface
  2019-09-18 18:57                       ` Alan Stern
@ 2019-09-19 15:19                         ` Andrey Konovalov
  0 siblings, 0 replies; 30+ messages in thread
From: Andrey Konovalov @ 2019-09-19 15:19 UTC (permalink / raw)
  To: Alan Stern
  Cc: syzbot, Greg Kroah-Hartman, Kai Heng Feng, LKML, USB list, mans,
	Oliver Neukum, syzkaller-bugs

On Wed, Sep 18, 2019 at 8:57 PM Alan Stern <stern@rowland.harvard.edu> wrote:
>
> On Tue, 17 Sep 2019, syzbot wrote:
>
> > Hello,
> >
> > syzbot has tested the proposed patch but the reproducer still triggered
> > crash:
> > WARNING in sysfs_remove_group
> >
> > ------------[ cut here ]------------
> > sysfs group 'power' not found for kobject 'radio0'
>
> Andrey:
>
> Is there any way to tell syzbot to run the reproducer but with only one
> device instance (that is, only one dummy-hcd bus)?
>
> Or can you a new, modified reproducer that will do this?

AFAIU there two bugs here and you've fixed the first one, but the
second one gets triggered.

I think the second one got reported separately here:

https://syzkaller.appspot.com/bug?extid=5b9bba68c833c84a1135

That one has a reproducer with a single dummy-hcd, so you can try
running your debugging patch against that report.

I'll see if I can run it manually in the meantime.

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: general protection fault in usb_set_interface
  2019-09-17 18:43                     ` syzbot
@ 2019-09-18 18:57                       ` Alan Stern
  2019-09-19 15:19                         ` Andrey Konovalov
  0 siblings, 1 reply; 30+ messages in thread
From: Alan Stern @ 2019-09-18 18:57 UTC (permalink / raw)
  To: syzbot
  Cc: andreyknvl, gregkh, kai.heng.feng, linux-kernel, linux-usb, mans,
	oneukum, syzkaller-bugs

On Tue, 17 Sep 2019, syzbot wrote:

> Hello,
> 
> syzbot has tested the proposed patch but the reproducer still triggered  
> crash:
> WARNING in sysfs_remove_group
> 
> ------------[ cut here ]------------
> sysfs group 'power' not found for kobject 'radio0'

Andrey:

Is there any way to tell syzbot to run the reproducer but with only one 
device instance (that is, only one dummy-hcd bus)?

Or can you a new, modified reproducer that will do this?

Alan Stern


^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: general protection fault in usb_set_interface
  2019-09-17 18:31                   ` Alan Stern
@ 2019-09-17 18:43                     ` syzbot
  2019-09-18 18:57                       ` Alan Stern
  0 siblings, 1 reply; 30+ messages in thread
From: syzbot @ 2019-09-17 18:43 UTC (permalink / raw)
  To: andreyknvl, gregkh, kai.heng.feng, linux-kernel, linux-usb, mans,
	oneukum, stern, syzkaller-bugs

Hello,

syzbot has tested the proposed patch but the reproducer still triggered  
crash:
WARNING in sysfs_remove_group

------------[ cut here ]------------
sysfs group 'power' not found for kobject 'radio0'
WARNING: CPU: 0 PID: 2871 at fs/sysfs/group.c:278 sysfs_remove_group  
fs/sysfs/group.c:278 [inline]
WARNING: CPU: 0 PID: 2871 at fs/sysfs/group.c:278  
sysfs_remove_group+0x155/0x1b0 fs/sysfs/group.c:269
Kernel panic - not syncing: panic_on_warn set ...
CPU: 0 PID: 2871 Comm: v4l_id Not tainted 5.3.0-rc7+ #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS  
Google 01/01/2011
Call Trace:
  __dump_stack lib/dump_stack.c:77 [inline]
  dump_stack+0xca/0x13e lib/dump_stack.c:113
  panic+0x2a3/0x6da kernel/panic.c:219
  __warn.cold+0x20/0x4a kernel/panic.c:576
  report_bug+0x262/0x2a0 lib/bug.c:186
  fixup_bug arch/x86/kernel/traps.c:179 [inline]
  fixup_bug arch/x86/kernel/traps.c:174 [inline]
  do_error_trap+0x12b/0x1e0 arch/x86/kernel/traps.c:272
  do_invalid_op+0x32/0x40 arch/x86/kernel/traps.c:291
  invalid_op+0x23/0x30 arch/x86/entry/entry_64.S:1028
RIP: 0010:sysfs_remove_group fs/sysfs/group.c:278 [inline]
RIP: 0010:sysfs_remove_group+0x155/0x1b0 fs/sysfs/group.c:269
Code: 48 89 d9 49 8b 14 24 48 b8 00 00 00 00 00 fc ff df 48 c1 e9 03 80 3c  
01 00 75 41 48 8b 33 48 c7 c7 e0 c8 d0 85 e8 a0 0e 8b ff <0f> 0b eb 95 e8  
e2 d1 db ff e9 d2 fe ff ff 48 89 df e8 d5 d1 db ff
RSP: 0018:ffff8881c6c37c50 EFLAGS: 00010286
RAX: 0000000000000000 RBX: ffffffff85f2d700 RCX: 0000000000000000
RDX: 0000000000000000 RSI: ffffffff81288ddd RDI: ffffed1038d86f7c
RBP: 0000000000000000 R08: ffff8881d5dab000 R09: ffffed103b643ee7
R10: ffffed103b643ee6 R11: ffff8881db21f737 R12: ffff8881cf7e2bd8
R13: ffffffff85f2dca0 R14: 0000000000000000 R15: ffff8881cf7e3078
  dpm_sysfs_remove+0x97/0xb0 drivers/base/power/sysfs.c:735
  device_del+0x12a/0xb10 drivers/base/core.c:2316
  device_unregister+0x11/0x30 drivers/base/core.c:2371
  video_unregister_device+0xa2/0xc0 drivers/media/v4l2-core/v4l2-dev.c:1051
  usbvision_unregister_video+0x83/0x120  
drivers/media/usb/usbvision/usbvision-video.c:1256
  usbvision_release+0x10d/0x1c0  
drivers/media/usb/usbvision/usbvision-video.c:1369
  usbvision_radio_close.cold+0x2b/0x74  
drivers/media/usb/usbvision/usbvision-video.c:1142
  v4l2_release+0x2e7/0x390 drivers/media/v4l2-core/v4l2-dev.c:455
  __fput+0x2d7/0x840 fs/file_table.c:280
  task_work_run+0x13f/0x1c0 kernel/task_work.c:113
  tracehook_notify_resume include/linux/tracehook.h:188 [inline]
  exit_to_usermode_loop+0x1d2/0x200 arch/x86/entry/common.c:163
  prepare_exit_to_usermode arch/x86/entry/common.c:194 [inline]
  syscall_return_slowpath arch/x86/entry/common.c:274 [inline]
  do_syscall_64+0x45f/0x580 arch/x86/entry/common.c:299
  entry_SYSCALL_64_after_hwframe+0x49/0xbe
RIP: 0033:0x7fa3a6eac2b0
Code: 40 75 0b 31 c0 48 83 c4 08 e9 0c ff ff ff 48 8d 3d c5 32 08 00 e8 c0  
07 02 00 83 3d 45 a3 2b 00 00 75 10 b8 03 00 00 00 0f 05 <48> 3d 01 f0 ff  
ff 73 31 c3 48 83 ec 08 e8 ce 8a 01 00 48 89 04 24
RSP: 002b:00007ffe36ff6c28 EFLAGS: 00000246 ORIG_RAX: 0000000000000003
RAX: 0000000000000000 RBX: 0000000000000003 RCX: 00007fa3a6eac2b0
RDX: 0000000000000013 RSI: 0000000080685600 RDI: 0000000000000003
RBP: 0000000000000000 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000400884
R13: 00007ffe36ff6d80 R14: 0000000000000000 R15: 0000000000000000
Kernel Offset: disabled
Rebooting in 86400 seconds..


Tested on:

commit:         f0df5c1b usb-fuzzer: main usb gadget fuzzer driver
git tree:       https://github.com/google/kasan.git
console output: https://syzkaller.appspot.com/x/log.txt?x=10621965600000
kernel config:  https://syzkaller.appspot.com/x/.config?x=5c6633fa4ed00be5
dashboard link: https://syzkaller.appspot.com/bug?extid=7fa38a608b1075dfd634
compiler:       gcc (GCC) 9.0.0 20181231 (experimental)
patch:          https://syzkaller.appspot.com/x/patch.diff?x=15fea979600000


^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: general protection fault in usb_set_interface
  2019-09-17 18:15                 ` syzbot
@ 2019-09-17 18:31                   ` Alan Stern
  2019-09-17 18:43                     ` syzbot
  0 siblings, 1 reply; 30+ messages in thread
From: Alan Stern @ 2019-09-17 18:31 UTC (permalink / raw)
  To: syzbot
  Cc: andreyknvl, gregkh, kai.heng.feng, linux-kernel, linux-usb, mans,
	oneukum, syzkaller-bugs

On Tue, 17 Sep 2019, syzbot wrote:

> Hello,
> 
> syzbot tried to test the proposed patch but build/boot failed:

Oops.  Typo.

#syz test: https://github.com/google/kasan.git f0df5c1b

 drivers/media/usb/usbvision/usbvision-video.c |   27 ++++++++++++++++++++++----
 1 file changed, 23 insertions(+), 4 deletions(-)

Index: usb-devel/drivers/media/usb/usbvision/usbvision-video.c
===================================================================
--- usb-devel.orig/drivers/media/usb/usbvision/usbvision-video.c
+++ usb-devel/drivers/media/usb/usbvision/usbvision-video.c
@@ -314,6 +314,10 @@ static int usbvision_v4l2_open(struct fi
 	if (mutex_lock_interruptible(&usbvision->v4l2_lock))
 		return -ERESTARTSYS;
 
+	if (usbvision->remove_pending) {
+		err_code = -ENODEV;
+		goto unlock;
+	}
 	if (usbvision->user) {
 		err_code = -EBUSY;
 	} else {
@@ -377,6 +381,7 @@ unlock:
 static int usbvision_v4l2_close(struct file *file)
 {
 	struct usb_usbvision *usbvision = video_drvdata(file);
+	int r;
 
 	PDEBUG(DBG_IO, "close");
 
@@ -391,9 +396,10 @@ static int usbvision_v4l2_close(struct f
 	usbvision_scratch_free(usbvision);
 
 	usbvision->user--;
+	r = usbvision->remove_pending;
 	mutex_unlock(&usbvision->v4l2_lock);
 
-	if (usbvision->remove_pending) {
+	if (r) {
 		printk(KERN_INFO "%s: Final disconnect\n", __func__);
 		usbvision_release(usbvision);
 		return 0;
@@ -453,6 +459,9 @@ static int vidioc_querycap(struct file *
 {
 	struct usb_usbvision *usbvision = video_drvdata(file);
 
+	if (!usbvision->dev)
+		return -ENODEV;
+
 	strscpy(vc->driver, "USBVision", sizeof(vc->driver));
 	strscpy(vc->card,
 		usbvision_device_data[usbvision->dev_model].model_string,
@@ -1073,6 +1082,11 @@ static int usbvision_radio_open(struct f
 
 	if (mutex_lock_interruptible(&usbvision->v4l2_lock))
 		return -ERESTARTSYS;
+
+	if (usbvision->remove_pending) {
+		err_code = -ENODEV;
+		goto out;
+	}
 	err_code = v4l2_fh_open(file);
 	if (err_code)
 		goto out;
@@ -1105,21 +1119,24 @@ out:
 static int usbvision_radio_close(struct file *file)
 {
 	struct usb_usbvision *usbvision = video_drvdata(file);
+	int r;
 
 	PDEBUG(DBG_IO, "");
 
 	mutex_lock(&usbvision->v4l2_lock);
 	/* Set packet size to 0 */
 	usbvision->iface_alt = 0;
-	usb_set_interface(usbvision->dev, usbvision->iface,
+	if (usbvision->dev)
+		usb_set_interface(usbvision->dev, usbvision->iface,
 				    usbvision->iface_alt);
 
 	usbvision_audio_off(usbvision);
 	usbvision->radio = 0;
 	usbvision->user--;
+	r = usbvision->remove_pending;
 	mutex_unlock(&usbvision->v4l2_lock);
 
-	if (usbvision->remove_pending) {
+	if (r) {
 		printk(KERN_INFO "%s: Final disconnect\n", __func__);
 		v4l2_fh_release(file);
 		usbvision_release(usbvision);
@@ -1551,6 +1568,7 @@ err_usb:
 static void usbvision_disconnect(struct usb_interface *intf)
 {
 	struct usb_usbvision *usbvision = to_usbvision(usb_get_intfdata(intf));
+	int u;
 
 	PDEBUG(DBG_PROBE, "");
 
@@ -1567,13 +1585,14 @@ static void usbvision_disconnect(struct
 	v4l2_device_disconnect(&usbvision->v4l2_dev);
 	usbvision_i2c_unregister(usbvision);
 	usbvision->remove_pending = 1;	/* Now all ISO data will be ignored */
+	u = usbvision->user;
 
 	usb_put_dev(usbvision->dev);
 	usbvision->dev = NULL;	/* USB device is no more */
 
 	mutex_unlock(&usbvision->v4l2_lock);
 
-	if (usbvision->user) {
+	if (u) {
 		printk(KERN_INFO "%s: In use, disconnect pending\n",
 		       __func__);
 		wake_up_interruptible(&usbvision->wait_frame);



^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: general protection fault in usb_set_interface
  2019-09-17 18:08               ` Alan Stern
@ 2019-09-17 18:15                 ` syzbot
  2019-09-17 18:31                   ` Alan Stern
  0 siblings, 1 reply; 30+ messages in thread
From: syzbot @ 2019-09-17 18:15 UTC (permalink / raw)
  To: andreyknvl, gregkh, kai.heng.feng, linux-kernel, linux-usb, mans,
	oneukum, stern, syzkaller-bugs

Hello,

syzbot tried to test the proposed patch but build/boot failed:

  drivers/usb/typec/altmodes/built-in.a
   CC      drivers/usb/misc/legousbtower.o
   AR      drivers/usb/musb/built-in.a
   CC      drivers/usb/host/sl811-hcd.o
   CC      drivers/usb/usbip/vhci_sysfs.o
   AR      drivers/usb/typec/mux/built-in.a
   CC      drivers/usb/serial/generic.o
   CC      drivers/usb/serial/bus.o
   CC      drivers/usb/usbip/vhci_tx.o
   CC      drivers/usb/serial/aircable.o
   CC      drivers/usb/typec/tcpm/tcpm.o
   CC      drivers/staging/rtl8712/usb_halinit.o
   CC      drivers/net/wireless/realtek/rtlwifi/rtl8192ee/dm.o
   AR      drivers/media/usb/zr364xx/built-in.a
   CC      drivers/staging/uwb/driver.o
   CC      drivers/staging/rtl8712/usb_ops.o
   CC      drivers/staging/rtl8712/usb_ops_linux.o
   CC      drivers/staging/rtl8712/rtl871x_io.o
   CC      drivers/staging/rtl8712/rtl8712_io.o
   CC      drivers/media/usb/uvc/uvc_debugfs.o
   CC      drivers/net/wireless/realtek/rtlwifi/rtl8192ce/rf.o
   CC      drivers/net/wireless/realtek/rtlwifi/rtl8192ee/fw.o
   CC      drivers/net/wireless/realtek/rtlwifi/rtl8192ce/phy.o
   CC      drivers/media/usb/uvc/uvc_metadata.o
   CC      drivers/usb/serial/ark3116.o
   CC      drivers/net/wireless/realtek/rtlwifi/rtl8192ce/sw.o
   CC      drivers/usb/serial/belkin_sa.o
   CC      drivers/media/usb/uvc/uvc_entity.o
   CC      drivers/net/wireless/realtek/rtlwifi/rtl8192ee/hw.o
   CC      drivers/gpu/drm/i915/i915_oa_sklgt4.o
   CC      drivers/gpu/drm/i915/i915_oa_bxt.o
   CC      drivers/usb/misc/rio500.o
   CC      drivers/usb/misc/usbtest.o
   CC      drivers/staging/wlan-ng/prism2usb.o
   CC      drivers/usb/misc/ehset.o
   CC      drivers/usb/serial/ch341.o
   CC      drivers/usb/storage/protocol.o
   CC      drivers/usb/typec/ucsi/trace.o
   AR      drivers/net/wireless/realtek/rtlwifi/rtl8192cu/built-in.a
   CC      drivers/usb/usbip/vhci_rx.o
   CC      drivers/usb/usbip/vhci_hcd.o
   CC      drivers/usb/misc/trancevibrator.o
   CC      drivers/usb/typec/ucsi/ucsi.o
   CC      drivers/net/wireless/realtek/rtlwifi/rtl8192de/fw.o
   CC      drivers/staging/uwb/drp.o
   CC      drivers/usb/host/sl811_cs.o
   CC      drivers/staging/uwb/drp-avail.o
   CC      drivers/usb/host/u132-hcd.o
   CC      drivers/staging/rtl8712/rtl871x_ioctl_linux.o
   CC      drivers/net/wireless/realtek/rtlwifi/rtl8192ce/table.o
   AR      drivers/media/usb/uvc/built-in.a
scripts/Makefile.build:497: recipe for target 'drivers/media/usb' failed
make[2]: *** [drivers/media/usb] Error 2
scripts/Makefile.build:497: recipe for target 'drivers/media' failed
make[1]: *** [drivers/media] Error 2
make[1]: *** Waiting for unfinished jobs....
   CC      drivers/usb/misc/uss720.o
   CC      drivers/usb/storage/transport.o
   CC      drivers/usb/misc/usbsevseg.o
   CC      drivers/usb/usbip/stub_dev.o
   CC      drivers/usb/misc/usb251xb.o
   CC      drivers/staging/uwb/drp-ie.o
   CC      drivers/usb/serial/cp210x.o
   CC      drivers/usb/serial/cyberjack.o
   CC      drivers/usb/serial/cypress_m8.o
   CC      drivers/gpu/drm/i915/i915_oa_kblgt2.o
   CC      drivers/usb/host/bcma-hcd.o
   CC      drivers/usb/host/r8a66597-hcd.o
   CC      drivers/usb/misc/yurex.o
   CC      drivers/usb/misc/usb3503.o
   CC      drivers/net/wireless/realtek/rtlwifi/rtl8192ee/led.o
   CC      drivers/staging/wlan-ng/p80211conv.o
   CC      drivers/usb/host/ssb-hcd.o
   CC      drivers/net/wireless/realtek/rtlwifi/rtl8192ee/phy.o
   CC      drivers/net/wireless/realtek/rtlwifi/rtl8192ce/trx.o
   CC      drivers/staging/uwb/est.o
   CC      drivers/usb/misc/usb4604.o
   CC      drivers/usb/misc/chaoskey.o
   CC      drivers/net/wireless/realtek/rtlwifi/rtl8192se/dm.o
   CC      drivers/net/wireless/realtek/rtlwifi/rtl8192se/fw.o
   CC      drivers/staging/rtl8712/rtl871x_ioctl_rtl.o
   CC      drivers/usb/usbip/stub_main.o
   CC      drivers/usb/misc/lvstest.o
   CC      drivers/usb/storage/usb.o
   CC      drivers/usb/storage/initializers.o
   CC      drivers/usb/storage/sierra_ms.o
   CC      drivers/gpu/drm/drm_vblank.o
   CC      drivers/gpu/drm/drm_syncobj.o
   CC      drivers/usb/typec/ucsi/ucsi_acpi.o
   CC      drivers/net/wireless/realtek/rtlwifi/rtl8192de/hw.o
   CC      drivers/usb/host/fotg210-hcd.o
   CC      drivers/staging/uwb/ie.o
   CC      drivers/gpu/drm/i915/i915_oa_kblgt3.o
   CC      drivers/staging/wlan-ng/p80211req.o
   CC      drivers/net/wireless/realtek/rtlwifi/rtl8192ee/pwrseq.o
   CC      drivers/staging/wlan-ng/p80211wep.o
   CC      drivers/staging/wlan-ng/p80211netdev.o
   CC      drivers/usb/serial/usb_debug.o
   CC      drivers/staging/rtl8712/rtl871x_ioctl_set.o
   CC      drivers/net/wireless/realtek/rtlwifi/rtl8192de/led.o
   CC      drivers/net/wireless/realtek/rtlwifi/rtl8192se/hw.o
   CC      drivers/usb/usbip/stub_rx.o
   CC      drivers/net/wireless/realtek/rtlwifi/rtl8192se/led.o
   CC      drivers/usb/usbip/stub_tx.o
   CC      drivers/staging/uwb/ie-rcv.o
   CC      drivers/usb/typec/class.o
   CC      drivers/usb/serial/digi_acceleport.o
   AR      drivers/usb/typec/ucsi/built-in.a
   AR      drivers/usb/misc/built-in.a
   CC      drivers/gpu/drm/i915/i915_oa_glk.o
   CC      drivers/staging/uwb/lc-dev.o
   CC      drivers/net/wireless/realtek/rtlwifi/rtl8192se/phy.o
   CC      drivers/net/wireless/realtek/rtlwifi/rtl8192se/rf.o
   CC      drivers/usb/usbip/vudc_dev.o
   AR      drivers/net/wireless/realtek/rtlwifi/rtl8192ce/built-in.a
   CC      drivers/usb/typec/tcpm/fusb302.o
   CC      drivers/usb/storage/option_ms.o
   CC      drivers/usb/storage/usual-tables.o
   CC      drivers/net/wireless/realtek/rtlwifi/rtl8192de/phy.o
   CC      drivers/staging/rtl8712/rtl8712_led.o
   CC      drivers/usb/typec/mux.o
   CC      drivers/usb/typec/bus.o
   CC      drivers/usb/typec/tcpm/tcpci.o
   CC      drivers/gpu/drm/i915/i915_oa_cflgt2.o
   CC      drivers/gpu/drm/i915/i915_oa_cflgt3.o
   CC      drivers/net/wireless/realtek/rtlwifi/rtl8192ee/rf.o
   CC      drivers/staging/uwb/lc-rc.o
   CC      drivers/net/wireless/realtek/rtlwifi/rtl8192de/rf.o
   CC      drivers/usb/host/max3421-hcd.o
   CC      drivers/usb/usbip/vudc_sysfs.o
   CC      drivers/usb/serial/io_edgeport.o
   CC      drivers/usb/serial/io_ti.o
   CC      drivers/net/wireless/realtek/rtlwifi/rtl8192de/sw.o
   CC      drivers/usb/typec/tps6598x.o
   CC      drivers/usb/storage/alauda.o
   CC      drivers/usb/storage/cypress_atacb.o
   CC      drivers/usb/storage/datafab.o
   CC      drivers/gpu/drm/i915/i915_oa_cnl.o
   CC      drivers/usb/usbip/vudc_tx.o
   CC      drivers/net/wireless/realtek/rtlwifi/rtl8192ee/sw.o
   CC      drivers/staging/rtl8712/rtl871x_mlme.o
   CC      drivers/staging/rtl8712/ieee80211.o
   CC      drivers/staging/uwb/neh.o
   CC      drivers/usb/usbip/vudc_rx.o
   CC      drivers/net/wireless/realtek/rtlwifi/rtl8192ee/table.o
   CC      drivers/net/wireless/realtek/rtlwifi/rtl8192se/sw.o
   AR      drivers/usb/typec/tcpm/built-in.a
   CC      drivers/gpu/drm/drm_lease.o
   CC      drivers/net/wireless/realtek/rtlwifi/rtl8192de/table.o
   CC      drivers/net/wireless/realtek/rtlwifi/rtl8192ee/trx.o
   AR      drivers/usb/typec/built-in.a
   CC      drivers/staging/uwb/pal.o
   CC      drivers/staging/uwb/radio.o
   CC      drivers/net/wireless/realtek/rtlwifi/rtl8192de/trx.o
   CC      drivers/staging/uwb/reset.o
   CC      drivers/usb/usbip/vudc_transfer.o
   CC      drivers/gpu/drm/drm_writeback.o
   CC      drivers/usb/usbip/vudc_main.o
   AR      drivers/staging/wlan-ng/built-in.a
   CC      drivers/gpu/drm/drm_client.o
   CC      drivers/usb/storage/ene_ub6250.o
   CC      drivers/staging/uwb/rsv.o
   CC      drivers/usb/serial/empeg.o
   CC      drivers/net/wireless/realtek/rtlwifi/rtl8723ae/dm.o
   CC      drivers/net/wireless/realtek/rtlwifi/rtl8723ae/fw.o
   CC      drivers/net/wireless/realtek/rtlwifi/rtl8192se/table.o
   CC      drivers/usb/serial/f81232.o
   CC      drivers/net/wireless/realtek/rtlwifi/rtl8723be/dm.o
   CC      drivers/net/wireless/realtek/rtlwifi/rtl8723be/fw.o
   CC      drivers/staging/uwb/scan.o
   CC      drivers/net/wireless/realtek/rtlwifi/rtl8192se/trx.o
   CC      drivers/staging/rtl8712/rtl871x_mp_ioctl.o
   CC      drivers/staging/uwb/uwb-debug.o
   CC      drivers/usb/storage/freecom.o
   CC      drivers/gpu/drm/i915/i915_oa_icl.o
   CC      drivers/usb/serial/f81534.o
   CC      drivers/net/wireless/realtek/rtlwifi/rtl8723be/hw.o
   CC      drivers/net/wireless/realtek/rtlwifi/base.o
   CC      drivers/net/wireless/realtek/rtlwifi/cam.o
   CC      drivers/gpu/drm/drm_client_modeset.o
   CC      drivers/gpu/drm/drm_hdcp.o
   AR      drivers/net/wireless/realtek/rtlwifi/rtl8192ee/built-in.a
   CC      drivers/gpu/drm/drm_ioc32.o
   CC      drivers/net/wireless/realtek/rtlwifi/rtl8821ae/dm.o
   AR      drivers/usb/usbip/built-in.a
   CC      drivers/net/wireless/realtek/rtlwifi/rtl8821ae/fw.o
   CC      drivers/net/wireless/realtek/rtlwifi/rtl8821ae/hw.o
   CC      drivers/net/wireless/realtek/rtlwifi/rtl8723com/main.o
   CC      drivers/net/wireless/realtek/rtlwifi/rtl8821ae/led.o
   CC      drivers/gpu/drm/drm_atomic_uapi.o
   CC      drivers/usb/serial/ftdi_sio.o
   CC      drivers/staging/rtl8712/rtl871x_mp.o
   CC      drivers/staging/wusbcore/host/whci/asl.o
   CC      drivers/gpu/drm/drm_panel.o
   CC      drivers/gpu/drm/drm_of.o
   AR      drivers/usb/host/built-in.a
   CC      drivers/net/wireless/realtek/rtlwifi/rtl8723com/dm_common.o
   CC      drivers/usb/serial/garmin_gps.o
   CC      drivers/net/wireless/realtek/rtlwifi/rtl8723com/fw_common.o
   CC      drivers/staging/uwb/uwbd.o
   CC      drivers/net/wireless/realtek/rtlwifi/rtl8723com/phy_common.o
   CC      drivers/usb/storage/isd200.o
   CC      drivers/net/wireless/realtek/rtlwifi/core.o
   AR      drivers/gpu/drm/i915/built-in.a
   CC      drivers/usb/serial/ipaq.o
   CC      drivers/staging/rtl8712/mlme_linux.o
   CC      drivers/net/wireless/realtek/rtlwifi/debug.o
   CC      drivers/net/wireless/realtek/rtlwifi/efuse.o
   CC      drivers/staging/uwb/umc-bus.o
   CC      drivers/staging/uwb/umc-dev.o
   CC      drivers/staging/uwb/umc-drv.o
   CC      drivers/staging/wusbcore/host/whci/debug.o
   CC      drivers/staging/wusbcore/crypto.o
   CC      drivers/gpu/drm/drm_agpsupport.o
   AR      drivers/net/wireless/realtek/rtlwifi/rtl8192se/built-in.a
   CC      drivers/net/wireless/realtek/rtlwifi/rtl8723ae/hal_btc.o
   CC      drivers/net/wireless/realtek/rtlwifi/rtl8723ae/hal_bt_coexist.o
   CC      drivers/net/wireless/realtek/rtlwifi/rtl8723ae/hw.o
   CC      drivers/staging/rtl8712/recv_linux.o
   CC      drivers/staging/wusbcore/devconnect.o
   CC      drivers/staging/wusbcore/dev-sysfs.o
   CC      drivers/staging/uwb/whci.o
   CC      drivers/staging/wusbcore/mmc.o
   CC      drivers/staging/wusbcore/pal.o
   CC      drivers/staging/wusbcore/host/whci/hcd.o
   CC      drivers/net/wireless/realtek/rtlwifi/rtl8723be/led.o
   CC      drivers/net/wireless/realtek/rtlwifi/rtl8723be/phy.o
   CC      drivers/net/wireless/realtek/rtlwifi/rtl8723be/pwrseq.o
   CC      drivers/staging/rtl8712/xmit_linux.o
   CC      drivers/staging/rtl8712/usb_intf.o
   CC      drivers/gpu/drm/drm_debugfs.o
   CC      drivers/usb/storage/jumpshot.o
   CC      drivers/staging/uwb/whc-rc.o
   CC      drivers/gpu/drm/drm_debugfs_crc.o
   CC      drivers/usb/storage/karma.o
   CC      drivers/usb/serial/ipw.o
   CC      drivers/usb/storage/onetouch.o
   CC      drivers/usb/serial/ir-usb.o
   CC      drivers/gpu/drm/drm_mipi_dsi.o
   CC      drivers/net/wireless/realtek/rtlwifi/ps.o
   AR      drivers/net/wireless/realtek/rtlwifi/rtl8192de/built-in.a
   CC      drivers/staging/wusbcore/host/hwa-hc.o
   CC      drivers/staging/uwb/hwa-rc.o
   CC      drivers/staging/wusbcore/rh.o
   AR      drivers/net/wireless/realtek/rtlwifi/rtl8723com/built-in.a
   CC      drivers/staging/wusbcore/reservation.o
   CC      drivers/staging/rtl8712/os_intfs.o
   CC      drivers/net/wireless/realtek/rtlwifi/rtl8723ae/led.o
   CC      drivers/staging/wusbcore/host/whci/hw.o
   CC      drivers/usb/storage/realtek_cr.o
   CC      drivers/staging/wusbcore/host/whci/init.o
   CC      drivers/staging/wusbcore/host/whci/int.o
   CC      drivers/staging/rtl8712/rtl871x_pwrctrl.o
   CC      drivers/usb/storage/sddr09.o
   CC      drivers/usb/serial/iuu_phoenix.o
   CC      drivers/net/wireless/realtek/rtlwifi/rtl8723be/sw.o
   CC      drivers/staging/rtl8712/rtl8712_recv.o
   CC      drivers/usb/storage/sddr55.o
   CC      drivers/net/wireless/realtek/rtlwifi/rtl8723be/rf.o
   CC      drivers/gpu/drm/drm_panel_orientation_quirks.o
   CC      drivers/usb/storage/shuttle_usbat.o
   CC      drivers/staging/wusbcore/security.o
   CC      drivers/net/wireless/realtek/rtlwifi/rtl8723ae/phy.o
   CC      drivers/net/wireless/realtek/rtlwifi/rtl8723ae/pwrseq.o
   CC      drivers/net/wireless/realtek/rtlwifi/rtl8723ae/rf.o
   CC      drivers/net/wireless/realtek/rtlwifi/rtl8723ae/sw.o
   CC      drivers/staging/wusbcore/wusbhc.o
   CC      drivers/staging/rtl8712/rtl871x_recv.o
   CC      drivers/staging/rtl8712/rtl871x_sta_mgt.o
   CC      drivers/staging/rtl8712/rtl871x_xmit.o
   CC      drivers/staging/rtl8712/rtl8712_xmit.o
   CC      drivers/net/wireless/realtek/rtlwifi/rtl8723be/table.o
   CC      drivers/net/wireless/realtek/rtlwifi/rtl8723be/trx.o
   CC      drivers/usb/serial/keyspan.o
   CC      drivers/usb/serial/keyspan_pda.o
   AR      drivers/staging/uwb/built-in.a
   AR      drivers/gpu/drm/built-in.a
   CC      drivers/staging/wusbcore/wa-hc.o
   CC      drivers/net/wireless/realtek/rtlwifi/rtl8821ae/phy.o
   CC      drivers/net/wireless/realtek/rtlwifi/rtl8821ae/pwrseq.o
   CC      drivers/net/wireless/realtek/rtlwifi/rtl8821ae/rf.o
   CC      drivers/staging/wusbcore/host/whci/qset.o
   CC      drivers/staging/wusbcore/host/whci/pzl.o
   AR      drivers/gpu/built-in.a
   CC      drivers/staging/wusbcore/host/whci/wusb.o
   CC      drivers/net/wireless/realtek/rtlwifi/rtl8723ae/trx.o
   CC      drivers/net/wireless/realtek/rtlwifi/rc.o
   CC      drivers/net/wireless/realtek/rtlwifi/regd.o
   CC      drivers/net/wireless/realtek/rtlwifi/rtl8821ae/sw.o
   CC      drivers/net/wireless/realtek/rtlwifi/rtl8723ae/table.o
   CC      drivers/net/wireless/realtek/rtlwifi/stats.o
   CC      drivers/net/wireless/realtek/rtlwifi/pci.o
   CC      drivers/staging/wusbcore/wa-rpipe.o
   CC      drivers/staging/wusbcore/wa-nep.o
   AR      drivers/usb/storage/built-in.a
   CC      drivers/net/wireless/realtek/rtlwifi/usb.o
   CC      drivers/net/wireless/realtek/rtlwifi/rtl8821ae/table.o
   CC      drivers/net/wireless/realtek/rtlwifi/rtl8821ae/trx.o
   CC      drivers/staging/wusbcore/wa-xfer.o
   CC      drivers/staging/wusbcore/cbaf.o
   CC      drivers/usb/serial/kobil_sct.o
   CC      drivers/usb/serial/kl5kusb105.o
   CC      drivers/usb/serial/metro-usb.o
   CC      drivers/usb/serial/mct_u232.o
   CC      drivers/usb/serial/mos7720.o
   CC      drivers/usb/serial/mos7840.o
   CC      drivers/usb/serial/mxuport.o
   CC      drivers/usb/serial/navman.o
   CC      drivers/usb/serial/omninet.o
   CC      drivers/usb/serial/opticon.o
   CC      drivers/usb/serial/option.o
   CC      drivers/usb/serial/oti6858.o
   CC      drivers/usb/serial/pl2303.o
   CC      drivers/usb/serial/qcaux.o
   CC      drivers/usb/serial/qcserial.o
   CC      drivers/usb/serial/quatech2.o
   CC      drivers/usb/serial/safe_serial.o
   AR      drivers/staging/rtl8712/built-in.a
   CC      drivers/usb/serial/sierra.o
   AR      drivers/net/wireless/realtek/rtlwifi/rtl8723be/built-in.a
   CC      drivers/usb/serial/usb-serial-simple.o
   CC      drivers/usb/serial/spcp8x5.o
   AR      drivers/staging/wusbcore/host/whci/built-in.a
   AR      drivers/staging/wusbcore/host/built-in.a
   CC      drivers/usb/serial/ssu100.o
   CC      drivers/usb/serial/symbolserial.o
   CC      drivers/usb/serial/usb_wwan.o
   CC      drivers/usb/serial/ti_usb_3410_5052.o
   CC      drivers/usb/serial/upd78f0730.o
   CC      drivers/usb/serial/visor.o
   AR      drivers/net/wireless/realtek/rtlwifi/rtl8723ae/built-in.a
   CC      drivers/usb/serial/wishbone-serial.o
   CC      drivers/usb/serial/xsens_mt.o
   CC      drivers/usb/serial/whiteheat.o
   AR      drivers/staging/wusbcore/built-in.a
   AR      drivers/staging/built-in.a
   AR      drivers/usb/serial/built-in.a
   AR      drivers/usb/built-in.a
   AR      drivers/net/wireless/realtek/rtlwifi/rtl8821ae/built-in.a
   AR      drivers/net/wireless/realtek/rtlwifi/built-in.a
   AR      drivers/net/wireless/realtek/built-in.a
   AR      drivers/net/wireless/built-in.a
   AR      drivers/net/built-in.a
Makefile:1083: recipe for target 'drivers' failed
make: *** [drivers] Error 2


Error text is too large and was truncated, full error text is at:
https://syzkaller.appspot.com/x/error.txt?x=176045b5600000


Tested on:

commit:         f0df5c1b usb-fuzzer: main usb gadget fuzzer driver
git tree:       https://github.com/google/kasan.git
dashboard link: https://syzkaller.appspot.com/bug?extid=7fa38a608b1075dfd634
compiler:       gcc (GCC) 9.0.0 20181231 (experimental)
patch:          https://syzkaller.appspot.com/x/patch.diff?x=12f8611d600000


^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: general protection fault in usb_set_interface
  2019-09-17 17:36             ` Alan Stern
@ 2019-09-17 18:08               ` Alan Stern
  2019-09-17 18:15                 ` syzbot
  0 siblings, 1 reply; 30+ messages in thread
From: Alan Stern @ 2019-09-17 18:08 UTC (permalink / raw)
  To: syzbot
  Cc: andreyknvl, gregkh, kai.heng.feng, linux-kernel, linux-usb, mans,
	oneukum, syzkaller-bugs

On Tue, 17 Sep 2019, Alan Stern wrote:

> On Tue, 17 Sep 2019, syzbot wrote:
> 
> > Hello,
> > 
> > syzbot has tested the proposed patch but the reproducer still triggered  
> > crash:
> > WARNING in sysfs_remove_group
> > 
> > ------------[ cut here ]------------
> > sysfs group 'power' not found for kobject 'radio3'
> > WARNING: CPU: 1 PID: 2883 at fs/sysfs/group.c:278 sysfs_remove_group  
> > fs/sysfs/group.c:278 [inline]
> > WARNING: CPU: 1 PID: 2883 at fs/sysfs/group.c:278  
> > sysfs_remove_group+0x155/0x1b0 fs/sysfs/group.c:269
> > Kernel panic - not syncing: panic_on_warn set ...
> > CPU: 1 PID: 2883 Comm: v4l_id Not tainted 5.3.0-rc7+ #0
> > Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS  
> > Google 01/01/2011
> > Call Trace:
> >   __dump_stack lib/dump_stack.c:77 [inline]
> >   dump_stack+0xca/0x13e lib/dump_stack.c:113
> >   panic+0x2a3/0x6da kernel/panic.c:219
> >   __warn.cold+0x20/0x4a kernel/panic.c:576
> >   report_bug+0x262/0x2a0 lib/bug.c:186
> >   fixup_bug arch/x86/kernel/traps.c:179 [inline]
> >   fixup_bug arch/x86/kernel/traps.c:174 [inline]
> >   do_error_trap+0x12b/0x1e0 arch/x86/kernel/traps.c:272
> >   do_invalid_op+0x32/0x40 arch/x86/kernel/traps.c:291
> >   invalid_op+0x23/0x30 arch/x86/entry/entry_64.S:1028
> > RIP: 0010:sysfs_remove_group fs/sysfs/group.c:278 [inline]
> > RIP: 0010:sysfs_remove_group+0x155/0x1b0 fs/sysfs/group.c:269
> > Code: 48 89 d9 49 8b 14 24 48 b8 00 00 00 00 00 fc ff df 48 c1 e9 03 80 3c  
> > 01 00 75 41 48 8b 33 48 c7 c7 e0 c8 d0 85 e8 a0 0e 8b ff <0f> 0b eb 95 e8  
> > e2 d1 db ff e9 d2 fe ff ff 48 89 df e8 d5 d1 db ff
> > RSP: 0018:ffff8881c6d17c50 EFLAGS: 00010286
> > RAX: 0000000000000000 RBX: ffffffff85f2d700 RCX: 0000000000000000
> > RDX: 0000000000000000 RSI: ffffffff81288ddd RDI: ffffed1038da2f7c
> > RBP: 0000000000000000 R08: ffff8881d6243000 R09: 0000000000000000
> > R10: 0000000000000000 R11: 0000000000000000 R12: ffff8881cf014cd8
> > R13: ffffffff85f2dca0 R14: 0000000000000000 R15: ffff8881cf015178
> >   dpm_sysfs_remove+0x97/0xb0 drivers/base/power/sysfs.c:735
> >   device_del+0x12a/0xb10 drivers/base/core.c:2316
> >   device_unregister+0x11/0x30 drivers/base/core.c:2371
> >   video_unregister_device+0xa2/0xc0 drivers/media/v4l2-core/v4l2-dev.c:1051
> >   usbvision_unregister_video+0x83/0x120  
> > drivers/media/usb/usbvision/usbvision-video.c:1243
> >   usbvision_release+0x10d/0x1c0  
> > drivers/media/usb/usbvision/usbvision-video.c:1356
> >   usbvision_radio_close.cold+0x2b/0x74  
> > drivers/media/usb/usbvision/usbvision-video.c:1129
> >   v4l2_release+0x2e7/0x390 drivers/media/v4l2-core/v4l2-dev.c:455
> >   __fput+0x2d7/0x840 fs/file_table.c:280
> >   task_work_run+0x13f/0x1c0 kernel/task_work.c:113
> >   tracehook_notify_resume include/linux/tracehook.h:188 [inline]
> >   exit_to_usermode_loop+0x1d2/0x200 arch/x86/entry/common.c:163
> >   prepare_exit_to_usermode arch/x86/entry/common.c:194 [inline]
> >   syscall_return_slowpath arch/x86/entry/common.c:274 [inline]
> >   do_syscall_64+0x45f/0x580 arch/x86/entry/common.c:299
> >   entry_SYSCALL_64_after_hwframe+0x49/0xbe
> > RIP: 0033:0x7f4fde8992b0
> > Code: 40 75 0b 31 c0 48 83 c4 08 e9 0c ff ff ff 48 8d 3d c5 32 08 00 e8 c0  
> > 07 02 00 83 3d 45 a3 2b 00 00 75 10 b8 03 00 00 00 0f 05 <48> 3d 01 f0 ff  
> > ff 73 31 c3 48 83 ec 08 e8 ce 8a 01 00 48 89 04 24
> > RSP: 002b:00007ffcce3d65f8 EFLAGS: 00000246 ORIG_RAX: 0000000000000003
> > RAX: 0000000000000000 RBX: 0000000000000003 RCX: 00007f4fde8992b0
> > RDX: 0000000000000013 RSI: 0000000080685600 RDI: 0000000000000003
> > RBP: 0000000000000000 R08: 0000000000000000 R09: 0000000000000000
> > R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000400884
> > R13: 00007ffcce3d6750 R14: 0000000000000000 R15: 0000000000000000
> > Kernel Offset: disabled
> > Rebooting in 86400 seconds..
> > 
> > 
> > Tested on:
> > 
> > commit:         f0df5c1b usb-fuzzer: main usb gadget fuzzer driver
> > git tree:       https://github.com/google/kasan.git
> > console output: https://syzkaller.appspot.com/x/log.txt?x=178ba88d600000
> > kernel config:  https://syzkaller.appspot.com/x/.config?x=5c6633fa4ed00be5
> > dashboard link: https://syzkaller.appspot.com/bug?extid=7fa38a608b1075dfd634
> > compiler:       gcc (GCC) 9.0.0 20181231 (experimental)
> > patch:          https://syzkaller.appspot.com/x/patch.diff?x=14ce1b59600000
> 
> This is more than I can fix.  The whole way the v4l2 layer handles
> reference counting seems suspicious and I don't understand it.  (Does
> the code assume that the only reference holders are initial
> registration and open files?)
> 
> In this case it looks like the device may be unregistered twice.  It's
> hard to tell exactly what's going wrong without knowing more about how
> this is supposed to work.  It wouldn't hurt, for example, to use 
> dev_info() instead of printk(KERN_INFO) in places like 
> usbvision_disconnect().
> 
> I'm going to step back and let the maintainers deal with the rest of
> this.

Changed my mind.  There are some obvious races between the open, close, 
and disconnect routines.  Maybe fixing them will help.

Alan Stern

#syz test: https://github.com/google/kasan.git f0df5c1b

 drivers/media/usb/usbvision/usbvision-video.c |   27 ++++++++++++++++++++++----
 1 file changed, 23 insertions(+), 4 deletions(-)

Index: usb-devel/drivers/media/usb/usbvision/usbvision-video.c
===================================================================
--- usb-devel.orig/drivers/media/usb/usbvision/usbvision-video.c
+++ usb-devel/drivers/media/usb/usbvision/usbvision-video.c
@@ -314,6 +314,10 @@ static int usbvision_v4l2_open(struct fi
 	if (mutex_lock_interruptible(&usbvision->v4l2_lock))
 		return -ERESTARTSYS;
 
+	if (usbvision->remove_pending) {
+		err_code = -ENODEV;
+		goto unlock;
+	}
 	if (usbvision->user) {
 		err_code = -EBUSY;
 	} else {
@@ -377,6 +381,7 @@ unlock:
 static int usbvision_v4l2_close(struct file *file)
 {
 	struct usb_usbvision *usbvision = video_drvdata(file);
+	int r;
 
 	PDEBUG(DBG_IO, "close");
 
@@ -391,9 +396,10 @@ static int usbvision_v4l2_close(struct f
 	usbvision_scratch_free(usbvision);
 
 	usbvision->user--;
+	r = usbvision->remove_pending;
 	mutex_unlock(&usbvision->v4l2_lock);
 
-	if (usbvision->remove_pending) {
+	if (r) {
 		printk(KERN_INFO "%s: Final disconnect\n", __func__);
 		usbvision_release(usbvision);
 		return 0;
@@ -453,6 +459,9 @@ static int vidioc_querycap(struct file *
 {
 	struct usb_usbvision *usbvision = video_drvdata(file);
 
+	if (!usbvision->dev)
+		return -ENODEV;
+
 	strscpy(vc->driver, "USBVision", sizeof(vc->driver));
 	strscpy(vc->card,
 		usbvision_device_data[usbvision->dev_model].model_string,
@@ -1073,6 +1082,11 @@ static int usbvision_radio_open(struct f
 
 	if (mutex_lock_interruptible(&usbvision->v4l2_lock))
 		return -ERESTARTSYS;
+
+	if (usbvision->remove_pending) {
+		err_code = -ENODEV;
+		goto out;
+	}
 	err_code = v4l2_fh_open(file);
 	if (err_code)
 		goto out;
@@ -1105,21 +1119,24 @@ out:
 static int usbvision_radio_close(struct file *file)
 {
 	struct usb_usbvision *usbvision = video_drvdata(file);
+	int r;
 
 	PDEBUG(DBG_IO, "");
 
 	mutex_lock(&usbvision->v4l2_lock);
 	/* Set packet size to 0 */
 	usbvision->iface_alt = 0;
-	usb_set_interface(usbvision->dev, usbvision->iface,
+	if (usbvision->dev)
+		usb_set_interface(usbvision->dev, usbvision->iface,
 				    usbvision->iface_alt);
 
 	usbvision_audio_off(usbvision);
 	usbvision->radio = 0;
 	usbvision->user--;
+	r = usbvision->remove_pending;
 	mutex_unlock(&usbvision->v4l2_lock);
 
-	if (usbvision->remove_pending) {
+	if (r) {
 		printk(KERN_INFO "%s: Final disconnect\n", __func__);
 		v4l2_fh_release(file);
 		usbvision_release(usbvision);
@@ -1551,6 +1568,7 @@ err_usb:
 static void usbvision_disconnect(struct usb_interface *intf)
 {
 	struct usb_usbvision *usbvision = to_usbvision(usb_get_intfdata(intf));
+	int u;
 
 	PDEBUG(DBG_PROBE, "");
 
@@ -1567,13 +1585,14 @@ static void usbvision_disconnect(struct
 	v4l2_device_disconnect(&usbvision->v4l2_dev);
 	usbvision_i2c_unregister(usbvision);
 	usbvision->remove_pending = 1;	/* Now all ISO data will be ignored */
+	u = usbvision_user;
 
 	usb_put_dev(usbvision->dev);
 	usbvision->dev = NULL;	/* USB device is no more */
 
 	mutex_unlock(&usbvision->v4l2_lock);
 
-	if (usbvision->user) {
+	if (u) {
 		printk(KERN_INFO "%s: In use, disconnect pending\n",
 		       __func__);
 		wake_up_interruptible(&usbvision->wait_frame);


^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: general protection fault in usb_set_interface
  2019-09-17 16:06           ` syzbot
@ 2019-09-17 17:36             ` Alan Stern
  2019-09-17 18:08               ` Alan Stern
  0 siblings, 1 reply; 30+ messages in thread
From: Alan Stern @ 2019-09-17 17:36 UTC (permalink / raw)
  To: syzbot
  Cc: andreyknvl, gregkh, kai.heng.feng, linux-kernel, linux-usb, mans,
	oneukum, syzkaller-bugs

On Tue, 17 Sep 2019, syzbot wrote:

> Hello,
> 
> syzbot has tested the proposed patch but the reproducer still triggered  
> crash:
> WARNING in sysfs_remove_group
> 
> ------------[ cut here ]------------
> sysfs group 'power' not found for kobject 'radio3'
> WARNING: CPU: 1 PID: 2883 at fs/sysfs/group.c:278 sysfs_remove_group  
> fs/sysfs/group.c:278 [inline]
> WARNING: CPU: 1 PID: 2883 at fs/sysfs/group.c:278  
> sysfs_remove_group+0x155/0x1b0 fs/sysfs/group.c:269
> Kernel panic - not syncing: panic_on_warn set ...
> CPU: 1 PID: 2883 Comm: v4l_id Not tainted 5.3.0-rc7+ #0
> Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS  
> Google 01/01/2011
> Call Trace:
>   __dump_stack lib/dump_stack.c:77 [inline]
>   dump_stack+0xca/0x13e lib/dump_stack.c:113
>   panic+0x2a3/0x6da kernel/panic.c:219
>   __warn.cold+0x20/0x4a kernel/panic.c:576
>   report_bug+0x262/0x2a0 lib/bug.c:186
>   fixup_bug arch/x86/kernel/traps.c:179 [inline]
>   fixup_bug arch/x86/kernel/traps.c:174 [inline]
>   do_error_trap+0x12b/0x1e0 arch/x86/kernel/traps.c:272
>   do_invalid_op+0x32/0x40 arch/x86/kernel/traps.c:291
>   invalid_op+0x23/0x30 arch/x86/entry/entry_64.S:1028
> RIP: 0010:sysfs_remove_group fs/sysfs/group.c:278 [inline]
> RIP: 0010:sysfs_remove_group+0x155/0x1b0 fs/sysfs/group.c:269
> Code: 48 89 d9 49 8b 14 24 48 b8 00 00 00 00 00 fc ff df 48 c1 e9 03 80 3c  
> 01 00 75 41 48 8b 33 48 c7 c7 e0 c8 d0 85 e8 a0 0e 8b ff <0f> 0b eb 95 e8  
> e2 d1 db ff e9 d2 fe ff ff 48 89 df e8 d5 d1 db ff
> RSP: 0018:ffff8881c6d17c50 EFLAGS: 00010286
> RAX: 0000000000000000 RBX: ffffffff85f2d700 RCX: 0000000000000000
> RDX: 0000000000000000 RSI: ffffffff81288ddd RDI: ffffed1038da2f7c
> RBP: 0000000000000000 R08: ffff8881d6243000 R09: 0000000000000000
> R10: 0000000000000000 R11: 0000000000000000 R12: ffff8881cf014cd8
> R13: ffffffff85f2dca0 R14: 0000000000000000 R15: ffff8881cf015178
>   dpm_sysfs_remove+0x97/0xb0 drivers/base/power/sysfs.c:735
>   device_del+0x12a/0xb10 drivers/base/core.c:2316
>   device_unregister+0x11/0x30 drivers/base/core.c:2371
>   video_unregister_device+0xa2/0xc0 drivers/media/v4l2-core/v4l2-dev.c:1051
>   usbvision_unregister_video+0x83/0x120  
> drivers/media/usb/usbvision/usbvision-video.c:1243
>   usbvision_release+0x10d/0x1c0  
> drivers/media/usb/usbvision/usbvision-video.c:1356
>   usbvision_radio_close.cold+0x2b/0x74  
> drivers/media/usb/usbvision/usbvision-video.c:1129
>   v4l2_release+0x2e7/0x390 drivers/media/v4l2-core/v4l2-dev.c:455
>   __fput+0x2d7/0x840 fs/file_table.c:280
>   task_work_run+0x13f/0x1c0 kernel/task_work.c:113
>   tracehook_notify_resume include/linux/tracehook.h:188 [inline]
>   exit_to_usermode_loop+0x1d2/0x200 arch/x86/entry/common.c:163
>   prepare_exit_to_usermode arch/x86/entry/common.c:194 [inline]
>   syscall_return_slowpath arch/x86/entry/common.c:274 [inline]
>   do_syscall_64+0x45f/0x580 arch/x86/entry/common.c:299
>   entry_SYSCALL_64_after_hwframe+0x49/0xbe
> RIP: 0033:0x7f4fde8992b0
> Code: 40 75 0b 31 c0 48 83 c4 08 e9 0c ff ff ff 48 8d 3d c5 32 08 00 e8 c0  
> 07 02 00 83 3d 45 a3 2b 00 00 75 10 b8 03 00 00 00 0f 05 <48> 3d 01 f0 ff  
> ff 73 31 c3 48 83 ec 08 e8 ce 8a 01 00 48 89 04 24
> RSP: 002b:00007ffcce3d65f8 EFLAGS: 00000246 ORIG_RAX: 0000000000000003
> RAX: 0000000000000000 RBX: 0000000000000003 RCX: 00007f4fde8992b0
> RDX: 0000000000000013 RSI: 0000000080685600 RDI: 0000000000000003
> RBP: 0000000000000000 R08: 0000000000000000 R09: 0000000000000000
> R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000400884
> R13: 00007ffcce3d6750 R14: 0000000000000000 R15: 0000000000000000
> Kernel Offset: disabled
> Rebooting in 86400 seconds..
> 
> 
> Tested on:
> 
> commit:         f0df5c1b usb-fuzzer: main usb gadget fuzzer driver
> git tree:       https://github.com/google/kasan.git
> console output: https://syzkaller.appspot.com/x/log.txt?x=178ba88d600000
> kernel config:  https://syzkaller.appspot.com/x/.config?x=5c6633fa4ed00be5
> dashboard link: https://syzkaller.appspot.com/bug?extid=7fa38a608b1075dfd634
> compiler:       gcc (GCC) 9.0.0 20181231 (experimental)
> patch:          https://syzkaller.appspot.com/x/patch.diff?x=14ce1b59600000

This is more than I can fix.  The whole way the v4l2 layer handles
reference counting seems suspicious and I don't understand it.  (Does
the code assume that the only reference holders are initial
registration and open files?)

In this case it looks like the device may be unregistered twice.  It's
hard to tell exactly what's going wrong without knowing more about how
this is supposed to work.  It wouldn't hurt, for example, to use 
dev_info() instead of printk(KERN_INFO) in places like 
usbvision_disconnect().

I'm going to step back and let the maintainers deal with the rest of
this.

Alan Stern


^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: general protection fault in usb_set_interface
  2019-09-17 15:53         ` Alan Stern
@ 2019-09-17 16:06           ` syzbot
  2019-09-17 17:36             ` Alan Stern
  0 siblings, 1 reply; 30+ messages in thread
From: syzbot @ 2019-09-17 16:06 UTC (permalink / raw)
  To: andreyknvl, gregkh, kai.heng.feng, linux-kernel, linux-usb, mans,
	oneukum, stern, syzkaller-bugs

Hello,

syzbot has tested the proposed patch but the reproducer still triggered  
crash:
WARNING in sysfs_remove_group

------------[ cut here ]------------
sysfs group 'power' not found for kobject 'radio3'
WARNING: CPU: 1 PID: 2883 at fs/sysfs/group.c:278 sysfs_remove_group  
fs/sysfs/group.c:278 [inline]
WARNING: CPU: 1 PID: 2883 at fs/sysfs/group.c:278  
sysfs_remove_group+0x155/0x1b0 fs/sysfs/group.c:269
Kernel panic - not syncing: panic_on_warn set ...
CPU: 1 PID: 2883 Comm: v4l_id Not tainted 5.3.0-rc7+ #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS  
Google 01/01/2011
Call Trace:
  __dump_stack lib/dump_stack.c:77 [inline]
  dump_stack+0xca/0x13e lib/dump_stack.c:113
  panic+0x2a3/0x6da kernel/panic.c:219
  __warn.cold+0x20/0x4a kernel/panic.c:576
  report_bug+0x262/0x2a0 lib/bug.c:186
  fixup_bug arch/x86/kernel/traps.c:179 [inline]
  fixup_bug arch/x86/kernel/traps.c:174 [inline]
  do_error_trap+0x12b/0x1e0 arch/x86/kernel/traps.c:272
  do_invalid_op+0x32/0x40 arch/x86/kernel/traps.c:291
  invalid_op+0x23/0x30 arch/x86/entry/entry_64.S:1028
RIP: 0010:sysfs_remove_group fs/sysfs/group.c:278 [inline]
RIP: 0010:sysfs_remove_group+0x155/0x1b0 fs/sysfs/group.c:269
Code: 48 89 d9 49 8b 14 24 48 b8 00 00 00 00 00 fc ff df 48 c1 e9 03 80 3c  
01 00 75 41 48 8b 33 48 c7 c7 e0 c8 d0 85 e8 a0 0e 8b ff <0f> 0b eb 95 e8  
e2 d1 db ff e9 d2 fe ff ff 48 89 df e8 d5 d1 db ff
RSP: 0018:ffff8881c6d17c50 EFLAGS: 00010286
RAX: 0000000000000000 RBX: ffffffff85f2d700 RCX: 0000000000000000
RDX: 0000000000000000 RSI: ffffffff81288ddd RDI: ffffed1038da2f7c
RBP: 0000000000000000 R08: ffff8881d6243000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000000 R12: ffff8881cf014cd8
R13: ffffffff85f2dca0 R14: 0000000000000000 R15: ffff8881cf015178
  dpm_sysfs_remove+0x97/0xb0 drivers/base/power/sysfs.c:735
  device_del+0x12a/0xb10 drivers/base/core.c:2316
  device_unregister+0x11/0x30 drivers/base/core.c:2371
  video_unregister_device+0xa2/0xc0 drivers/media/v4l2-core/v4l2-dev.c:1051
  usbvision_unregister_video+0x83/0x120  
drivers/media/usb/usbvision/usbvision-video.c:1243
  usbvision_release+0x10d/0x1c0  
drivers/media/usb/usbvision/usbvision-video.c:1356
  usbvision_radio_close.cold+0x2b/0x74  
drivers/media/usb/usbvision/usbvision-video.c:1129
  v4l2_release+0x2e7/0x390 drivers/media/v4l2-core/v4l2-dev.c:455
  __fput+0x2d7/0x840 fs/file_table.c:280
  task_work_run+0x13f/0x1c0 kernel/task_work.c:113
  tracehook_notify_resume include/linux/tracehook.h:188 [inline]
  exit_to_usermode_loop+0x1d2/0x200 arch/x86/entry/common.c:163
  prepare_exit_to_usermode arch/x86/entry/common.c:194 [inline]
  syscall_return_slowpath arch/x86/entry/common.c:274 [inline]
  do_syscall_64+0x45f/0x580 arch/x86/entry/common.c:299
  entry_SYSCALL_64_after_hwframe+0x49/0xbe
RIP: 0033:0x7f4fde8992b0
Code: 40 75 0b 31 c0 48 83 c4 08 e9 0c ff ff ff 48 8d 3d c5 32 08 00 e8 c0  
07 02 00 83 3d 45 a3 2b 00 00 75 10 b8 03 00 00 00 0f 05 <48> 3d 01 f0 ff  
ff 73 31 c3 48 83 ec 08 e8 ce 8a 01 00 48 89 04 24
RSP: 002b:00007ffcce3d65f8 EFLAGS: 00000246 ORIG_RAX: 0000000000000003
RAX: 0000000000000000 RBX: 0000000000000003 RCX: 00007f4fde8992b0
RDX: 0000000000000013 RSI: 0000000080685600 RDI: 0000000000000003
RBP: 0000000000000000 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000400884
R13: 00007ffcce3d6750 R14: 0000000000000000 R15: 0000000000000000
Kernel Offset: disabled
Rebooting in 86400 seconds..


Tested on:

commit:         f0df5c1b usb-fuzzer: main usb gadget fuzzer driver
git tree:       https://github.com/google/kasan.git
console output: https://syzkaller.appspot.com/x/log.txt?x=178ba88d600000
kernel config:  https://syzkaller.appspot.com/x/.config?x=5c6633fa4ed00be5
dashboard link: https://syzkaller.appspot.com/bug?extid=7fa38a608b1075dfd634
compiler:       gcc (GCC) 9.0.0 20181231 (experimental)
patch:          https://syzkaller.appspot.com/x/patch.diff?x=14ce1b59600000


^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: general protection fault in usb_set_interface
  2019-09-17 15:28       ` syzbot
@ 2019-09-17 15:53         ` Alan Stern
  2019-09-17 16:06           ` syzbot
  0 siblings, 1 reply; 30+ messages in thread
From: Alan Stern @ 2019-09-17 15:53 UTC (permalink / raw)
  To: syzbot
  Cc: andreyknvl, gregkh, kai.heng.feng, linux-kernel, linux-usb, mans,
	oneukum, syzkaller-bugs

On Tue, 17 Sep 2019, syzbot wrote:

> Hello,
> 
> syzbot has tested the proposed patch but the reproducer still triggered  
> crash:
> possible deadlock in vidioc_querycap
> 
> ============================================
> WARNING: possible recursive locking detected
> 5.3.0-rc7+ #0 Not tainted
> --------------------------------------------
> v4l_id/3016 is trying to acquire lock:
> 0000000069c3004e (&usbvision->v4l2_lock){+.+.}, at:  
> vidioc_querycap+0x62/0x3b0 drivers/media/usb/usbvision/usbvision-video.c:456
> 
> but task is already holding lock:
> 0000000069c3004e (&usbvision->v4l2_lock){+.+.}, at:  
> __video_do_ioctl+0x3ba/0xba0 drivers/media/v4l2-core/v4l2-ioctl.c:2846

Heh.  That's what comes of trying to patch a driver when you aren't an 
expert on it already.

Okay, the lock is already held at this point so we don't need to 
acquire it.

Alan Stern

#syz test: https://github.com/google/kasan.git f0df5c1b

 drivers/media/usb/usbvision/usbvision-video.c |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

Index: usb-devel/drivers/media/usb/usbvision/usbvision-video.c
===================================================================
--- usb-devel.orig/drivers/media/usb/usbvision/usbvision-video.c
+++ usb-devel/drivers/media/usb/usbvision/usbvision-video.c
@@ -453,6 +453,9 @@ static int vidioc_querycap(struct file *
 {
 	struct usb_usbvision *usbvision = video_drvdata(file);
 
+	if (!usbvision->dev)
+		return -ENODEV;
+
 	strscpy(vc->driver, "USBVision", sizeof(vc->driver));
 	strscpy(vc->card,
 		usbvision_device_data[usbvision->dev_model].model_string,
@@ -1111,7 +1114,8 @@ static int usbvision_radio_close(struct
 	mutex_lock(&usbvision->v4l2_lock);
 	/* Set packet size to 0 */
 	usbvision->iface_alt = 0;
-	usb_set_interface(usbvision->dev, usbvision->iface,
+	if (usbvision->dev)
+		usb_set_interface(usbvision->dev, usbvision->iface,
 				    usbvision->iface_alt);
 
 	usbvision_audio_off(usbvision);


^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: general protection fault in usb_set_interface
  2019-09-17 15:16     ` Alan Stern
@ 2019-09-17 15:28       ` syzbot
  2019-09-17 15:53         ` Alan Stern
  0 siblings, 1 reply; 30+ messages in thread
From: syzbot @ 2019-09-17 15:28 UTC (permalink / raw)
  To: andreyknvl, gregkh, kai.heng.feng, linux-kernel, linux-usb, mans,
	oneukum, stern, syzkaller-bugs

Hello,

syzbot has tested the proposed patch but the reproducer still triggered  
crash:
possible deadlock in vidioc_querycap

============================================
WARNING: possible recursive locking detected
5.3.0-rc7+ #0 Not tainted
--------------------------------------------
v4l_id/3016 is trying to acquire lock:
0000000069c3004e (&usbvision->v4l2_lock){+.+.}, at:  
vidioc_querycap+0x62/0x3b0 drivers/media/usb/usbvision/usbvision-video.c:456

but task is already holding lock:
0000000069c3004e (&usbvision->v4l2_lock){+.+.}, at:  
__video_do_ioctl+0x3ba/0xba0 drivers/media/v4l2-core/v4l2-ioctl.c:2846

other info that might help us debug this:
  Possible unsafe locking scenario:

        CPU0
        ----
   lock(&usbvision->v4l2_lock);
   lock(&usbvision->v4l2_lock);

  *** DEADLOCK ***

  May be due to missing lock nesting notation

1 lock held by v4l_id/3016:
  #0: 0000000069c3004e (&usbvision->v4l2_lock){+.+.}, at:  
__video_do_ioctl+0x3ba/0xba0 drivers/media/v4l2-core/v4l2-ioctl.c:2846

stack backtrace:
CPU: 0 PID: 3016 Comm: v4l_id Not tainted 5.3.0-rc7+ #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS  
Google 01/01/2011
Call Trace:
  __dump_stack lib/dump_stack.c:77 [inline]
  dump_stack+0xca/0x13e lib/dump_stack.c:113
  print_deadlock_bug kernel/locking/lockdep.c:2301 [inline]
  check_deadlock kernel/locking/lockdep.c:2342 [inline]
  validate_chain kernel/locking/lockdep.c:2881 [inline]
  __lock_acquire.cold+0x148/0x29b kernel/locking/lockdep.c:3880
  lock_acquire+0x127/0x320 kernel/locking/lockdep.c:4412
  __mutex_lock_common kernel/locking/mutex.c:930 [inline]
  __mutex_lock+0x158/0x1360 kernel/locking/mutex.c:1077
  vidioc_querycap+0x62/0x3b0  
drivers/media/usb/usbvision/usbvision-video.c:456
  v4l_querycap+0x121/0x340 drivers/media/v4l2-core/v4l2-ioctl.c:1058
  __video_do_ioctl+0x969/0xba0 drivers/media/v4l2-core/v4l2-ioctl.c:2878
  video_usercopy+0x446/0xf40 drivers/media/v4l2-core/v4l2-ioctl.c:3060
  v4l2_ioctl+0x1a2/0x220 drivers/media/v4l2-core/v4l2-dev.c:360
  vfs_ioctl fs/ioctl.c:46 [inline]
  file_ioctl fs/ioctl.c:509 [inline]
  do_vfs_ioctl+0xd2d/0x1330 fs/ioctl.c:696
  ksys_ioctl+0x9b/0xc0 fs/ioctl.c:713
  __do_sys_ioctl fs/ioctl.c:720 [inline]
  __se_sys_ioctl fs/ioctl.c:718 [inline]
  __x64_sys_ioctl+0x6f/0xb0 fs/ioctl.c:718
  do_syscall_64+0xb7/0x580 arch/x86/entry/common.c:296
  entry_SYSCALL_64_after_hwframe+0x49/0xbe
RIP: 0033:0x7f642b0b9347
Code: 90 90 90 48 8b 05 f1 fa 2a 00 64 c7 00 26 00 00 00 48 c7 c0 ff ff ff  
ff c3 90 90 90 90 90 90 90 90 90 90 b8 10 00 00 00 0f 05 <48> 3d 01 f0 ff  
ff 73 01 c3 48 8b 0d c1 fa 2a 00 31 d2 48 29 c2 64
RSP: 002b:00007ffc2fc62b28 EFLAGS: 00000206 ORIG_RAX: 0000000000000010
RAX: ffffffffffffffda RBX: 0000000000000003 RCX: 00007f642b0b9347
RDX: 00007ffc2fc62b30 RSI: 0000000080685600 RDI: 0000000000000003
RBP: 0000000000000000 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000206 R12: 0000000000400884
R13: 00007ffc2fc62c80 R14: 0000000000000000 R15: 0000000000000000


Tested on:

commit:         f0df5c1b usb-fuzzer: main usb gadget fuzzer driver
git tree:       https://github.com/google/kasan.git
console output: https://syzkaller.appspot.com/x/log.txt?x=160d95c3600000
kernel config:  https://syzkaller.appspot.com/x/.config?x=5c6633fa4ed00be5
dashboard link: https://syzkaller.appspot.com/bug?extid=7fa38a608b1075dfd634
compiler:       gcc (GCC) 9.0.0 20181231 (experimental)
patch:          https://syzkaller.appspot.com/x/patch.diff?x=125290b1600000


^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: general protection fault in usb_set_interface
  2019-09-16 21:03   ` syzbot
@ 2019-09-17 15:16     ` Alan Stern
  2019-09-17 15:28       ` syzbot
  0 siblings, 1 reply; 30+ messages in thread
From: Alan Stern @ 2019-09-17 15:16 UTC (permalink / raw)
  To: syzbot
  Cc: andreyknvl, gregkh, kai.heng.feng, linux-kernel, linux-usb, mans,
	oneukum, syzkaller-bugs

On Mon, 16 Sep 2019, syzbot wrote:

> Hello,
> 
> syzbot has tested the proposed patch but the reproducer still triggered  
> crash:
> general protection fault in vidioc_querycap

Same problem in a different part of the code.

Alan Stern

#syz test: https://github.com/google/kasan.git f0df5c1b

 drivers/media/usb/usbvision/usbvision-video.c |   10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

Index: usb-devel/drivers/media/usb/usbvision/usbvision-video.c
===================================================================
--- usb-devel.orig/drivers/media/usb/usbvision/usbvision-video.c
+++ usb-devel/drivers/media/usb/usbvision/usbvision-video.c
@@ -453,6 +453,12 @@ static int vidioc_querycap(struct file *
 {
 	struct usb_usbvision *usbvision = video_drvdata(file);
 
+	mutex_lock(&usbvision->v4l2_lock);
+	if (!usbvision->dev) {
+		mutex_unlock(&usbvision->v4l2_lock);
+		return -ENODEV;
+	}
+
 	strscpy(vc->driver, "USBVision", sizeof(vc->driver));
 	strscpy(vc->card,
 		usbvision_device_data[usbvision->dev_model].model_string,
@@ -464,6 +470,7 @@ static int vidioc_querycap(struct file *
 		vc->capabilities |= V4L2_CAP_RADIO;
 	if (usbvision->have_tuner)
 		vc->capabilities |= V4L2_CAP_TUNER;
+	mutex_unlock(&usbvision->v4l2_lock);
 	return 0;
 }
 
@@ -1111,7 +1118,8 @@ static int usbvision_radio_close(struct
 	mutex_lock(&usbvision->v4l2_lock);
 	/* Set packet size to 0 */
 	usbvision->iface_alt = 0;
-	usb_set_interface(usbvision->dev, usbvision->iface,
+	if (usbvision->dev)
+		usb_set_interface(usbvision->dev, usbvision->iface,
 				    usbvision->iface_alt);
 
 	usbvision_audio_off(usbvision);



^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: general protection fault in usb_set_interface
  2019-09-16 20:51 ` Alan Stern
@ 2019-09-16 21:03   ` syzbot
  2019-09-17 15:16     ` Alan Stern
  0 siblings, 1 reply; 30+ messages in thread
From: syzbot @ 2019-09-16 21:03 UTC (permalink / raw)
  To: andreyknvl, gregkh, kai.heng.feng, linux-kernel, linux-usb, mans,
	oneukum, stern, syzkaller-bugs

Hello,

syzbot has tested the proposed patch but the reproducer still triggered  
crash:
general protection fault in vidioc_querycap

kasan: CONFIG_KASAN_INLINE enabled
kasan: GPF could be caused by NULL-ptr deref or user memory access
general protection fault: 0000 [#1] SMP KASAN
CPU: 0 PID: 2937 Comm: v4l_id Not tainted 5.3.0-rc7+ #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS  
Google 01/01/2011
RIP: 0010:usb_make_path include/linux/usb.h:914 [inline]
RIP: 0010:vidioc_querycap+0x11c/0x320  
drivers/media/usb/usbvision/usbvision-video.c:460
Code: 80 3c 02 00 0f 85 03 02 00 00 4c 8b ad f0 17 00 00 48 b8 00 00 00 00  
00 fc ff df 49 8d 7d 48 4d 8d 45 04 48 89 fa 48 c1 ea 03 <80> 3c 02 00 0f  
85 c7 01 00 00 48 b8 00 00 00 00 00 fc ff df 4d 8b
RSP: 0018:ffff8881c045fa28 EFLAGS: 00010206
RAX: dffffc0000000000 RBX: ffff8881c045fc18 RCX: 0000000000000000
RDX: 0000000000000009 RSI: 2e4c1f4252534d27 RDI: 0000000000000048
RBP: ffff8881d5172100 R08: 0000000000000004 R09: fffffbfff0c90220
R10: fffffbfff0c9021f R11: ffffffff864810f8 R12: ffff8881d517399c
R13: 0000000000000000 R14: ffff8881c045fc48 R15: 0000000080050000
FS:  00007fd17db9e700(0000) GS:ffff8881db200000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00007f28e2972518 CR3: 00000001d9a2b000 CR4: 00000000001406f0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
Call Trace:
  v4l_querycap+0x121/0x340 drivers/media/v4l2-core/v4l2-ioctl.c:1058
  __video_do_ioctl+0x969/0xba0 drivers/media/v4l2-core/v4l2-ioctl.c:2878
  video_usercopy+0x446/0xf40 drivers/media/v4l2-core/v4l2-ioctl.c:3060
  v4l2_ioctl+0x1a2/0x220 drivers/media/v4l2-core/v4l2-dev.c:360
  vfs_ioctl fs/ioctl.c:46 [inline]
  file_ioctl fs/ioctl.c:509 [inline]
  do_vfs_ioctl+0xd2d/0x1330 fs/ioctl.c:696
  ksys_ioctl+0x9b/0xc0 fs/ioctl.c:713
  __do_sys_ioctl fs/ioctl.c:720 [inline]
  __se_sys_ioctl fs/ioctl.c:718 [inline]
  __x64_sys_ioctl+0x6f/0xb0 fs/ioctl.c:718
  do_syscall_64+0xb7/0x580 arch/x86/entry/common.c:296
  entry_SYSCALL_64_after_hwframe+0x49/0xbe
RIP: 0033:0x7fd17d6d1347
Code: 90 90 90 48 8b 05 f1 fa 2a 00 64 c7 00 26 00 00 00 48 c7 c0 ff ff ff  
ff c3 90 90 90 90 90 90 90 90 90 90 b8 10 00 00 00 0f 05 <48> 3d 01 f0 ff  
ff 73 01 c3 48 8b 0d c1 fa 2a 00 31 d2 48 29 c2 64
RSP: 002b:00007ffd9397d098 EFLAGS: 00000202 ORIG_RAX: 0000000000000010
RAX: ffffffffffffffda RBX: 0000000000000003 RCX: 00007fd17d6d1347
RDX: 00007ffd9397d0a0 RSI: 0000000080685600 RDI: 0000000000000003
RBP: 0000000000000000 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000202 R12: 0000000000400884
R13: 00007ffd9397d1f0 R14: 0000000000000000 R15: 0000000000000000
Modules linked in:
---[ end trace e95ba987ba08e9f8 ]---
RIP: 0010:usb_make_path include/linux/usb.h:914 [inline]
RIP: 0010:vidioc_querycap+0x11c/0x320  
drivers/media/usb/usbvision/usbvision-video.c:460
Code: 80 3c 02 00 0f 85 03 02 00 00 4c 8b ad f0 17 00 00 48 b8 00 00 00 00  
00 fc ff df 49 8d 7d 48 4d 8d 45 04 48 89 fa 48 c1 ea 03 <80> 3c 02 00 0f  
85 c7 01 00 00 48 b8 00 00 00 00 00 fc ff df 4d 8b
RSP: 0018:ffff8881c045fa28 EFLAGS: 00010206
RAX: dffffc0000000000 RBX: ffff8881c045fc18 RCX: 0000000000000000
RDX: 0000000000000009 RSI: 2e4c1f4252534d27 RDI: 0000000000000048
RBP: ffff8881d5172100 R08: 0000000000000004 R09: fffffbfff0c90220
R10: fffffbfff0c9021f R11: ffffffff864810f8 R12: ffff8881d517399c
R13: 0000000000000000 R14: ffff8881c045fc48 R15: 0000000080050000
FS:  00007fd17db9e700(0000) GS:ffff8881db200000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00007f28e2972518 CR3: 00000001d9a2b000 CR4: 00000000001406f0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400


Tested on:

commit:         f0df5c1b usb-fuzzer: main usb gadget fuzzer driver
git tree:       https://github.com/google/kasan.git
console output: https://syzkaller.appspot.com/x/log.txt?x=12a52ac9600000
kernel config:  https://syzkaller.appspot.com/x/.config?x=5c6633fa4ed00be5
dashboard link: https://syzkaller.appspot.com/bug?extid=7fa38a608b1075dfd634
compiler:       gcc (GCC) 9.0.0 20181231 (experimental)
patch:          https://syzkaller.appspot.com/x/patch.diff?x=14e7f9c3600000


^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: general protection fault in usb_set_interface
  2019-09-16 13:29 general protection fault in usb_set_interface syzbot
@ 2019-09-16 20:51 ` Alan Stern
  2019-09-16 21:03   ` syzbot
  2019-12-13 12:15 ` Andrey Konovalov
  1 sibling, 1 reply; 30+ messages in thread
From: Alan Stern @ 2019-09-16 20:51 UTC (permalink / raw)
  To: syzbot
  Cc: andreyknvl, gregkh, kai.heng.feng, linux-kernel, linux-usb, mans,
	oneukum, syzkaller-bugs

On Mon, 16 Sep 2019, syzbot wrote:

> Hello,
> 
> syzbot found the following crash on:
> 
> HEAD commit:    f0df5c1b usb-fuzzer: main usb gadget fuzzer driver
> git tree:       https://github.com/google/kasan.git usb-fuzzer
> console output: https://syzkaller.appspot.com/x/log.txt?x=158b66f1600000
> kernel config:  https://syzkaller.appspot.com/x/.config?x=5c6633fa4ed00be5
> dashboard link: https://syzkaller.appspot.com/bug?extid=7fa38a608b1075dfd634
> compiler:       gcc (GCC) 9.0.0 20181231 (experimental)
> syz repro:      https://syzkaller.appspot.com/x/repro.syz?x=14f57db9600000
> C reproducer:   https://syzkaller.appspot.com/x/repro.c?x=127b61a5600000
> 
> IMPORTANT: if you fix the bug, please add the following tag to the commit:
> Reported-by: syzbot+7fa38a608b1075dfd634@syzkaller.appspotmail.com
> 
> usb 3-1: usbvision_write_reg: failed: error -2
> usbvision_set_audio: can't write iopin register for audio switching
> kasan: CONFIG_KASAN_INLINE enabled
> kasan: GPF could be caused by NULL-ptr deref or user memory access
> general protection fault: 0000 [#1] SMP KASAN
> CPU: 1 PID: 1955 Comm: v4l_id Not tainted 5.3.0-rc7+ #0
> Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS  
> Google 01/01/2011
> RIP: 0010:usb_set_interface+0x34/0xa50 drivers/usb/core/message.c:1362
> Code: fc 55 53 48 83 ec 40 89 54 24 18 89 74 24 10 e8 22 1c ef fd 49 8d 7c  
> 24 48 48 b8 00 00 00 00 00 fc ff df 48 89 fa 48 c1 ea 03 <80> 3c 02 00 0f  
> 85 fb 08 00 00 49 8b 44 24 48 49 8d 7c 24 18 48 89
> RSP: 0018:ffff8881cb19fd50 EFLAGS: 00010206
> RAX: dffffc0000000000 RBX: 0000000000000000 RCX: 0000000000000000
> RDX: 0000000000000009 RSI: ffffffff834ebe7e RDI: 0000000000000048
> RBP: ffff8881cb8e4200 R08: ffffffff88d21878 R09: ffffed103971cb43
> R10: ffff8881cb19fdc8 R11: ffff8881cb8e5a17 R12: 0000000000000000
> R13: ffff8881cb8e5a10 R14: ffff8881cb8e4cc8 R15: ffff8881cb8e5178
> FS:  00007f4f60b6d700(0000) GS:ffff8881db300000(0000) knlGS:0000000000000000
> CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
> CR2: 00007f4f6060c330 CR3: 00000001cc3a8000 CR4: 00000000001406e0
> DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
> DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
> Call Trace:
>   usbvision_radio_close+0x105/0x250  
> drivers/media/usb/usbvision/usbvision-video.c:1114
>   v4l2_release+0x2e7/0x390 drivers/media/v4l2-core/v4l2-dev.c:455
>   __fput+0x2d7/0x840 fs/file_table.c:280
>   task_work_run+0x13f/0x1c0 kernel/task_work.c:113
>   tracehook_notify_resume include/linux/tracehook.h:188 [inline]
>   exit_to_usermode_loop+0x1d2/0x200 arch/x86/entry/common.c:163
>   prepare_exit_to_usermode arch/x86/entry/common.c:194 [inline]
>   syscall_return_slowpath arch/x86/entry/common.c:274 [inline]
>   do_syscall_64+0x45f/0x580 arch/x86/entry/common.c:299
>   entry_SYSCALL_64_after_hwframe+0x49/0xbe
> RIP: 0033:0x7f4f6069b2b0
> Code: 40 75 0b 31 c0 48 83 c4 08 e9 0c ff ff ff 48 8d 3d c5 32 08 00 e8 c0  
> 07 02 00 83 3d 45 a3 2b 00 00 75 10 b8 03 00 00 00 0f 05 <48> 3d 01 f0 ff  
> ff 73 31 c3 48 83 ec 08 e8 ce 8a 01 00 48 89 04 24
> RSP: 002b:00007ffde2d50ee8 EFLAGS: 00000246 ORIG_RAX: 0000000000000003
> RAX: 0000000000000000 RBX: 0000000000000003 RCX: 00007f4f6069b2b0
> RDX: 00007f4f60951df0 RSI: 0000000000000001 RDI: 0000000000000003
> RBP: 0000000000000000 R08: 00007f4f60951df0 R09: 000000000000000a
> R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000400884
> R13: 00007ffde2d51040 R14: 0000000000000000 R15: 0000000000000000
> Modules linked in:
> ---[ end trace 62bd2b7512ab49ee ]---
> RIP: 0010:usb_set_interface+0x34/0xa50 drivers/usb/core/message.c:1362
> Code: fc 55 53 48 83 ec 40 89 54 24 18 89 74 24 10 e8 22 1c ef fd 49 8d 7c  
> 24 48 48 b8 00 00 00 00 00 fc ff df 48 89 fa 48 c1 ea 03 <80> 3c 02 00 0f  
> 85 fb 08 00 00 49 8b 44 24 48 49 8d 7c 24 18 48 89
> RSP: 0018:ffff8881cb19fd50 EFLAGS: 00010206
> RAX: dffffc0000000000 RBX: 0000000000000000 RCX: 0000000000000000
> RDX: 0000000000000009 RSI: ffffffff834ebe7e RDI: 0000000000000048
> RBP: ffff8881cb8e4200 R08: ffffffff88d21878 R09: ffffed103971cb43
> R10: ffff8881cb19fdc8 R11: ffff8881cb8e5a17 R12: 0000000000000000
> R13: ffff8881cb8e5a10 R14: ffff8881cb8e4cc8 R15: ffff8881cb8e5178
> FS:  00007f4f60b6d700(0000) GS:ffff8881db300000(0000) knlGS:0000000000000000
> CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
> CR2: 00007f4f6060c330 CR3: 00000001cc3a8000 CR4: 00000000001406e0
> DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
> DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
> 
> 
> ---
> This bug is generated by a bot. It may contain errors.
> See https://goo.gl/tpsmEJ for more information about syzbot.
> syzbot engineers can be reached at syzkaller@googlegroups.com.
> 
> syzbot will keep track of this bug report. See:
> https://goo.gl/tpsmEJ#status for how to communicate with syzbot.
> syzbot can test patches for this bug, for details see:
> https://goo.gl/tpsmEJ#testing-patches

Use-after-free bug.

Alan Stern

#syz test: https://github.com/google/kasan.git f0df5c1b

 drivers/media/usb/usbvision/usbvision-video.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Index: usb-devel/drivers/media/usb/usbvision/usbvision-video.c
===================================================================
--- usb-devel.orig/drivers/media/usb/usbvision/usbvision-video.c
+++ usb-devel/drivers/media/usb/usbvision/usbvision-video.c
@@ -1111,7 +1111,8 @@ static int usbvision_radio_close(struct
 	mutex_lock(&usbvision->v4l2_lock);
 	/* Set packet size to 0 */
 	usbvision->iface_alt = 0;
-	usb_set_interface(usbvision->dev, usbvision->iface,
+	if (usbvision->dev)
+		usb_set_interface(usbvision->dev, usbvision->iface,
 				    usbvision->iface_alt);
 
 	usbvision_audio_off(usbvision);


^ permalink raw reply	[flat|nested] 30+ messages in thread

* general protection fault in usb_set_interface
@ 2019-09-16 13:29 syzbot
  2019-09-16 20:51 ` Alan Stern
  2019-12-13 12:15 ` Andrey Konovalov
  0 siblings, 2 replies; 30+ messages in thread
From: syzbot @ 2019-09-16 13:29 UTC (permalink / raw)
  To: andreyknvl, gregkh, kai.heng.feng, linux-kernel, linux-usb, mans,
	oneukum, stern, syzkaller-bugs

Hello,

syzbot found the following crash on:

HEAD commit:    f0df5c1b usb-fuzzer: main usb gadget fuzzer driver
git tree:       https://github.com/google/kasan.git usb-fuzzer
console output: https://syzkaller.appspot.com/x/log.txt?x=158b66f1600000
kernel config:  https://syzkaller.appspot.com/x/.config?x=5c6633fa4ed00be5
dashboard link: https://syzkaller.appspot.com/bug?extid=7fa38a608b1075dfd634
compiler:       gcc (GCC) 9.0.0 20181231 (experimental)
syz repro:      https://syzkaller.appspot.com/x/repro.syz?x=14f57db9600000
C reproducer:   https://syzkaller.appspot.com/x/repro.c?x=127b61a5600000

IMPORTANT: if you fix the bug, please add the following tag to the commit:
Reported-by: syzbot+7fa38a608b1075dfd634@syzkaller.appspotmail.com

usb 3-1: usbvision_write_reg: failed: error -2
usbvision_set_audio: can't write iopin register for audio switching
kasan: CONFIG_KASAN_INLINE enabled
kasan: GPF could be caused by NULL-ptr deref or user memory access
general protection fault: 0000 [#1] SMP KASAN
CPU: 1 PID: 1955 Comm: v4l_id Not tainted 5.3.0-rc7+ #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS  
Google 01/01/2011
RIP: 0010:usb_set_interface+0x34/0xa50 drivers/usb/core/message.c:1362
Code: fc 55 53 48 83 ec 40 89 54 24 18 89 74 24 10 e8 22 1c ef fd 49 8d 7c  
24 48 48 b8 00 00 00 00 00 fc ff df 48 89 fa 48 c1 ea 03 <80> 3c 02 00 0f  
85 fb 08 00 00 49 8b 44 24 48 49 8d 7c 24 18 48 89
RSP: 0018:ffff8881cb19fd50 EFLAGS: 00010206
RAX: dffffc0000000000 RBX: 0000000000000000 RCX: 0000000000000000
RDX: 0000000000000009 RSI: ffffffff834ebe7e RDI: 0000000000000048
RBP: ffff8881cb8e4200 R08: ffffffff88d21878 R09: ffffed103971cb43
R10: ffff8881cb19fdc8 R11: ffff8881cb8e5a17 R12: 0000000000000000
R13: ffff8881cb8e5a10 R14: ffff8881cb8e4cc8 R15: ffff8881cb8e5178
FS:  00007f4f60b6d700(0000) GS:ffff8881db300000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00007f4f6060c330 CR3: 00000001cc3a8000 CR4: 00000000001406e0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
Call Trace:
  usbvision_radio_close+0x105/0x250  
drivers/media/usb/usbvision/usbvision-video.c:1114
  v4l2_release+0x2e7/0x390 drivers/media/v4l2-core/v4l2-dev.c:455
  __fput+0x2d7/0x840 fs/file_table.c:280
  task_work_run+0x13f/0x1c0 kernel/task_work.c:113
  tracehook_notify_resume include/linux/tracehook.h:188 [inline]
  exit_to_usermode_loop+0x1d2/0x200 arch/x86/entry/common.c:163
  prepare_exit_to_usermode arch/x86/entry/common.c:194 [inline]
  syscall_return_slowpath arch/x86/entry/common.c:274 [inline]
  do_syscall_64+0x45f/0x580 arch/x86/entry/common.c:299
  entry_SYSCALL_64_after_hwframe+0x49/0xbe
RIP: 0033:0x7f4f6069b2b0
Code: 40 75 0b 31 c0 48 83 c4 08 e9 0c ff ff ff 48 8d 3d c5 32 08 00 e8 c0  
07 02 00 83 3d 45 a3 2b 00 00 75 10 b8 03 00 00 00 0f 05 <48> 3d 01 f0 ff  
ff 73 31 c3 48 83 ec 08 e8 ce 8a 01 00 48 89 04 24
RSP: 002b:00007ffde2d50ee8 EFLAGS: 00000246 ORIG_RAX: 0000000000000003
RAX: 0000000000000000 RBX: 0000000000000003 RCX: 00007f4f6069b2b0
RDX: 00007f4f60951df0 RSI: 0000000000000001 RDI: 0000000000000003
RBP: 0000000000000000 R08: 00007f4f60951df0 R09: 000000000000000a
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000400884
R13: 00007ffde2d51040 R14: 0000000000000000 R15: 0000000000000000
Modules linked in:
---[ end trace 62bd2b7512ab49ee ]---
RIP: 0010:usb_set_interface+0x34/0xa50 drivers/usb/core/message.c:1362
Code: fc 55 53 48 83 ec 40 89 54 24 18 89 74 24 10 e8 22 1c ef fd 49 8d 7c  
24 48 48 b8 00 00 00 00 00 fc ff df 48 89 fa 48 c1 ea 03 <80> 3c 02 00 0f  
85 fb 08 00 00 49 8b 44 24 48 49 8d 7c 24 18 48 89
RSP: 0018:ffff8881cb19fd50 EFLAGS: 00010206
RAX: dffffc0000000000 RBX: 0000000000000000 RCX: 0000000000000000
RDX: 0000000000000009 RSI: ffffffff834ebe7e RDI: 0000000000000048
RBP: ffff8881cb8e4200 R08: ffffffff88d21878 R09: ffffed103971cb43
R10: ffff8881cb19fdc8 R11: ffff8881cb8e5a17 R12: 0000000000000000
R13: ffff8881cb8e5a10 R14: ffff8881cb8e4cc8 R15: ffff8881cb8e5178
FS:  00007f4f60b6d700(0000) GS:ffff8881db300000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00007f4f6060c330 CR3: 00000001cc3a8000 CR4: 00000000001406e0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400


---
This bug is generated by a bot. It may contain errors.
See https://goo.gl/tpsmEJ for more information about syzbot.
syzbot engineers can be reached at syzkaller@googlegroups.com.

syzbot will keep track of this bug report. See:
https://goo.gl/tpsmEJ#status for how to communicate with syzbot.
syzbot can test patches for this bug, for details see:
https://goo.gl/tpsmEJ#testing-patches

^ permalink raw reply	[flat|nested] 30+ messages in thread

end of thread, other threads:[~2019-12-13 20:36 UTC | newest]

Thread overview: 30+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-09 22:15 KASAN: use-after-free Read in usbvision_v4l2_open syzbot
2019-12-10 19:47 ` Alan Stern
2019-12-10 19:48   ` syzbot
2019-12-10 20:17     ` Alan Stern
2019-12-11 14:23       ` Andrey Konovalov
2019-12-11 15:14         ` Alan Stern
2019-12-11 15:35           ` Dmitry Vyukov
2019-12-12 16:52       ` general protection fault in usb_set_interface Alan Stern
2019-12-10 19:48   ` Re: KASAN: use-after-free Read in usbvision_v4l2_open syzbot
2019-12-10 20:06   ` Andrey Konovalov
2019-12-10 20:13     ` Alan Stern
2019-12-11 14:22       ` Andrey Konovalov
2019-12-11 15:30         ` Dmitry Vyukov
2019-12-11 16:22           ` Alan Stern
2019-12-12 16:08             ` Andrey Konovalov
  -- strict thread matches above, loose matches on Subject: below --
2019-09-16 13:29 general protection fault in usb_set_interface syzbot
2019-09-16 20:51 ` Alan Stern
2019-09-16 21:03   ` syzbot
2019-09-17 15:16     ` Alan Stern
2019-09-17 15:28       ` syzbot
2019-09-17 15:53         ` Alan Stern
2019-09-17 16:06           ` syzbot
2019-09-17 17:36             ` Alan Stern
2019-09-17 18:08               ` Alan Stern
2019-09-17 18:15                 ` syzbot
2019-09-17 18:31                   ` Alan Stern
2019-09-17 18:43                     ` syzbot
2019-09-18 18:57                       ` Alan Stern
2019-09-19 15:19                         ` Andrey Konovalov
2019-12-13 12:15 ` Andrey Konovalov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).