syzbot


possible deadlock in iterate_dir (3)

Status: upstream: reported on 2025/09/14 06:44
Subsystems: btrfs
[Documentation on labels]
Reported-by: syzbot+e290013facb5d5159eca@syzkaller.appspotmail.com
First crash: 33d, last: 20d
Discussions (1)
Title Replies (including bot) Last reply
[syzbot] [btrfs?] possible deadlock in iterate_dir (3) 0 (1) 2025/09/14 06:44
Similar bugs (10)
Kernel Title Rank 🛈 Repro Cause bisect Fix bisect Count Last Reported Patched Status
linux-6.1 possible deadlock in iterate_dir (3) origin:lts-only 4 C error 7 10d 269d 0/3 upstream: reported C repro on 2025/01/16 11:46
linux-5.15 possible deadlock in iterate_dir (3) missing-backport origin:upstream 4 C error 20 77d 558d 0/3 upstream: reported C repro on 2024/04/03 07:56
upstream possible deadlock in iterate_dir (2) fs 4 1 283d 275d 0/29 auto-obsoleted due to no activity on 2025/04/12 17:38
linux-6.1 possible deadlock in iterate_dir (2) 4 2 536d 561d 0/3 auto-obsoleted due to no activity on 2024/08/02 17:42
linux-6.1 possible deadlock in iterate_dir 4 2 816d 822d 0/3 auto-obsoleted due to no activity on 2023/10/27 20:39
linux-4.14 possible deadlock in iterate_dir ubifs 4 C 11375 951d 1946d 0/1 upstream: reported C repro on 2020/06/15 06:16
linux-5.15 possible deadlock in iterate_dir (2) 4 2 683d 776d 0/3 auto-obsoleted due to no activity on 2024/03/08 13:21
linux-4.19 possible deadlock in iterate_dir 4 1 2117d 2117d 0/1 auto-closed as invalid on 2020/04/24 15:06
upstream possible deadlock in iterate_dir fs 4 23 781d 1023d 0/29 auto-obsoleted due to no activity on 2023/12/01 22:38
linux-5.15 possible deadlock in iterate_dir 4 1 930d 930d 0/3 auto-obsoleted due to no activity on 2023/07/25 13:55

Sample crash report:
======================================================
WARNING: possible circular locking dependency detected
syzkaller #0 Not tainted
------------------------------------------------------
syz.4.162/7186 is trying to acquire lock:
ffff88802b5a2410 (&mm->mmap_lock){++++}-{4:4}, at: mmap_read_lock_killable+0x1d/0x70 include/linux/mmap_lock.h:462

