LKML Archive on lore.kernel.org
 help / color / Atom feed
* 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; 19+ 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] 19+ 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; 19+ 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] 19+ 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; 19+ 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] 19+ 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; 19+ 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] 19+ 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; 19+ 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] 19+ 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; 19+ 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] 19+ 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; 19+ 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] 19+ 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; 19+ 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] 19+ 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; 19+ 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] 19+ 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; 19+ 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] 19+ 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; 19+ 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] 19+ 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; 19+ 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] 19+ 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; 19+ 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] 19+ 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; 19+ 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] 19+ messages in thread

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

> 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

This bug is already marked as fixed. No point in testing.


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

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

On Fri, Dec 13, 2019 at 1:16 PM syzbot
<syzbot+7fa38a608b1075dfd634@syzkaller.appspotmail.com> wrote:
>
> > 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
>
> This bug is already marked as fixed. No point in testing.
>

Hm, that explains some of the weirdness. It doesn't explain though
neither why the patch was actually tested when Alan requested it nor
why syzbot sent no reply.

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

* Re: Re: general protection fault in usb_set_interface
  2019-12-13 12:19     ` Andrey Konovalov
@ 2019-12-13 19:51       ` Alan Stern
  0 siblings, 0 replies; 19+ messages in thread
From: Alan Stern @ 2019-12-13 19:51 UTC (permalink / raw)
  To: Andrey Konovalov; +Cc: syzbot, LKML, USB list, mans, syzkaller-bugs

On Fri, 13 Dec 2019, Andrey Konovalov wrote:

> > > Let's retry here:
> >
> > > #syz test: https://github.com/google/kasan.git f0df5c1b
> >
> > This bug is already marked as fixed. No point in testing.
> >
> 
> Hm, that explains some of the weirdness. It doesn't explain though
> neither why the patch was actually tested when Alan requested it nor
> why syzbot sent no reply.

In the meantime, is there any way to get syzbot to test the new patch
with the old reproducer?  Perhaps tell it to re-open this bug?

Alan Stern


^ permalink raw reply	[flat|nested] 19+ 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
  2019-12-13 12:16   ` syzbot
  1 sibling, 1 reply; 19+ 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] 19+ messages in thread

* Re: general protection fault in usb_set_interface
  2019-12-10 20:17 Re: KASAN: use-after-free Read in usbvision_v4l2_open Alan Stern
@ 2019-12-12 16:52 ` Alan Stern
  0 siblings, 0 replies; 19+ 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] 19+ messages in thread

end of thread, back to index

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2019-12-13 12:16   ` syzbot
2019-12-13 12:19     ` Andrey Konovalov
2019-12-13 19:51       ` Alan Stern
2019-12-10 20:17 Re: KASAN: use-after-free Read in usbvision_v4l2_open Alan Stern
2019-12-12 16:52 ` general protection fault in usb_set_interface Alan Stern

LKML Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/lkml/0 lkml/git/0.git
	git clone --mirror https://lore.kernel.org/lkml/1 lkml/git/1.git
	git clone --mirror https://lore.kernel.org/lkml/2 lkml/git/2.git
	git clone --mirror https://lore.kernel.org/lkml/3 lkml/git/3.git
	git clone --mirror https://lore.kernel.org/lkml/4 lkml/git/4.git
	git clone --mirror https://lore.kernel.org/lkml/5 lkml/git/5.git
	git clone --mirror https://lore.kernel.org/lkml/6 lkml/git/6.git
	git clone --mirror https://lore.kernel.org/lkml/7 lkml/git/7.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 lkml lkml/ https://lore.kernel.org/lkml \
		linux-kernel@vger.kernel.org
	public-inbox-index lkml

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-kernel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git