possible deadlock in dev_rescan_store

Status: upstream: reported C repro on 2026/08/14 01:38
Reported-by: syzbot+866d23e06942b587e560@syzkaller.appspotmail.com
First crash: 5d04h, last: 4d18h

Sample crash report:
======================================================
WARNING: possible circular locking dependency detected
syzkaller #0 Not tainted
------------------------------------------------------
syz.0.17/4357 is trying to acquire lock:
ffffffff8c95fde8 (pci_rescan_remove_lock){+.+.}-{3:3}, at: dev_rescan_store+0xc2/0x150 drivers/pci/pci-sysfs.c:476

but task is already holding lock:
ffff8881449f3bd0 (kn->active#495){++++}-{0:0}, at: kernfs_fop_write_iter+0x1fd/0x500 fs/kernfs/file.c:288

which lock already depends on the new lock.


the existing dependency chain (in reverse order) is:

-> #1 (kn->active#495){++++}-{0:0}:
       kernfs_drain fs/kernfs/dir.c:478 [inline]
       __kernfs_remove+0x5da/0xcb0 fs/kernfs/dir.c:1372
       kernfs_remove_by_name_ns+0x91/0x100 fs/kernfs/dir.c:1566
       kernfs_remove_by_name include/linux/kernfs.h:598 [inline]
       remove_files fs/sysfs/group.c:28 [inline]
       sysfs_remove_group+0xfd/0x290 fs/sysfs/group.c:289
       sysfs_remove_groups+0x50/0xa0 fs/sysfs/group.c:313
       device_remove_groups drivers/base/core.c:2498 [inline]
       device_remove_attrs+0xf1/0x140 drivers/base/core.c:2701
       device_del+0x637/0xa80 drivers/base/core.c:3614
       pci_destroy_dev drivers/pci/remove.c:36 [inline]
       pci_remove_bus_device+0x114/0x610 drivers/pci/remove.c:100
       pci_stop_and_remove_bus_device drivers/pci/remove.c:118 [inline]
       pci_stop_and_remove_bus_device_locked+0x1e/0x30 drivers/pci/remove.c:125
       remove_store+0xe2/0x140 drivers/pci/pci-sysfs.c:494
       kernfs_fop_write_iter+0x3a8/0x500 fs/kernfs/file.c:296
       call_write_iter include/linux/fs.h:2173 [inline]
       new_sync_write fs/read_write.c:507 [inline]
       vfs_write+0x748/0xd70 fs/read_write.c:594
       ksys_write+0x153/0x260 fs/read_write.c:647
       do_syscall_x64 arch/x86/entry/common.c:50 [inline]
       do_syscall_64+0x4c/0xa0 arch/x86/entry/common.c:80
       entry_SYSCALL_64_after_hwframe+0x66/0xd0

-> #0 (pci_rescan_remove_lock){+.+.}-{3:3}:
       check_prev_add kernel/locking/lockdep.c:3053 [inline]
       check_prevs_add kernel/locking/lockdep.c:3172 [inline]
       validate_chain kernel/locking/lockdep.c:3788 [inline]
       __lock_acquire+0x2c66/0x7b50 kernel/locking/lockdep.c:5012
       lock_acquire+0x19e/0x400 kernel/locking/lockdep.c:5623
       __mutex_lock_common+0x1e5/0x2400 kernel/locking/mutex.c:596
       __mutex_lock kernel/locking/mutex.c:729 [inline]
       mutex_lock_nested+0x17/0x20 kernel/locking/mutex.c:743
       dev_rescan_store+0xc2/0x150 drivers/pci/pci-sysfs.c:476
       kernfs_fop_write_iter+0x3a8/0x500 fs/kernfs/file.c:296
       call_write_iter include/linux/fs.h:2173 [inline]
       new_sync_write fs/read_write.c:507 [inline]
       vfs_write+0x748/0xd70 fs/read_write.c:594
       ksys_write+0x153/0x260 fs/read_write.c:647
       do_syscall_x64 arch/x86/entry/common.c:50 [inline]
       do_syscall_64+0x4c/0xa0 arch/x86/entry/common.c:80
       entry_SYSCALL_64_after_hwframe+0x66/0xd0

other info that might help us debug this:

 Possible unsafe locking scenario:

       CPU0                    CPU1
       ----                    ----
  lock(kn->active#495);
                               lock(pci_rescan_remove_lock);
                               lock(kn->active#495);
  lock(pci_rescan_remove_lock);

 *** DEADLOCK ***

3 locks held by syz.0.17/4357:
 #0: ffff888079afa460 (sb_writers#8){.+.+}-{0:0}, at: vfs_write+0x296/0xd70 fs/read_write.c:590
 #1: ffff888026209088 (&of->mutex){+.+.}-{3:3}, at: kernfs_fop_write_iter+0x1dc/0x500 fs/kernfs/file.c:287
 #2: ffff8881449f3bd0 (kn->active#495){++++}-{0:0}, at: kernfs_fop_write_iter+0x1fd/0x500 fs/kernfs/file.c:288

stack backtrace:
CPU: 0 PID: 4357 Comm: syz.0.17 Not tainted syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 07/24/2026
Call Trace:
 <TASK>
 dump_stack_lvl+0x188/0x250 lib/dump_stack.c:106
 check_noncircular+0x296/0x330 kernel/locking/lockdep.c:2133
 check_prev_add kernel/locking/lockdep.c:3053 [inline]
 check_prevs_add kernel/locking/lockdep.c:3172 [inline]
 validate_chain kernel/locking/lockdep.c:3788 [inline]
 __lock_acquire+0x2c66/0x7b50 kernel/locking/lockdep.c:5012
 lock_acquire+0x19e/0x400 kernel/locking/lockdep.c:5623
 __mutex_lock_common+0x1e5/0x2400 kernel/locking/mutex.c:596
 __mutex_lock kernel/locking/mutex.c:729 [inline]
 mutex_lock_nested+0x17/0x20 kernel/locking/mutex.c:743
 dev_rescan_store+0xc2/0x150 drivers/pci/pci-sysfs.c:476
 kernfs_fop_write_iter+0x3a8/0x500 fs/kernfs/file.c:296
 call_write_iter include/linux/fs.h:2173 [inline]
 new_sync_write fs/read_write.c:507 [inline]
 vfs_write+0x748/0xd70 fs/read_write.c:594
 ksys_write+0x153/0x260 fs/read_write.c:647
 do_syscall_x64 arch/x86/entry/common.c:50 [inline]
 do_syscall_64+0x4c/0xa0 arch/x86/entry/common.c:80
 entry_SYSCALL_64_after_hwframe+0x66/0xd0
RIP: 0033:0x7fe9ef1160d9
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:00007fff167b3cc8 EFLAGS: 00000246 ORIG_RAX: 0000000000000001
RAX: ffffffffffffffda RBX: 00007fe9ef39dfa0 RCX: 00007fe9ef1160d9
RDX: 0000000000000001 RSI: 0000200000000300 RDI: 0000000000000004
RBP: 00007fe9ef1ad024 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
R13: 00007fe9ef39dfac R14: 00007fe9ef39dfa0 R15: 00007fe9ef39dfa0
 </TASK>
pci 0000:00:01.0: [8086:7110] type 00 class 0x060100

Crashes (4):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2026/08/14 10:49 linux-5.15.y aabd761612db b13552fe .config console log report syz / log C [disk image] [vmlinux] [kernel image] ci2-linux-5-15-kasan possible deadlock in dev_rescan_store
2026/08/14 08:18 linux-5.15.y aabd761612db b13552fe .config console log report syz / log C [disk image] [vmlinux] [kernel image] ci2-linux-5-15-kasan possible deadlock in dev_rescan_store
2026/08/14 06:11 linux-5.15.y aabd761612db b13552fe .config console log report syz / log C [disk image] [vmlinux] [kernel image] ci2-linux-5-15-kasan possible deadlock in dev_rescan_store
2026/08/14 01:38 linux-5.15.y aabd761612db b13552fe .config console log report info [disk image] [vmlinux] [kernel image] ci2-linux-5-15-kasan possible deadlock in dev_rescan_store
* Struck through repros no longer work on HEAD.