WARNING in usbtmc_ioctl/usb_submit_urb
syzbot
syzbotHello,
syzbot found the following issue on:
HEAD commit: 2293be58d6a1 Merge tag 'trace-v5.17-rc4' of git://git.kern.. git tree: upstream console output: https://syzkaller.appspot.com/x/log.txt?x=166215b6700000 kernel config: https://syzkaller.appspot.com/x/.config?x=4b9a7fa580ff2b33 dashboard link: https://syzkaller.appspot.com/bug?extid=a48e3d1a875240cab5de compiler: Debian clang version 11.0.1-2, GNU ld (GNU Binutils for Debian) 2.35.2 syz repro: https://syzkaller.appspot.com/x/repro.syz?x=172cdd12700000 C reproducer: https://syzkaller.appspot.com/x/repro.c?x=170790e6700000
Bisection is inconclusive: the issue happens on the oldest tested release.
bisection log: https://syzkaller.appspot.com/x/bisect.txt?x=15f51482700000 final oops: https://syzkaller.appspot.com/x/report.txt?x=17f51482700000 console output: https://syzkaller.appspot.com/x/log.txt?x=13f51482700000
IMPORTANT: if you fix the issue, please add the following tag to the commit:
usb 5-1: BOGUS control dir, pipe 80001e80 doesn't match bRequestType 0
WARNING: CPU: 0 PID: 3813 at drivers/usb/core/urb.c:412 usb_submit_urb+0x13a5/0x1970 drivers/usb/core/urb.c:410 Modules linked in: CPU: 0 PID: 3813 Comm: syz-executor122 Not tainted 5.17.0-rc5-syzkaller-00306-g2293be58d6a1 #0 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011 RIP: 0010:usb_submit_urb+0x13a5/0x1970 drivers/usb/core/urb.c:410 Code: 4c 24 38 8a 04 01 84 c0 0f 85 ad 05 00 00 45 0f b6 06 48 c7 c7 c0 f0 26 8b 48 8b 74 24 20 4c 89 e2 89 d9 31 c0 e8 3b 4b 58 fb <0f> 0b e9 0b f0 ff ff 89 d9 80 e1 07 80 c1 03 38 c1 0f 8c a8 ed ff RSP: 0018:ffffc90002c3fa40 EFLAGS: 00010246 RAX: 1323d10499d7ec00 RBX: 0000000080001e80 RCX: ffff88801c2c5700 RDX: 0000000000000000 RSI: 0000000080000000 RDI: 0000000000000000 RBP: 0000000000000000 R08: ffffffff816aea02 R09: fffffbfff1ffbbde R10: fffffbfff1ffbbde R11: 0000000000000000 R12: ffff88801d757618 R13: ffff88801d79d000 R14: ffff88801da98b18 R15: ffff88807a91f0a8 FS: 00005555574a2300(0000) GS:ffff8880b9a00000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007fa78ffa04d0 CR3: 00000000195f0000 CR4: 00000000003506f0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 Call Trace: <TASK> usb_start_wait_urb+0x113/0x530 drivers/usb/core/message.c:58 usb_internal_control_msg drivers/usb/core/message.c:102 [inline] usb_control_msg+0x2a5/0x4b0 drivers/usb/core/message.c:153 usbtmc_ioctl_request drivers/usb/class/usbtmc.c:1947 [inline] usbtmc_ioctl+0x164e/0x20e0 drivers/usb/class/usbtmc.c:2090 vfs_ioctl fs/ioctl.c:51 [inline] __do_sys_ioctl fs/ioctl.c:874 [inline] __se_sys_ioctl+0xfb/0x170 fs/ioctl.c:860 do_syscall_x64 arch/x86/entry/common.c:50 [inline] do_syscall_64+0x44/0xd0 arch/x86/entry/common.c:80 entry_SYSCALL_64_after_hwframe+0x44/0xae RIP: 0033:0x7fe3805832a9 Code: 28 00 00 00 75 05 48 83 c4 28 c3 e8 b1 14 00 00 90 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 c0 ff ff ff f7 d8 64 89 01 48 RSP: 002b:00007ffec2198ee8 EFLAGS: 00000246 ORIG_RAX: 0000000000000010 RAX: ffffffffffffffda RBX: 00000000000f4240 RCX: 00007fe3805832a9 RDX: 0000000020000140 RSI: 00000000c0105b08 RDI: 0000000000000005 RBP: 0000000000000000 R08: 0000000000000001 R09: 0000000000000001 R10: 000000000000000f R11: 0000000000000246 R12: 00000000000530bd R13: 00007ffec2198efc R14: 00007ffec2198f10 R15: 00007ffec2198f00 </TASK>
---
This report 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 [email protected].
syzbot will keep track of this issue. See:
https://goo.gl/tpsmEJ#status for how to communicate with syzbot. For information about bisection process see: https://goo.gl/tpsmEJ#bisection
syzbot can test patches for this issue, for details see:
https://goo.gl/tpsmEJ#testing-patches
Quoted 38 lines · syzbot
Hello,
syzbot found the following issue on:
HEAD commit: 2293be58d6a1 Merge tag 'trace-v5.17-rc4' of git://git.kern.. git tree: upstream console output: https://syzkaller.appspot.com/x/log.txt?x=166215b6700000 kernel config: https://syzkaller.appspot.com/x/.config?x=4b9a7fa580ff2b33 dashboard link: https://syzkaller.appspot.com/bug?extid=a48e3d1a875240cab5de compiler: Debian clang version 11.0.1-2, GNU ld (GNU Binutils for Debian) 2.35.2 syz repro: https://syzkaller.appspot.com/x/repro.syz?x=172cdd12700000 C reproducer: https://syzkaller.appspot.com/x/repro.c?x=170790e6700000Bisection is inconclusive: the issue happens on the oldest tested release.
bisection log: https://syzkaller.appspot.com/x/bisect.txt?x=15f51482700000 final oops: https://syzkaller.appspot.com/x/report.txt?x=17f51482700000 console output: https://syzkaller.appspot.com/x/log.txt?x=13f51482700000IMPORTANT: if you fix the issue, please add the following tag to the commit:
Reported-by [email protected]usb 5-1: BOGUS control dir, pipe
80001e80doesn't match bRequestType 0WARNING: CPU: 0 PID: 3813 at drivers/usb/core/urb.c:412 usb_submit_urb+0x13a5/0x1970 drivers/usb/core/urb.c:410 Modules linked in: CPU: 0 PID: 3813 Comm: syz-executor122 Not tainted 5.17.0-rc5-syzkaller-00306-g2293be58d6a1 #0 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011 RIP: 0010:usb_submit_urb+0x13a5/0x1970 drivers/usb/core/urb.c:410 Code: 4c 24 38 8a 04 01 84 c0 0f 85 ad 05 00 00 45 0f b6 06 48 c7 c7 c0 f0 26 8b 48 8b 74 24 20 4c 89 e2 89 d9 31 c0 e8 3b 4b 58 fb <0f> 0b e9 0b f0 ff ff 89 d9 80 e1 07 80 c1 03 38 c1 0f 8c a8 ed ff RSP: 0018:ffffc90002c3fa40 EFLAGS: 00010246 RAX: 1323d10499d7ec00 RBX: 0000000080001e80 RCX: ffff88801c2c5700 RDX: 0000000000000000 RSI: 0000000080000000 RDI: 0000000000000000 RBP: 0000000000000000 R08: ffffffff816aea02 R09: fffffbfff1ffbbde R10: fffffbfff1ffbbde R11: 0000000000000000 R12: ffff88801d757618 R13: ffff88801d79d000 R14: ffff88801da98b18 R15: ffff88807a91f0a8 FS: 00005555574a2300(0000) GS:ffff8880b9a00000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007fa78ffa04d0 CR3: 00000000195f0000 CR4: 00000000003506f0
Quoted 8 lines
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 Call Trace: <TASK> usb_start_wait_urb+0x113/0x530 drivers/usb/core/message.c:58 usb_internal_control_msg drivers/usb/core/message.c:102 [inline] usb_control_msg+0x2a5/0x4b0 drivers/usb/core/message.c:153 usbtmc_ioctl_request drivers/usb/class/usbtmc.c:1947 [inline]
#syz test: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/ v5.17-rc4
drivers/usb/class/usbtmc.c +10 -3
@@ -1919,6 +1919,7 @@ static int usbtmc_ioctl_request(struct ustruct usbtmc_ctrlrequest request;u8 *buffer =NULL ;int rv; +unsigned int is_in, pipe;unsigned long res; res =copy_from_user (&request, arg,sizeof (struct usbtmc_ctrlrequest ));
@@ -1928,12 +1929,14 @@ static int usbtmc_ioctl_request(struct uif (request.req.wLength >USBTMC_BUFSIZE )return -EMSGSIZE ; + is_in = request.req.bRequestType &USB_DIR_IN ; +if (request.req.wLength) { buffer =kmalloc (request.req.wLength,GFP_KERNEL );if (!buffer)return -ENOMEM ; -if ((request.req.bRequestType &USB_DIR_IN ) ==0 ) { +if (!is_in) {/* Send control data to device */ res =copy_from_user (buffer, request.data, request.req.wLength);
@@ -1944,8 +1947,12 @@ static int usbtmc_ioctl_request(struct u } } +if (is_in) + pipe =usb_rcvctrlpipe (data->usb_dev,0 ); +else + pipe =usb_sndctrlpipe (data->usb_dev,0 ); rv = usb_control_msg(data->usb_dev, - usb_rcvctrlpipe(data->usb_dev, 0), + pipe, request.req.bRequest, request.req.bRequestType, request.req.wValue,
@@ -1957,7 +1964,7 @@ static int usbtmc_ioctl_request(struct u goto exit; } -if (rv && (request.req.bRequestType &USB_DIR_IN )) { +if (rv && is_in) {/* Read control data from device */ res =copy_to_user (request.data, buffer, rv);if (res)
syzbot
syzbotsyzbot has tested the proposed patch and the reproducer did not trigger any issue:
Hello,
syzbot has tested the proposed patch and the reproducer did not trigger any issue:
Tested on:
commit: 754e0b0e Linux 5.17-rc4 git tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/ v5.17-rc4 kernel config: https://syzkaller.appspot.com/x/.config?x=f4cd52967afc7901 dashboard link: https://syzkaller.appspot.com/bug?extid=a48e3d1a875240cab5de compiler: gcc (Debian 10.2.1-6) 10.2.1 20210110, GNU ld (GNU Binutils for Debian) 2.35.2 patch: https://syzkaller.appspot.com/x/patch.diff?x=140dcc16700000
Note: testing is done by a robot and is best-effort only.
PATCH 1/1 usb: usbtmc: Fix bug in pipe direction for control transfers
The syzbot fuzzer reported a minor bug in the usbtmc driver:
usb 5-1: BOGUS control dir, pipe 80001e80 doesn't match bRequestType 0
WARNING: CPU: 0 PID: 3813 at drivers/usb/core/urb.c:412 usb_submit_urb+0x13a5/0x1970 drivers/usb/core/urb.c:410 Modules linked in: CPU: 0 PID: 3813 Comm: syz-executor122 Not tainted 5.17.0-rc5-syzkaller-00306-g2293be58d6a1 #0 ... Call Trace: <TASK> usb_start_wait_urb+0x113/0x530 drivers/usb/core/message.c:58 usb_internal_control_msg drivers/usb/core/message.c:102 [inline] usb_control_msg+0x2a5/0x4b0 drivers/usb/core/message.c:153 usbtmc_ioctl_request drivers/usb/class/usbtmc.c:1947 [inline]
The problem is that usbtmc_ioctl_request() uses usb_rcvctrlpipe() for all of its transfers, whether they are in or out. It's easy to fix.
---
[as1973]
drivers/usb/class/usbtmc.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
drivers/usb/class/usbtmc.c +10 -3
@@ -1919,6 +1919,7 @@ static int usbtmc_ioctl_request(struct ustruct usbtmc_ctrlrequest request;u8 *buffer =NULL ;int rv; +unsigned int is_in, pipe;unsigned long res; res =copy_from_user (&request, arg,sizeof (struct usbtmc_ctrlrequest ));
@@ -1928,12 +1929,14 @@ static int usbtmc_ioctl_request(struct uif (request.req.wLength >USBTMC_BUFSIZE )return -EMSGSIZE ; + is_in = request.req.bRequestType &USB_DIR_IN ; +if (request.req.wLength) { buffer =kmalloc (request.req.wLength,GFP_KERNEL );if (!buffer)return -ENOMEM ; -if ((request.req.bRequestType &USB_DIR_IN ) ==0 ) { +if (!is_in) {/* Send control data to device */ res =copy_from_user (buffer, request.data, request.req.wLength);
@@ -1944,8 +1947,12 @@ static int usbtmc_ioctl_request(struct u } } +if (is_in) + pipe =usb_rcvctrlpipe (data->usb_dev,0 ); +else + pipe =usb_sndctrlpipe (data->usb_dev,0 ); rv = usb_control_msg(data->usb_dev, - usb_rcvctrlpipe(data->usb_dev, 0), + pipe, request.req.bRequest, request.req.bRequestType, request.req.wValue,
@@ -1957,7 +1964,7 @@ static int usbtmc_ioctl_request(struct u goto exit; } -if (rv && (request.req.bRequestType &USB_DIR_IN )) { +if (rv && is_in) {/* Read control data from device */ res =copy_to_user (request.data, buffer, rv);if (res)