BUG: sleeping function called from invalid context in dummy_dequeue
syzbot
syzbotHello,
syzbot found the following issue on:
HEAD commit: 8d245acc1e88 Merge tag 'char-misc-6.17-rc3' of git://git.k.. git tree: upstream console output: https://syzkaller.appspot.com/x/log.txt?x=11e42062580000 kernel config: https://syzkaller.appspot.com/x/.config?x=e1e1566c7726877e dashboard link: https://syzkaller.appspot.com/bug?extid=8baacc4139f12fa77909 compiler: Debian clang version 20.1.7 (++20250616065708+6146a88f6049-1~exp1~20250616065826.132), Debian LLD 20.1.7 syz repro: https://syzkaller.appspot.com/x/repro.syz?x=13317062580000 C reproducer: https://syzkaller.appspot.com/x/repro.c?x=14d5ea34580000
Downloadable assets:
disk image: https://storage.googleapis.com/syzbot-assets/096739d8f0ec/disk-8d245acc.raw.xz
vmlinux: https://storage.googleapis.com/syzbot-assets/83a21aa9b978/vmlinux-8d245acc.xz
kernel image: https://storage.googleapis.com/syzbot-assets/7e7f165a3b29/bzImage-8d245acc.xz
IMPORTANT: if you fix the issue, please add the following tag to the commit:
BUG: sleeping function called from invalid context at kernel/locking/spinlock_rt.c:48
in_atomic(): 0, irqs_disabled(): 1, non_block: 0, pid: 6118, name: syz.0.17preempt_count: 0, expected: 0
RCU nest depth: 0, expected: 0
1 lock held by syz.0.17/6118:
#0: ffff888144724058 (&dum_hcd->dum->lock){+.+.}-{3:3}, at: spin_lock include/linux/spinlock_rt.h:44 [inline] #0: ffff888144724058 (&dum_hcd->dum->lock){+.+.}-{3:3}, at: dummy_dequeue+0x164/0x480 drivers/usb/gadget/udc/dummy_hcd.c:769
irq event stamp: 5054
hardirqs last enabled at (5053): [<ffffffff8af9b343>] __raw_spin_unlock_irq include/linux/spinlock_api_smp.h:159 [inline]
hardirqs last enabled at (5053): [<ffffffff8af9b343>] _raw_spin_unlock_irq+0x23/0x50 kernel/locking/spinlock.c:202
hardirqs last disabled at (5054): [<ffffffff86fc2471>] dummy_dequeue+0x151/0x480 drivers/usb/gadget/udc/dummy_hcd.c:768
softirqs last enabled at (0): [<ffffffff81828ba9>] rcu_lock_acquire include/linux/rcupdate.h:331 [inline]
softirqs last enabled at (0): [<ffffffff81828ba9>] rcu_read_lock include/linux/rcupdate.h:841 [inline]
softirqs last enabled at (0): [<ffffffff81828ba9>] copy_process+0x979/0x3ae0 kernel/fork.c:2043
softirqs last disabled at (0): [<0000000000000000>] 0x0
CPU: 0 UID: 0 PID: 6118 Comm: syz.0.17 Not tainted syzkaller #0 PREEMPT_{RT,(full)}
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 07/12/2025
Call Trace:
<TASK>
dump_stack_lvl+0x189/0x250 lib/dump_stack.c:120
__might_resched+0x44b/0x5d0 kernel/sched/core.c:8957
__rt_spin_lock kernel/locking/spinlock_rt.c:48 [inline]
rt_spin_lock+0xc7/0x2c0 kernel/locking/spinlock_rt.c:57
spin_lock include/linux/spinlock_rt.h:44 [inline]
dummy_dequeue+0x164/0x480 drivers/usb/gadget/udc/dummy_hcd.c:769
usb_ep_dequeue+0x66/0x250 drivers/usb/gadget/udc/core.c:330
raw_process_ep_io+0x5a3/0xaf0 drivers/usb/gadget/legacy/raw_gadget.c:1124
raw_ioctl_ep_write drivers/usb/gadget/legacy/raw_gadget.c:1152 [inline]
raw_ioctl+0x22dc/0x3ba0 drivers/usb/gadget/legacy/raw_gadget.c:1324
vfs_ioctl fs/ioctl.c:51 [inline]
__do_sys_ioctl fs/ioctl.c:598 [inline]
__se_sys_ioctl+0xfc/0x170 fs/ioctl.c:584
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xfa/0x3b0 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7f1608d4e7eb
Code: 00 48 89 44 24 18 31 c0 48 8d 44 24 60 c7 04 24 10 00 00 00 48 89 44 24 08 48 8d 44 24 20 48 89 44 24 10 b8 10 00 00 00 0f 05 <89> c2 3d 00 f0 ff ff 77 1c 48 8b 44 24 18 64 48 2b 04 25 28 00 00
RSP: 002b:00007ffdcd9fcf80 EFLAGS: 00000246 ORIG_RAX: 0000000000000010
RAX: ffffffffffffffda RBX: 0000000000000044 RCX: 00007f1608d4e7eb
RDX: 00007ffdcd9fd000 RSI: 0000000040085507 RDI: 0000000000000003
RBP: 0000000000000003 R08: 00007f16090a0320 R09: 0000000000000000
R10: 0000000000000003 R11: 0000000000000246 R12: 0000200000000080
R13: 000000000000000a R14: 00007f1608f75fa0 R15: 0000000000000004
</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.
If the report is already addressed, let syzbot know by replying with:
#syz fix: exact-commit-title
If you want syzbot to run the reproducer, reply with:
#syz test: git://repo/address.git branch-or-commit-hash
If you attach or paste a git patch, syzbot will apply it before testing.
If you want to overwrite report's subsystems, reply with:
#syz set subsystems: new-subsystem
(See the list of subsystem names on the web dashboard)
If the report is a duplicate of another one, reply with:
#syz dup: exact-subject-of-another-report
If you want to undo deduplication, reply with:
#syz undup
Quoted 5 lines
Date: Mon, 25 Aug 2025 01:51:29 -0700 [thread overview]
Hello,syzbot found the following issue on:
Quoted 8 lines
HEAD commit: 8d245acc1e88 Merge tag 'char-misc-6.17-rc3' of git://git.k.. git tree: upstream console output: https://syzkaller.appspot.com/x/log.txt?x=11e42062580000 kernel config: https://syzkaller.appspot.com/x/.config?x=e1e1566c7726877e dashboard link: https://syzkaller.appspot.com/bug?extid=8baacc4139f12fa77909 compiler: Debian clang version 20.1.7 (++20250616065708+6146a88f6049-1~exp1~20250616065826.132), Debian LLD 20.1.7 syz repro: https://syzkaller.appspot.com/x/repro.syz?x=13317062580000 C reproducer: https://syzkaller.appspot.com/x/repro.c?x=14d5ea34580000
#syz test
drivers/usb/gadget/udc/dummy_hcd.c +1 -2
@@ -765,8 +765,7 @@ static int dummy_dequeue(struct usb_ep *if (!dum->driver)return -ESHUTDOWN ; -local_irq_save (flags); -spin_lock (&dum->lock); +spin_lock_irqsave (&dum->lock, flags);list_for_each_entry (iter, &ep->queue, queue) {if (&iter->req != _req)continue ;
--
syzbot
syzbotsyzbot has tested the proposed patch but the reproducer is still triggering an issue: WARNING in dummy_dequeue
Hello,
syzbot has tested the proposed patch but the reproducer is still triggering an issue:
WARNING in dummy_dequeue
------------[ cut here ]------------
raw_local_irq_restore() called with IRQs enabled
WARNING: CPU: 0 PID: 6659 at kernel/locking/irqflag-debug.c:10 warn_bogus_irq_restore+0x2a/0x40 kernel/locking/irqflag-debug.c:10
Modules linked in:
CPU: 0 UID: 0 PID: 6659 Comm: syz.0.17 Not tainted syzkaller #0 PREEMPT_{RT,(full)}
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 07/12/2025
RIP: 0010:warn_bogus_irq_restore+0x2a/0x40 kernel/locking/irqflag-debug.c:10
Code: f3 0f 1e fa 90 80 3d 83 fb 10 04 00 74 07 90 c3 cc cc cc cc cc c6 05 73 fb 10 04 01 90 48 c7 c7 40 ee 0a 8b e8 d7 dc 8c f6 90 <0f> 0b 90 90 90 e9 cc ad 03 00 cc cc cc cc cc cc cc cc cc cc cc cc
RSP: 0018:ffffc900041378f8 EFLAGS: 00010246
RAX: 7b813d5b6b8f1700 RBX: 0000000000000000 RCX: ffff888036dc9dc0
RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000000000
RBP: ffffc900041379d8 R08: 0000000000000000 R09: 0000000000000000
R10: dffffc0000000000 R11: ffffed1017104863 R12: dffffc0000000000
R13: ffff8880374cde64 R14: 1ffff92000826f28 R15: 0000000000000200
FS: 00007f4ab96ee6c0(0000) GS:ffff8881268c2000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 0000001b34363fff CR3: 000000001da8c000 CR4: 00000000003526f0
Call Trace:
<TASK>
dummy_dequeue+0x2d7/0x3d0 drivers/usb/gadget/udc/dummy_hcd.c:786
usb_ep_dequeue+0x66/0x250 drivers/usb/gadget/udc/core.c:330
raw_process_ep_io+0x5a3/0xaf0 drivers/usb/gadget/legacy/raw_gadget.c:1124
raw_ioctl_ep_write drivers/usb/gadget/legacy/raw_gadget.c:1152 [inline]
raw_ioctl+0x22dc/0x3ba0 drivers/usb/gadget/legacy/raw_gadget.c:1324
vfs_ioctl fs/ioctl.c:51 [inline]
__do_sys_ioctl fs/ioctl.c:598 [inline]
__se_sys_ioctl+0xfc/0x170 fs/ioctl.c:584
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xfa/0x3b0 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7f4aba07e7eb
Code: 00 48 89 44 24 18 31 c0 48 8d 44 24 60 c7 04 24 10 00 00 00 48 89 44 24 08 48 8d 44 24 20 48 89 44 24 10 b8 10 00 00 00 0f 05 <89> c2 3d 00 f0 ff ff 77 1c 48 8b 44 24 18 64 48 2b 04 25 28 00 00
RSP: 002b:00007f4ab96ecf70 EFLAGS: 00000246 ORIG_RAX: 0000000000000010
RAX: ffffffffffffffda RBX: 0000000000000044 RCX: 00007f4aba07e7eb
RDX: 00007f4ab96ecff0 RSI: 0000000040085507 RDI: 0000000000000003
RBP: 0000000000000003 R08: 00007f4aba3d0320 R09: 0000000000000000
R10: 0000000000000003 R11: 0000000000000246 R12: 0000200000000080
R13: 000000000000000a R14: 00007f4aba2a5fa0 R15: 00007ffc6e132658
</TASK>Tested on:
commit: 1b237f19 Linux 6.17-rc3 git tree: upstream console output: https://syzkaller.appspot.com/x/log.txt?x=144a6862580000 kernel config: https://syzkaller.appspot.com/x/.config?x=e1e1566c7726877e dashboard link: https://syzkaller.appspot.com/bug?extid=8baacc4139f12fa77909 compiler: Debian clang version 20.1.7 (++20250616065708+6146a88f6049-1~exp1~20250616065826.132), Debian LLD 20.1.7 patch: https://syzkaller.appspot.com/x/patch.diff?x=174aec42580000
Quoted 21 lines · syzbot
Hello,
syzbot found the following issue on:
HEAD commit: 8d245acc1e88 Merge tag 'char-misc-6.17-rc3' of git://git.k.. git tree: upstream console output: https://syzkaller.appspot.com/x/log.txt?x=11e42062580000 kernel config: https://syzkaller.appspot.com/x/.config?x=e1e1566c7726877e dashboard link: https://syzkaller.appspot.com/bug?extid=8baacc4139f12fa77909 compiler: Debian clang version 20.1.7 (++20250616065708+6146a88f6049-1~exp1~20250616065826.132), Debian LLD 20.1.7 syz repro: https://syzkaller.appspot.com/x/repro.syz?x=13317062580000 C reproducer: https://syzkaller.appspot.com/x/repro.c?x=14d5ea34580000Downloadable assets:
disk image: https://storage.googleapis.com/syzbot-assets/096739d8f0ec/disk-8d245acc.raw.xz
vmlinux: https://storage.googleapis.com/syzbot-assets/83a21aa9b978/vmlinux-8d245acc.xz
kernel image: https://storage.googleapis.com/syzbot-assets/7e7f165a3b29/bzImage-8d245acc.xzIMPORTANT: if you fix the issue, please add the following tag to the commit:
Reported-by [email protected]
Quoted 7 lines
BUG: sleeping function called from invalid context at kernel/locking/spinlock_rt.c:48
in_atomic(): 0,irqs_disabled(): 1,non_block: 0, pid: 6118, name: syz.0.17preempt_count: 0, expected: 0
RCU nest depth: 0, expected: 0
1 lock held by syz.0.17/6118:
#0:ffff888144724058(&dum_hcd->dum->lock){+.+.}-{3:3}, at:spin_lockinclude/linux/spinlock_rt.h:44[inline] #0:ffff888144724058(&dum_hcd->dum->lock){+.+.}-{3:3}, at:dummy_dequeue+0x164/0x480drivers/usb/gadget/udc/dummy_hcd.c:769
Here's the solution that we settled on.
Alan Stern
#syz test: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/ 8d245acc1e88
drivers/usb/gadget/udc/dummy_hcd.c +4 -4
@@ -765,8 +765,7 @@ static int dummy_dequeue(struct usb_ep *if (!dum->driver)return -ESHUTDOWN ; -local_irq_save (flags); -spin_lock (&dum->lock); +spin_lock_irqsave (&dum->lock, flags);list_for_each_entry (iter, &ep->queue, queue) {if (&iter->req != _req)continue ;
@@ -776,15 +775,16 @@ static int dummy_dequeue(struct usb_ep * retval =0 ;break ; } -spin_unlock (&dum->lock);if (retval ==0 ) {dev_dbg (udc_dev (dum),"dequeued req %p from %s, len %d buf %p\n" , req, _ep->name, _req->length, _req->buf); +spin_unlock (&dum->lock);usb_gadget_giveback_request (_ep, _req); +spin_lock (&dum->lock); } -local_irq_restore (flags); +spin_unlock_irqrestore (&dum->lock, flags);return retval; }
syzbot 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: 8d245acc Merge tag 'char-misc-6.17-rc3' of git://git.k.. git tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/ console output: https://syzkaller.appspot.com/x/log.txt?x=17b38462580000 kernel config: https://syzkaller.appspot.com/x/.config?x=e1e1566c7726877e dashboard link: https://syzkaller.appspot.com/bug?extid=8baacc4139f12fa77909 compiler: Debian clang version 20.1.7 (++20250616065708+6146a88f6049-1~exp1~20250616065826.132), Debian LLD 20.1.7 patch: https://syzkaller.appspot.com/x/patch.diff?x=15ee6862580000
Note: testing is done by a robot and is best-effort only.
PATCH 1/1 USB: gadget: dummy-hcd: Fix locking bug in RT-enabled kernels
Yunseong Kim and the syzbot fuzzer both reported a problem in RT-enabled kernels caused by the way dummy-hcd mixes interrupt management and spin-locking. The pattern was:
local_irq_save(flags); spin_lock(&dum->lock); ... spin_unlock(&dum->lock); ... // calls usb_gadget_giveback_request() local_irq_restore(flags);
The code was written this way because usb_gadget_giveback_request() needs to be called with interrupts disabled and the private lock not held.
While this pattern works fine in non-RT kernels, it's not good when RT is enabled. RT kernels handle spinlocks much like mutexes; in particular, spin_lock() may sleep. But sleeping is not allowed while local interrupts are disabled.
To fix the problem, rewrite the code to conform to the pattern used elsewhere in dummy-hcd and other UDC drivers:
spin_lock_irqsave(&dum->lock, flags); ... spin_unlock(&dum->lock); usb_gadget_giveback_request(...); spin_lock(&dum->lock); ... spin_unlock_irqrestore(&dum->lock, flags);
This approach satisfies the RT requirements.
---
drivers/usb/gadget/udc/dummy_hcd.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/usb/gadget/udc/dummy_hcd.c +4 -4
@@ -765,8 +765,7 @@ static int dummy_dequeue(struct usb_ep *if (!dum->driver)return -ESHUTDOWN ; -local_irq_save (flags); -spin_lock (&dum->lock); +spin_lock_irqsave (&dum->lock, flags);list_for_each_entry (iter, &ep->queue, queue) {if (&iter->req != _req)continue ;
@@ -776,15 +775,16 @@ static int dummy_dequeue(struct usb_ep * retval =0 ;break ; } -spin_unlock (&dum->lock);if (retval ==0 ) {dev_dbg (udc_dev (dum),"dequeued req %p from %s, len %d buf %p\n" , req, _ep->name, _req->length, _req->buf); +spin_unlock (&dum->lock);usb_gadget_giveback_request (_ep, _req); +spin_lock (&dum->lock); } -local_irq_restore (flags); +spin_unlock_irqrestore (&dum->lock, flags);return retval; }
Re: [PATCH] USB: gadget: dummy-hcd: Fix locking bug in RT-enabled kernels
Quoted 9 lines · Alan Stern
Signed-off-by Alan Stern <[email protected]>Fixes b4dbda1a22d2 ("USB: dummy-hcd: disable interrupts during req->complete")Reported-by Yunseong Kim <[email protected]>Reported-by [email protected]Tested-by [email protected]CC Sebastian Andrzej Siewior <[email protected]>CC <[email protected]>
Thank you Alan.
Sebastian
Quoted 5 lines
Date: Mon, 25 Aug 2025 01:51:29 -0700 [thread overview]
Hello,syzbot found the following issue on:
Quoted 8 lines
HEAD commit: 8d245acc1e88 Merge tag 'char-misc-6.17-rc3' of git://git.k.. git tree: upstream console output: https://syzkaller.appspot.com/x/log.txt?x=11e42062580000 kernel config: https://syzkaller.appspot.com/x/.config?x=e1e1566c7726877e dashboard link: https://syzkaller.appspot.com/bug?extid=8baacc4139f12fa77909 compiler: Debian clang version 20.1.7 (++20250616065708+6146a88f6049-1~exp1~20250616065826.132), Debian LLD 20.1.7 syz repro: https://syzkaller.appspot.com/x/repro.syz?x=13317062580000 C reproducer: https://syzkaller.appspot.com/x/repro.c?x=14d5ea34580000
#syz test
drivers/usb/gadget/udc/dummy_hcd.c +4 -3
@@ -765,8 +765,7 @@ static int dummy_dequeue(struct usb_ep *if (!dum->driver)return -ESHUTDOWN ; -local_irq_save (flags); -spin_lock (&dum->lock); +spin_lock_irqsave (&dum->lock, flags);list_for_each_entry (iter, &ep->queue, queue) {if (&iter->req != _req)continue ;
@@ -784,7 +783,9 @@ static int dummy_dequeue(struct usb_ep * req, _ep->name, _req->length, _req->buf);usb_gadget_giveback_request (_ep, _req); } -local_irq_restore (flags); +spin_lock (&dum->lock); +spin_unlock_irqrestore (&dum->lock, flags); +return retval; }
--
syzbot 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: fab1beda Merge tag 'devicetree-fixes-for-6.17-1' of gi.. git tree: upstream console output: https://syzkaller.appspot.com/x/log.txt?x=15dbe862580000 kernel config: https://syzkaller.appspot.com/x/.config?x=e1e1566c7726877e dashboard link: https://syzkaller.appspot.com/bug?extid=8baacc4139f12fa77909 compiler: Debian clang version 20.1.7 (++20250616065708+6146a88f6049-1~exp1~20250616065826.132), Debian LLD 20.1.7 patch: https://syzkaller.appspot.com/x/patch.diff?x=141de862580000
Note: testing is done by a robot and is best-effort only.