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: 87d, last: 13d
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 inconclusive 7 64d 324d 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 131d 612d 0/3 upstream: reported C repro on 2024/04/03 07:56
upstream possible deadlock in iterate_dir (2) fs 4 1 337d 330d 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 590d 616d 0/3 auto-obsoleted due to no activity on 2024/08/02 17:42
linux-6.1 possible deadlock in iterate_dir 4 2 870d 876d 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 1005d 2000d 0/1 upstream: reported C repro on 2020/06/15 06:16
linux-5.15 possible deadlock in iterate_dir (2) 4 2 738d 830d 0/3 auto-obsoleted due to no activity on 2024/03/08 13:21
linux-4.19 possible deadlock in iterate_dir 4 1 2172d 2172d 0/1 auto-closed as invalid on 2020/04/24 15:06
upstream possible deadlock in iterate_dir fs 4 23 835d 1078d 0/29 auto-obsoleted due to no activity on 2023/12/01 22:38
linux-5.15 possible deadlock in iterate_dir 4 1 985d 985d 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.1.8342/8264 is trying to acquire lock:
ffff88807799d7e0 (&mm->mmap_lock){++++}-{4:4}, at: mmap_read_lock_killable+0x1d/0x70 include/linux/mmap_lock.h:377

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

which lock already depends on the new lock.


the existing dependency chain (in reverse order) is:

-> #4 (&type->i_mutex_dir_key#5){++++}-{4:4}:
       lock_acquire+0x120/0x360 kernel/locking/lockdep.c:5868
       down_read+0x46/0x2e0 kernel/locking/rwsem.c:1537
       inode_lock_shared include/linux/fs.h:995 [inline]
       lookup_slow+0x46/0x70 fs/namei.c:1832
       walk_component+0x2d2/0x400 fs/namei.c:2151
       lookup_last fs/namei.c:2652 [inline]
       path_lookupat+0x163/0x430 fs/namei.c:2676
       filename_lookup+0x212/0x570 fs/namei.c:2705
       kern_path+0x35/0x50 fs/namei.c:2863
       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:1865 [inline]
       btrfs_get_tree_subvol fs/btrfs/super.c:2094 [inline]
       btrfs_get_tree+0x4ab/0x1920 fs/btrfs/super.c:2128
       vfs_get_tree+0x92/0x2b0 fs/super.c:1758
       fc_mount fs/namespace.c:1199 [inline]
       do_new_mount_fc fs/namespace.c:3642 [inline]
       do_new_mount+0x302/0xa10 fs/namespace.c:3718
       do_mount fs/namespace.c:4041 [inline]
       __do_sys_mount fs/namespace.c:4229 [inline]
       __se_sys_mount+0x313/0x410 fs/namespace.c:4206
       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

