Kernel bug: possible deadlock in input_ff_flush
Subsystem: input
Status: open

Crash report:
======================================================
WARNING: possible circular locking dependency detected
syzkaller #0 Not tainted
------------------------------------------------------
udevd/5949 is trying to acquire lock:
ffff888026fa88b0 (&ff->mutex){+.+.}-{4:4}, at: class_mutex_constructor include/linux/mutex.h:228 [inline]
ffff888026fa88b0 (&ff->mutex){+.+.}-{4:4}, at: input_ff_flush+0x5d/0x170 drivers/input/ff-core.c:231

but task is already holding lock:
ffff888026bfb2c0 (&dev->mutex#2){+.+.}-{4:4}, at: class_mutex_intr_constructor include/linux/mutex.h:230 [inline]
ffff888026bfb2c0 (&dev->mutex#2){+.+.}-{4:4}, at: input_flush_device+0x51/0x110 drivers/input/input.c:626

which lock already depends on the new lock.


the existing dependency chain (in reverse order) is:

-> #3 (&dev->mutex#2){+.+.}-{4:4}:
       lock_acquire+0x120/0x360 kernel/locking/lockdep.c:5868
       __mutex_lock_common kernel/locking/mutex.c:598 [inline]
       __mutex_lock+0x187/0x1350 kernel/locking/mutex.c:760
       class_mutex_intr_constructor include/linux/mutex.h:230 [inline]
       input_register_handle+0x18f/0x530 drivers/input/input.c:2619
       kbd_connect+0xc3/0x140 drivers/tty/vt/keyboard.c:1580
       input_attach_handler drivers/input/input.c:994 [inline]
       input_register_device+0xd00/0x1140 drivers/input/input.c:2378
       acpi_button_add+0x6b1/0xb50 drivers/acpi/button.c:621
       acpi_device_probe+0xa8/0x2d0 drivers/acpi/bus.c:1076
       call_driver_probe drivers/base/dd.c:-1 [inline]
       really_probe+0x26d/0x9e0 drivers/base/dd.c:659
       __driver_probe_device+0x18c/0x2f0 drivers/base/dd.c:801
       driver_probe_device+0x4f/0x430 drivers/base/dd.c:831
       __driver_attach+0x452/0x700 drivers/base/dd.c:1217
       bus_for_each_dev+0x233/0x2b0 drivers/base/bus.c:370
       bus_add_driver+0x345/0x640 drivers/base/bus.c:678
       driver_register+0x23a/0x320 drivers/base/driver.c:249
       do_one_initcall+0x236/0x820 init/main.c:1283
       do_initcall_level+0x104/0x190 init/main.c:1345
       do_initcalls+0x59/0xa0 init/main.c:1361
       kernel_init_freeable+0x334/0x4b0 init/main.c:1593
       kernel_init+0x1d/0x1d0 init/main.c:1483
       ret_from_fork+0x4bc/0x870 arch/x86/kernel/process.c:158
       ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:245

-> #2 (input_mutex){+.+.}-{4:4}:
       lock_acquire+0x120/0x360 kernel/locking/lockdep.c:5868
       __mutex_lock_common kernel/locking/mutex.c:598 [inline]
       __mutex_lock+0x187/0x1350 kernel/locking/mutex.c:760
       class_mutex_intr_constructor include/linux/mutex.h:230 [inline]
       input_register_device+0xa76/0x1140 drivers/input/input.c:2374
       uinput_create_device+0x422/0x670 drivers/input/misc/uinput.c:365
       uinput_ioctl_handler+0x3f0/0x1570 drivers/input/misc/uinput.c:919
       vfs_ioctl fs/ioctl.c:51 [inline]
       __do_sys_ioctl fs/ioctl.c:597 [inline]
       __se_sys_ioctl+0xfc/0x170 fs/ioctl.c:583
       do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
       do_syscall_64+0xfa/0xfa0 arch/x86/entry/syscall_64.c:94
       entry_SYSCALL_64_after_hwframe+0x77/0x7f

-> #1 (&newdev->mutex){+.+.}-{4:4}:
       lock_acquire+0x120/0x360 kernel/locking/lockdep.c:5868
       __mutex_lock_common kernel/locking/mutex.c:598 [inline]
       __mutex_lock+0x187/0x1350 kernel/locking/mutex.c:760
       uinput_request_send drivers/input/misc/uinput.c:151 [inline]
       uinput_request_submit+0x188/0x6f0 drivers/input/misc/uinput.c:182
       uinput_dev_upload_effect+0x150/0x1e0 drivers/input/misc/uinput.c:257
       input_ff_upload+0x5fb/0xb30 drivers/input/ff-core.c:148
       evdev_do_ioctl drivers/input/evdev.c:1181 [inline]
       evdev_ioctl_handler+0x1644/0x1f10 drivers/input/evdev.c:1270
       vfs_ioctl fs/ioctl.c:51 [inline]
       __do_sys_ioctl fs/ioctl.c:597 [inline]
       __se_sys_ioctl+0xfc/0x170 fs/ioctl.c:583
       do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
       do_syscall_64+0xfa/0xfa0 arch/x86/entry/syscall_64.c:94
       entry_SYSCALL_64_after_hwframe+0x77/0x7f

-> #0 (&ff->mutex){+.+.}-{4:4}:
       check_prev_add kernel/locking/lockdep.c:3165 [inline]
       check_prevs_add kernel/locking/lockdep.c:3284 [inline]
       validate_chain+0xb9b/0x2140 kernel/locking/lockdep.c:3908
       __lock_acquire+0xab9/0xd20 kernel/locking/lockdep.c:5237
       lock_acquire+0x120/0x360 kernel/locking/lockdep.c:5868
       __mutex_lock_common kernel/locking/mutex.c:598 [inline]
       __mutex_lock+0x187/0x1350 kernel/locking/mutex.c:760
       class_mutex_constructor include/linux/mutex.h:228 [inline]
       input_ff_flush+0x5d/0x170 drivers/input/ff-core.c:231
       input_flush_device+0xb4/0x110 drivers/input/input.c:628
       evdev_release+0xe1/0x800 drivers/input/evdev.c:435
       __fput+0x44c/0xa70 fs/file_table.c:468
       fput_close_sync+0x119/0x200 fs/file_table.c:573
       __do_sys_close fs/open.c:1589 [inline]
       __se_sys_close fs/open.c:1574 [inline]
       __x64_sys_close+0x7f/0x110 fs/open.c:1574
       do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
       do_syscall_64+0xfa/0xfa0 arch/x86/entry/syscall_64.c:94
       entry_SYSCALL_64_after_hwframe+0x77/0x7f

other info that might help us debug this:

Chain exists of:
  &ff->mutex --> input_mutex --> &dev->mutex#2

 Possible unsafe locking scenario:

       CPU0                    CPU1
       ----                    ----
  lock(&dev->mutex#2);
                               lock(input_mutex);
                               lock(&dev->mutex#2);
  lock(&ff->mutex);

 *** DEADLOCK ***

2 locks held by udevd/5949:
 #0: ffff88823bfe4118 (&evdev->mutex){+.+.}-{4:4}, at: evdev_release+0x73/0x800 drivers/input/evdev.c:432
 #1: ffff888026bfb2c0 (&dev->mutex#2){+.+.}-{4:4}, at: class_mutex_intr_constructor include/linux/mutex.h:230 [inline]
 #1: ffff888026bfb2c0 (&dev->mutex#2){+.+.}-{4:4}, at: input_flush_device+0x51/0x110 drivers/input/input.c:626

stack backtrace:
CPU: 0 UID: 0 PID: 5949 Comm: udevd Not tainted syzkaller #0 PREEMPT(full) 
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 10/02/2025
Call Trace:
 <TASK>
 dump_stack_lvl+0x189/0x250 lib/dump_stack.c:120
 print_circular_bug+0x2ee/0x310 kernel/locking/lockdep.c:2043
 check_noncircular+0x134/0x160 kernel/locking/lockdep.c:2175
 check_prev_add kernel/locking/lockdep.c:3165 [inline]
 check_prevs_add kernel/locking/lockdep.c:3284 [inline]
 validate_chain+0xb9b/0x2140 kernel/locking/lockdep.c:3908
 __lock_acquire+0xab9/0xd20 kernel/locking/lockdep.c:5237
 lock_acquire+0x120/0x360 kernel/locking/lockdep.c:5868
 __mutex_lock_common kernel/locking/mutex.c:598 [inline]
 __mutex_lock+0x187/0x1350 kernel/locking/mutex.c:760
 class_mutex_constructor include/linux/mutex.h:228 [inline]
 input_ff_flush+0x5d/0x170 drivers/input/ff-core.c:231
 input_flush_device+0xb4/0x110 drivers/input/input.c:628
 evdev_release+0xe1/0x800 drivers/input/evdev.c:435
 __fput+0x44c/0xa70 fs/file_table.c:468
 fput_close_sync+0x119/0x200 fs/file_table.c:573
 __do_sys_close fs/open.c:1589 [inline]
 __se_sys_close fs/open.c:1574 [inline]
 __x64_sys_close+0x7f/0x110 fs/open.c:1574
 do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
 do_syscall_64+0xfa/0xfa0 arch/x86/entry/syscall_64.c:94
 entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7fc6f9aa7407
Code: 48 89 fa 4c 89 df e8 38 aa 00 00 8b 93 08 03 00 00 59 5e 48 83 f8 fc 74 1a 5b c3 0f 1f 84 00 00 00 00 00 48 8b 44 24 10 0f 05 <5b> c3 0f 1f 80 00 00 00 00 83 e2 39 83 fa 08 75 de e8 23 ff ff ff
RSP: 002b:00007fff016cd120 EFLAGS: 00000202 ORIG_RAX: 0000000000000003
RAX: ffffffffffffffda RBX: 00007fc6fa17d880 RCX: 00007fc6f9aa7407
RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000000008
RBP: 00007fc6fa17d6e8 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000202 R12: 0000000000000016
R13: 00007fff016cd230 R14: 0000000000000000 R15: 0000000000000000
 </TASK>