but task is already holding lock:
ffff88802ff7b538 (&type->i_mutex_dir_key#5){++++}-{4:4}, at: iterate_dir+0x29e/0x580 fs/readdir.c:101

which lock already depends on the new lock.


the existing dependency chain (in reverse order) is:

-> #7 (&type->i_mutex_dir_key#5){++++}-{4:4}:
       lock_acquire+0x120/0x360 kernel/locking/lockdep.c:5868
       down_read+0x97/0x1f0 kernel/locking/rwsem.c:1537
       inode_lock_shared include/linux/fs.h:885 [inline]
       lookup_slow+0x46/0x70 fs/namei.c:1824
       walk_component+0x2d2/0x400 fs/namei.c:2129
       lookup_last fs/namei.c:2630 [inline]
       path_lookupat+0x163/0x430 fs/namei.c:2654
       filename_lookup+0x212/0x570 fs/namei.c:2683
       kern_path+0x35/0x50 fs/namei.c:2816
       is_same_device fs/btrfs/volumes.c:759 [inline]
       device_list_add+0xe2a/0x22a0 fs/btrfs/volumes.c:894
       btrfs_scan_one_device+0x3ee/0x650 fs/btrfs/volumes.c:1493
       btrfs_get_tree_super fs/btrfs/super.c:1867 [inline]
       btrfs_get_tree_subvol fs/btrfs/super.c:2091 [inline]
       btrfs_get_tree+0x433/0x1820 fs/btrfs/super.c:2125
       vfs_get_tree+0x8f/0x2b0 fs/super.c:1815
       do_new_mount+0x2a2/0x9e0 fs/namespace.c:3808
       do_mount fs/namespace.c:4136 [inline]
       __do_sys_mount fs/namespace.c:4347 [inline]
       __se_sys_mount+0x317/0x410 fs/namespace.c:4324
       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

-> #6 (&fs_devs->device_list_mutex){+.+.}-{4:4}:
       lock_acquire+0x120/0x360 kernel/locking/lockdep.c:5868
       __mutex_lock_common kernel/locking/rtmutex_api.c:535 [inline]
       mutex_lock_nested+0x5a/0x1d0 kernel/locking/rtmutex_api.c:547
       btrfs_run_dev_stats+0x102/0x10e0 fs/btrfs/volumes.c:7777
       commit_cowonly_roots+0x1b2/0x860 fs/btrfs/transaction.c:1348
       btrfs_commit_transaction+0xfc7/0x3950 fs/btrfs/transaction.c:2462
       btrfs_rebuild_free_space_tree+0x285/0x760 fs/btrfs/free-space-tree.c:1384
       btrfs_start_pre_rw_mount+0x128f/0x1bf0 fs/btrfs/disk-io.c:3075
       open_ctree+0x293a/0x3a10 fs/btrfs/disk-io.c:3617
       btrfs_fill_super fs/btrfs/super.c:991 [inline]
       btrfs_get_tree_super fs/btrfs/super.c:1954 [inline]
       btrfs_get_tree_subvol fs/btrfs/super.c:2091 [inline]
       btrfs_get_tree+0xf55/0x1820 fs/btrfs/super.c:2125
       vfs_get_tree+0x8f/0x2b0 fs/super.c:1815
       do_new_mount+0x2a2/0x9e0 fs/namespace.c:3808
       do_mount fs/namespace.c:4136 [inline]
       __do_sys_mount fs/namespace.c:4347 [inline]
       __se_sys_mount+0x317/0x410 fs/namespace.c:4324
       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

-> #5 (&fs_info->reloc_mutex){+.+.}-{4:4}:
       lock_acquire+0x120/0x360 kernel/locking/lockdep.c:5868
       __mutex_lock_common kernel/locking/rtmutex_api.c:535 [inline]
       mutex_lock_nested+0x5a/0x1d0 kernel/locking/rtmutex_api.c:547
       btrfs_commit_transaction+0xedd/0x3950 fs/btrfs/transaction.c:2408
       btrfs_rebuild_free_space_tree+0x285/0x760 fs/btrfs/free-space-tree.c:1384
       btrfs_start_pre_rw_mount+0x128f/0x1bf0 fs/btrfs/disk-io.c:3075
       open_ctree+0x293a/0x3a10 fs/btrfs/disk-io.c:3617
       btrfs_fill_super fs/btrfs/super.c:991 [inline]
       btrfs_get_tree_super fs/btrfs/super.c:1954 [inline]
       btrfs_get_tree_subvol fs/btrfs/super.c:2091 [inline]
       btrfs_get_tree+0xf55/0x1820 fs/btrfs/super.c:2125
       vfs_get_tree+0x8f/0x2b0 fs/super.c:1815
       do_new_mount+0x2a2/0x9e0 fs/namespace.c:3808
       do_mount fs/namespace.c:4136 [inline]
       __do_sys_mount fs/namespace.c:4347 [inline]
       __se_sys_mount+0x317/0x410 fs/namespace.c:4324
       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

-> #4 (btrfs_trans_unblocked){++++}-{0:0}:
       lock_acquire+0x120/0x360 kernel/locking/lockdep.c:5868
       wait_current_trans+0x22b/0x520 fs/btrfs/transaction.c:531
       start_transaction+0x6a4/0x1620 fs/btrfs/transaction.c:702
       btrfs_create_common+0x145/0x230 fs/btrfs/inode.c:6758
       vfs_mknod+0x37f/0x3c0 fs/namei.c:4235
       do_mknodat+0x385/0x4d0 fs/namei.c:-1
       __do_sys_mknodat fs/namei.c:4313 [inline]
       __se_sys_mknodat fs/namei.c:4310 [inline]
       __x64_sys_mknodat+0xa7/0xc0 fs/namei.c:4310
       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

-> #3 (sb_internal#2){.+.+}-{0:0}:
       lock_acquire+0x120/0x360 kernel/locking/lockdep.c:5868
       percpu_down_read_internal include/linux/percpu-rwsem.h:53 [inline]
       percpu_down_read_freezable include/linux/percpu-rwsem.h:83 [inline]
       __sb_start_write include/linux/fs.h:1799 [inline]
       sb_start_intwrite include/linux/fs.h:1982 [inline]
       start_transaction+0x56e/0x1620 fs/btrfs/transaction.c:699
       btrfs_dirty_inode+0x9f/0x190 fs/btrfs/inode.c:6244
       inode_update_time fs/inode.c:2075 [inline]
       __file_update_time fs/inode.c:2304 [inline]
       file_update_time+0x34d/0x490 fs/inode.c:2334
       btrfs_page_mkwrite+0x5dd/0x1a80 fs/btrfs/file.c:1916
       do_page_mkwrite+0x14d/0x310 mm/memory.c:3361
       wp_page_shared mm/memory.c:3762 [inline]
       do_wp_page+0x25b8/0x4910 mm/memory.c:3981
       handle_pte_fault mm/memory.c:6068 [inline]
       __handle_mm_fault mm/memory.c:6195 [inline]
       handle_mm_fault+0x97c/0x3400 mm/memory.c:6364
       do_user_addr_fault+0xa81/0x1390 arch/x86/mm/fault.c:1336
       handle_page_fault arch/x86/mm/fault.c:1476 [inline]
       exc_page_fault+0x76/0xf0 arch/x86/mm/fault.c:1532
       asm_exc_page_fault+0x26/0x30 arch/x86/include/asm/idtentry.h:623

-> #2 (sb_pagefaults#3){.+.+}-{0:0}:
       lock_acquire+0x120/0x360 kernel/locking/lockdep.c:5868
       percpu_down_read_internal include/linux/percpu-rwsem.h:53 [inline]
       percpu_down_read_freezable include/linux/percpu-rwsem.h:83 [inline]
       __sb_start_write include/linux/fs.h:1799 [inline]
       sb_start_pagefault include/linux/fs.h:1964 [inline]
       btrfs_page_mkwrite+0x32c/0x1a80 fs/btrfs/file.c:1875
       do_page_mkwrite+0x14d/0x310 mm/memory.c:3361
       wp_page_shared mm/memory.c:3762 [inline]
       do_wp_page+0x25b8/0x4910 mm/memory.c:3981
       handle_pte_fault mm/memory.c:6068 [inline]
       __handle_mm_fault mm/memory.c:6195 [inline]
       handle_mm_fault+0x97c/0x3400 mm/memory.c:6364
       do_user_addr_fault+0xa81/0x1390 arch/x86/mm/fault.c:1336
       handle_page_fault arch/x86/mm/fault.c:1476 [inline]
       exc_page_fault+0x76/0xf0 arch/x86/mm/fault.c:1532
       asm_exc_page_fault+0x26/0x30 arch/x86/include/asm/idtentry.h:623

-> #1 (vm_lock){++++}-{0:0}:
       lock_acquire+0x120/0x360 kernel/locking/lockdep.c:5868
       __vma_enter_locked+0x182/0x380 mm/mmap_lock.c:63
       __vma_start_write+0x1e/0x120 mm/mmap_lock.c:87
       vma_start_write include/linux/mmap_lock.h:297 [inline]
       mprotect_fixup+0x578/0x9c0 mm/mprotect.c:828
       setup_arg_pages+0x53a/0xaa0 fs/exec.c:670
       load_elf_binary+0xbad/0x2750 fs/binfmt_elf.c:1013
       search_binary_handler fs/exec.c:1670 [inline]
       exec_binprm fs/exec.c:1702 [inline]
       bprm_execve+0x999/0x1450 fs/exec.c:1754
       kernel_execve+0x8f0/0x9f0 fs/exec.c:1920
       try_to_run_init_process+0x13/0x60 init/main.c:1397
       kernel_init+0xad/0x1d0 init/main.c:1525
       ret_from_fork+0x436/0x7d0 arch/x86/kernel/process.c:148
       ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:245

-> #0 (&mm->mmap_lock){++++}-{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
       down_read_killable+0x9d/0x220 kernel/locking/rwsem.c:1560
       mmap_read_lock_killable+0x1d/0x70 include/linux/mmap_lock.h:462
       get_mmap_lock_carefully mm/mmap_lock.c:286 [inline]
       lock_mm_and_find_vma+0x2a8/0x300 mm/mmap_lock.c:337
       do_user_addr_fault+0x331/0x1390 arch/x86/mm/fault.c:1359
       handle_page_fault arch/x86/mm/fault.c:1476 [inline]
       exc_page_fault+0x76/0xf0 arch/x86/mm/fault.c:1532
       asm_exc_page_fault+0x26/0x30 arch/x86/include/asm/idtentry.h:623
       filldir64+0x2c7/0x690 fs/readdir.c:-1
       dir_emit include/linux/fs.h:3959 [inline]
       offset_dir_emit fs/libfs.c:507 [inline]
       offset_iterate_dir fs/libfs.c:523 [inline]
       offset_readdir+0x44c/0x560 fs/libfs.c:572
       iterate_dir+0x3a5/0x580 fs/readdir.c:108
       __do_sys_getdents64 fs/readdir.c:410 [inline]
       __se_sys_getdents64+0xe4/0x260 fs/readdir.c:396
       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

other info that might help us debug this:

Chain exists of:
  &mm->mmap_lock --> &fs_devs->device_list_mutex --> &type->i_mutex_dir_key#5

 Possible unsafe locking scenario:

       CPU0                    CPU1
       ----                    ----
  rlock(&type->i_mutex_dir_key#5);
                               lock(&fs_devs->device_list_mutex);
                               lock(&type->i_mutex_dir_key#5);
  rlock(&mm->mmap_lock);

 *** DEADLOCK ***

2 locks held by syz.4.162/7186:
 #0: ffff888032437928 (&f->f_pos_lock){+.+.}-{4:4}, at: fdget_pos+0x253/0x320 fs/file.c:1232
 #1: ffff88802ff7b538 (&type->i_mutex_dir_key#5){++++}-{4:4}, at: iterate_dir+0x29e/0x580 fs/readdir.c:101

stack backtrace:
CPU: 1 UID: 0 PID: 7186 Comm: syz.4.162 Not tainted syzkaller #0 PREEMPT_{RT,(full)} 
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 08/18/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
 down_read_killable+0x9d/0x220 kernel/locking/rwsem.c:1560
 mmap_read_lock_killable+0x1d/0x70 include/linux/mmap_lock.h:462
 get_mmap_lock_carefully mm/mmap_lock.c:286 [inline]
 lock_mm_and_find_vma+0x2a8/0x300 mm/mmap_lock.c:337
 do_user_addr_fault+0x331/0x1390 arch/x86/mm/fault.c:1359
 handle_page_fault arch/x86/mm/fault.c:1476 [inline]
 exc_page_fault+0x76/0xf0 arch/x86/mm/fault.c:1532
 asm_exc_page_fault+0x26/0x30 arch/x86/include/asm/idtentry.h:623
RIP: 0010:filldir64+0x2c7/0x690 fs/readdir.c:379
Code: e8 48 8b 44 24 50 49 89 44 24 08 48 8b 4c 24 08 48 8b 44 24 58 48 89 01 48 8b 04 24 8b 54 24 14 49 bc 00 00 00 00 00 fc ff df <66> 89 41 10 80 e2 0f 88 51 12 49 63 ee c6 44 29 13 00 4c 8d 79 13
RSP: 0018:ffffc9000447fc90 EFLAGS: 00050283
RAX: 0000000000000020 RBX: ffffc9000447fe38 RCX: 0000200000000ff0
RDX: 000000000000000a RSI: 0000200000000fd0 RDI: 0000200000001010
RBP: 00007ffffffff000 R08: 0000000000000000 R09: 0000000000000000
R10: dffffc0000000000 R11: ffffed100602cb29 R12: dffffc0000000000
R13: ffff888025556c78 R14: 000000000000000a R15: 0000200000001010
 dir_emit include/linux/fs.h:3959 [inline]
 offset_dir_emit fs/libfs.c:507 [inline]
 offset_iterate_dir fs/libfs.c:523 [inline]
 offset_readdir+0x44c/0x560 fs/libfs.c:572
 iterate_dir+0x3a5/0x580 fs/readdir.c:108
 __do_sys_getdents64 fs/readdir.c:410 [inline]
 __se_sys_getdents64+0xe4/0x260 fs/readdir.c:396
 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:0x7f515310eec9
Code: ff ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 40 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 a8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007f5148f55038 EFLAGS: 00000246 ORIG_RAX: 00000000000000d9
RAX: ffffffffffffffda RBX: 00007f5153366090 RCX: 00007f515310eec9
RDX: 0000000000001000 RSI: 0000200000000f80 RDI: 0000000000000005
RBP: 00007f5153191f91 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
R13: 00007f5153366128 R14: 00007f5153366090 R15: 00007ffd8fae2238
 </TASK>
----------------
Code disassembly (best guess):
   0:	e8 48 8b 44 24       	call   0x24448b4d
   5:	50                   	push   %rax
   6:	49 89 44 24 08       	mov    %rax,0x8(%r12)
   b:	48 8b 4c 24 08       	mov    0x8(%rsp),%rcx
  10:	48 8b 44 24 58       	mov    0x58(%rsp),%rax
  15:	48 89 01             	mov    %rax,(%rcx)
  18:	48 8b 04 24          	mov    (%rsp),%rax
  1c:	8b 54 24 14          	mov    0x14(%rsp),%edx
  20:	49 bc 00 00 00 00 00 	movabs $0xdffffc0000000000,%r12
  27:	fc ff df
* 2a:	66 89 41 10          	mov    %ax,0x10(%rcx) <-- trapping instruction
  2e:	80 e2 0f             	and    $0xf,%dl
  31:	88 51 12             	mov    %dl,0x12(%rcx)
  34:	49 63 ee             	movslq %r14d,%rbp
  37:	c6 44 29 13 00       	movb   $0x0,0x13(%rcx,%rbp,1)
  3c:	4c 8d 79 13          	lea    0x13(%rcx),%r15

Crashes (5):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2025/09/22 18:52 upstream 07e27ad16399 0ac7291c .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-fs possible deadlock in iterate_dir
2025/09/19 18:36 upstream 097a6c336d00 67c37560 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-fs possible deadlock in iterate_dir
2025/09/16 18:34 upstream 46a51f4f5eda e2beed91 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-fs possible deadlock in iterate_dir
2025/09/15 23:32 upstream f83ec76bf285 e2beed91 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-fs possible deadlock in iterate_dir
2025/09/10 06:35 upstream 9dd1835ecda5 fdeaa69b .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-fs possible deadlock in iterate_dir
* Struck through repros no longer work on HEAD.