-> #3 (&fs_devs->device_list_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
       insert_dev_extents fs/btrfs/block-group.c:2754 [inline]
       btrfs_create_pending_block_groups+0x5f8/0x1780 fs/btrfs/block-group.c:2805
       __btrfs_end_transaction+0x140/0x640 fs/btrfs/transaction.c:1071
       flush_space+0x315/0xcd0 fs/btrfs/space-info.c:865
       do_async_reclaim_metadata_space+0x144/0x390 fs/btrfs/space-info.c:1158
       btrfs_async_reclaim_metadata_space+0x89/0xe0 fs/btrfs/space-info.c:1226
       process_one_work kernel/workqueue.c:3263 [inline]
       process_scheduled_works+0xae1/0x17b0 kernel/workqueue.c:3346
       worker_thread+0x8a0/0xda0 kernel/workqueue.c:3427
       kthread+0x711/0x8a0 kernel/kthread.c:463
       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 (btrfs_trans_num_extwriters){++++}-{0:0}:
       lock_acquire+0x120/0x360 kernel/locking/lockdep.c:5868
       join_transaction+0x1a4/0xd70 fs/btrfs/transaction.c:321
       start_transaction+0x6b6/0x1620 fs/btrfs/transaction.c:705
       btrfs_setxattr_trans+0xcc/0x380 fs/btrfs/xattr.c:240
       __vfs_setxattr+0x43c/0x480 fs/xattr.c:200
       __vfs_setxattr_noperm+0x12d/0x660 fs/xattr.c:234
       vfs_setxattr+0x16b/0x2f0 fs/xattr.c:321
       do_setxattr fs/xattr.c:636 [inline]
       filename_setxattr+0x274/0x600 fs/xattr.c:665
       path_setxattrat+0x364/0x3a0 fs/xattr.c:713
       __do_sys_setxattr fs/xattr.c:747 [inline]
       __se_sys_setxattr fs/xattr.c:743 [inline]
       __x64_sys_setxattr+0xbc/0xe0 fs/xattr.c:743
       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 (btrfs_trans_num_writers){++++}-{0:0}:
       reacquire_held_locks+0x127/0x1d0 kernel/locking/lockdep.c:5385
       __lock_release kernel/locking/lockdep.c:5574 [inline]
       lock_release+0x1b4/0x3e0 kernel/locking/lockdep.c:5889
       percpu_up_read include/linux/percpu-rwsem.h:112 [inline]
       __sb_end_write include/linux/fs.h:1911 [inline]
       sb_end_intwrite+0x26/0x1c0 include/linux/fs.h:2028
       __btrfs_end_transaction+0x248/0x640 fs/btrfs/transaction.c:1076
       btrfs_dirty_inode+0x14c/0x190 fs/btrfs/inode.c:6286
       inode_update_time fs/inode.c:2129 [inline]
       touch_atime+0x2f9/0x6d0 fs/inode.c:2202
       file_accessed include/linux/fs.h:2673 [inline]
       btrfs_file_mmap_prepare+0xd5/0x140 fs/btrfs/file.c:2049
       vfs_mmap_prepare include/linux/fs.h:2410 [inline]
       call_mmap_prepare mm/vma.c:2586 [inline]
       __mmap_region mm/vma.c:2654 [inline]
       mmap_region+0xb47/0x2110 mm/vma.c:2740
       do_mmap+0xc45/0x10d0 mm/mmap.c:558
       vm_mmap_pgoff+0x2a6/0x4d0 mm/util.c:581
       ksys_mmap_pgoff+0x51f/0x760 mm/mmap.c:604
       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 (&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+0x50/0x350 kernel/locking/rwsem.c:1560
       mmap_read_lock_killable+0x1d/0x70 include/linux/mmap_lock.h:377
       get_mmap_lock_carefully mm/mmap_lock.c:377 [inline]
       lock_mm_and_find_vma+0x2a8/0x300 mm/mmap_lock.c:428
       do_user_addr_fault+0x331/0x1380 arch/x86/mm/fault.c:1359
       handle_page_fault arch/x86/mm/fault.c:1476 [inline]
       exc_page_fault+0x82/0x100 arch/x86/mm/fault.c:1532
       asm_exc_page_fault+0x26/0x30 arch/x86/include/asm/idtentry.h:618
       user_access_begin arch/x86/include/asm/uaccess.h:-1 [inline]
       filldir+0x29c/0x6c0 fs/readdir.c:290
       dir_emit_dot include/linux/fs.h:3992 [inline]
       dir_emit_dots include/linux/fs.h:4003 [inline]
       offset_readdir+0x1e6/0x560 fs/libfs.c:569
       iterate_dir+0x399/0x570 fs/readdir.c:108
       __do_sys_getdents fs/readdir.c:326 [inline]
       __se_sys_getdents+0xe4/0x250 fs/readdir.c:312
       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:
  &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.1.8342/8264:
 #0: ffff88802f7d60f8 (&f->f_pos_lock){+.+.}-{4:4}, at: fdget_pos+0x247/0x320 fs/file.c:1232
 #1: ffff8880289349f0 (&type->i_mutex_dir_key#5){++++}-{4:4}, at: iterate_dir+0x292/0x570 fs/readdir.c:101

stack backtrace:
CPU: 0 UID: 0 PID: 8264 Comm: syz.1.8342 Not tainted syzkaller #0 PREEMPT(full) 
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 10/25/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+0x50/0x350 kernel/locking/rwsem.c:1560
 mmap_read_lock_killable+0x1d/0x70 include/linux/mmap_lock.h:377
 get_mmap_lock_carefully mm/mmap_lock.c:377 [inline]
 lock_mm_and_find_vma+0x2a8/0x300 mm/mmap_lock.c:428
 do_user_addr_fault+0x331/0x1380 arch/x86/mm/fault.c:1359
 handle_page_fault arch/x86/mm/fault.c:1476 [inline]
 exc_page_fault+0x82/0x100 arch/x86/mm/fault.c:1532
 asm_exc_page_fault+0x26/0x30 arch/x86/include/asm/idtentry.h:618
RIP: 0010:filldir+0x29c/0x6c0 fs/readdir.c:294
Code: 83 ff 4c 89 ff 4c 89 e6 e8 31 dc 83 ff 4d 39 e7 0f 82 7c 02 00 00 49 39 ef 0f 87 73 02 00 00 0f 01 cb 0f ae 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
RSP: 0018:ffffc9000469fc90 EFLAGS: 00050287
RAX: 0000000000000000 RBX: ffffc9000469fe38 RCX: ffff888025869e40
RDX: 0000000000000000 RSI: 0000200000001fc0 RDI: 0000200000001fd8
RBP: 00007ffffffff000 R08: 000000000000054a R09: 0000000000000004
R10: 000000007fffffff R11: ffffffff823c2770 R12: 0000200000001fc0
R13: ffffffff8b79be60 R14: 0000000000000001 R15: 0000200000001fd8
 dir_emit_dot include/linux/fs.h:3992 [inline]
 dir_emit_dots include/linux/fs.h:4003 [inline]
 offset_readdir+0x1e6/0x560 fs/libfs.c:569
 iterate_dir+0x399/0x570 fs/readdir.c:108
 __do_sys_getdents fs/readdir.c:326 [inline]
 __se_sys_getdents+0xe4/0x250 fs/readdir.c:312
 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:0x7fdb0e18f749
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:00007fdb0efe6038 EFLAGS: 00000246 ORIG_RAX: 000000000000004e
RAX: ffffffffffffffda RBX: 00007fdb0e3e6180 RCX: 00007fdb0e18f749
RDX: 0000000020002078 RSI: 0000200000001fc0 RDI: 0000000000000008
RBP: 00007fdb0e213f91 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
R13: 00007fdb0e3e6218 R14: 00007fdb0e3e6180 R15: 00007ffdcdf695a8
 </TASK>
----------------
Code disassembly (best guess):
   0:	83 ff 4c             	cmp    $0x4c,%edi
   3:	89 ff                	mov    %edi,%edi
   5:	4c 89 e6             	mov    %r12,%rsi
   8:	e8 31 dc 83 ff       	call   0xff83dc3e
   d:	4d 39 e7             	cmp    %r12,%r15
  10:	0f 82 7c 02 00 00    	jb     0x292
  16:	49 39 ef             	cmp    %rbp,%r15
  19:	0f 87 73 02 00 00    	ja     0x292
  1f:	0f 01 cb             	stac
  22:	0f ae e8             	lfence
  25:	48 8b 44 24 50       	mov    0x50(%rsp),%rax
* 2a:	49 89 44 24 08       	mov    %rax,0x8(%r12) <-- trapping instruction
  2f:	48 8b 4c 24 08       	mov    0x8(%rsp),%rcx
  34:	48 8b 44 24 58       	mov    0x58(%rsp),%rax
  39:	48 89 01             	mov    %rax,(%rcx)
  3c:	48 8b 04 24          	mov    (%rsp),%rax

Crashes (9):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2025/11/23 08:01 upstream 89edd36fd801 4fb8ef37 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-kasan-gce-root possible deadlock in iterate_dir
2025/10/29 05:20 upstream 8eefed8f65cc fd2207e7 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-fs possible deadlock in iterate_dir
2025/10/16 07:24 upstream 7ea30958b305 19568248 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-fs possible deadlock in iterate_dir
2025/10/13 21:42 upstream 3a8660878839 b6605ba8 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-fs possible deadlock in iterate_dir
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.