possible deadlock in __kernfs_remove

Status: upstream: reported on 2026/08/25 23:30
Reported-by: syzbot+5d0375cf2b154b77a075@syzkaller.appspotmail.com
First crash: 4d16h, last: 4d16h
Similar bugs (4)
Kernel Title Rank 🛈 Repro Cause bisect Fix bisect Count Last Reported Patched Status
upstream possible deadlock in __kernfs_remove (3) prio:high input 4 syz, C 110 1h45m 185d 0/29 upstream: reported C repro on 2026/02/26 06:07
linux-6.1 possible deadlock in __kernfs_remove 4 syz, C 4 5d00h 8d18h 0/3 upstream: reported C repro on 2026/08/21 21:40
upstream possible deadlock in __kernfs_remove kernfs 4 syz, C 438 753d 796d 28/29 fixed on 2024/10/03 15:25
upstream possible deadlock in __kernfs_remove (2) kernfs 4 syz, C 4976 492d 660d 0/29 auto-obsoleted due to no activity on 2025/07/04 15:33

Sample crash report:
======================================================
WARNING: possible circular locking dependency detected
syzkaller #0 Not tainted
------------------------------------------------------
syz.4.3764/17972 is trying to acquire lock:
ffff88801bb32e90 (kn->active#79){++++}-{0:0}, at: __kernfs_remove+0x426/0x830 fs/kernfs/dir.c:1486

but task is already holding lock:
ffffffff8de922a8 (serio_mutex){+.+.}-{3:3}, at: serio_unregister_port+0x2f/0x150 drivers/input/serio/serio.c:704

which lock already depends on the new lock.


the existing dependency chain (in reverse order) is:

-> #1 (serio_mutex){+.+.}-{3:3}:
       __mutex_lock_common kernel/locking/mutex.c:603 [inline]
       __mutex_lock+0x135/0xc80 kernel/locking/mutex.c:747
       drvctl_store+0x2e/0xae0 drivers/input/serio/serio.c:385
       kernfs_fop_write_iter+0x3a4/0x520 fs/kernfs/file.c:352
       call_write_iter include/linux/fs.h:2018 [inline]
       new_sync_write fs/read_write.c:491 [inline]
       vfs_write+0x474/0x9a0 fs/read_write.c:584
       ksys_write+0x151/0x260 fs/read_write.c:637
       do_syscall_x64 arch/x86/entry/common.c:46 [inline]
       do_syscall_64+0x55/0xb0 arch/x86/entry/common.c:76
       entry_SYSCALL_64_after_hwframe+0x68/0xd2

-> #0 (kn->active#79){++++}-{0:0}:
       check_prev_add kernel/locking/lockdep.c:3134 [inline]
       check_prevs_add kernel/locking/lockdep.c:3253 [inline]
       validate_chain kernel/locking/lockdep.c:3869 [inline]
       __lock_acquire+0x37ef/0x7d80 kernel/locking/lockdep.c:5137
       lock_acquire+0x19e/0x420 kernel/locking/lockdep.c:5754
       kernfs_drain+0x31e/0x6d0 fs/kernfs/dir.c:500
       __kernfs_remove+0x426/0x830 fs/kernfs/dir.c:1486
       kernfs_remove_by_name_ns+0xdc/0x150 fs/kernfs/dir.c:1695
       kernfs_remove_by_name include/linux/kernfs.h:624 [inline]
       remove_files fs/sysfs/group.c:28 [inline]
       sysfs_remove_group+0x101/0x290 fs/sysfs/group.c:292
       sysfs_remove_groups+0x54/0xa0 fs/sysfs/group.c:316
       device_remove_groups drivers/base/core.c:2793 [inline]
       device_remove_attrs+0x1cc/0x280 drivers/base/core.c:2968
       device_del+0x517/0x910 drivers/base/core.c:3888
       serio_destroy_port+0x34a/0x470 drivers/input/serio/serio.c:570
       serio_unregister_port+0x130/0x150 drivers/input/serio/serio.c:706
       userio_char_release+0x83/0xc0 drivers/input/serio/userio.c:111
       __fput+0x221/0x940 fs/file_table.c:418
       task_work_run+0x1d4/0x260 kernel/task_work.c:245
       resume_user_mode_work include/linux/resume_user_mode.h:49 [inline]
       exit_to_user_mode_loop+0xe6/0x110 kernel/entry/common.c:177
       exit_to_user_mode_prepare+0xee/0x180 kernel/entry/common.c:210
       __syscall_exit_to_user_mode_work kernel/entry/common.c:291 [inline]
       syscall_exit_to_user_mode+0x1a/0x50 kernel/entry/common.c:302
       do_syscall_64+0x61/0xb0 arch/x86/entry/common.c:82
       entry_SYSCALL_64_after_hwframe+0x68/0xd2

other info that might help us debug this:

 Possible unsafe locking scenario:

       CPU0                    CPU1
       ----                    ----
  lock(serio_mutex);
                               lock(kn->active#79);
                               lock(serio_mutex);
  lock(kn->active#79);

 *** DEADLOCK ***

1 lock held by syz.4.3764/17972:
 #0: ffffffff8de922a8 (serio_mutex){+.+.}-{3:3}, at: serio_unregister_port+0x2f/0x150 drivers/input/serio/serio.c:704

stack backtrace:
CPU: 0 PID: 17972 Comm: syz.4.3764 Not tainted syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 07/24/2026
Call Trace:
 <TASK>
 dump_stack_lvl+0x18c/0x250 lib/dump_stack.c:106
 check_noncircular+0x2fc/0x400 kernel/locking/lockdep.c:2187
 check_prev_add kernel/locking/lockdep.c:3134 [inline]
 check_prevs_add kernel/locking/lockdep.c:3253 [inline]
 validate_chain kernel/locking/lockdep.c:3869 [inline]
 __lock_acquire+0x37ef/0x7d80 kernel/locking/lockdep.c:5137
 lock_acquire+0x19e/0x420 kernel/locking/lockdep.c:5754
 kernfs_drain+0x31e/0x6d0 fs/kernfs/dir.c:500
 __kernfs_remove+0x426/0x830 fs/kernfs/dir.c:1486
 kernfs_remove_by_name_ns+0xdc/0x150 fs/kernfs/dir.c:1695
 kernfs_remove_by_name include/linux/kernfs.h:624 [inline]
 remove_files fs/sysfs/group.c:28 [inline]
 sysfs_remove_group+0x101/0x290 fs/sysfs/group.c:292
 sysfs_remove_groups+0x54/0xa0 fs/sysfs/group.c:316
 device_remove_groups drivers/base/core.c:2793 [inline]
 device_remove_attrs+0x1cc/0x280 drivers/base/core.c:2968
 device_del+0x517/0x910 drivers/base/core.c:3888
 serio_destroy_port+0x34a/0x470 drivers/input/serio/serio.c:570
 serio_unregister_port+0x130/0x150 drivers/input/serio/serio.c:706
 userio_char_release+0x83/0xc0 drivers/input/serio/userio.c:111
 __fput+0x221/0x940 fs/file_table.c:418
 task_work_run+0x1d4/0x260 kernel/task_work.c:245
 resume_user_mode_work include/linux/resume_user_mode.h:49 [inline]
 exit_to_user_mode_loop+0xe6/0x110 kernel/entry/common.c:177
 exit_to_user_mode_prepare+0xee/0x180 kernel/entry/common.c:210
 __syscall_exit_to_user_mode_work kernel/entry/common.c:291 [inline]
 syscall_exit_to_user_mode+0x1a/0x50 kernel/entry/common.c:302
 do_syscall_64+0x61/0xb0 arch/x86/entry/common.c:82
 entry_SYSCALL_64_after_hwframe+0x68/0xd2
RIP: 0033:0x7f96a479e0d9
Code: ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 44 00 00 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 e8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007fff4bf0faf8 EFLAGS: 00000246 ORIG_RAX: 00000000000001b4
RAX: 0000000000000000 RBX: 00007f96a4a27da0 RCX: 00007f96a479e0d9
RDX: 0000000000000000 RSI: 000000000000001e RDI: 0000000000000003
RBP: 00007f96a4a27da0 R08: 0000000000000006 R09: 0000000000000000
R10: 00007f96a4a27cb0 R11: 0000000000000246 R12: 00000000000daee1
R13: 00007f96a4a2618c R14: 00000000000dae83 R15: 00007f96a4a26180
 </TASK>

Crashes (2):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2026/08/25 23:29 linux-6.6.y dc6160265ffc a9a1fc32 .config console log report info [disk image] [vmlinux] [kernel image] ci2-linux-6-6-kasan possible deadlock in __kernfs_remove
2026/08/25 23:29 linux-6.6.y dc6160265ffc a9a1fc32 .config console log report info [disk image] [vmlinux] [kernel image] ci2-linux-6-6-kasan possible deadlock in __kernfs_remove
* Struck through repros no longer work on HEAD.