syzbot


possible deadlock in btrfs_dirty_inode (2)

Status: auto-obsoleted due to no activity on 2024/09/22 15:54
Reported-by: syzbot+356920590036380b9c75@syzkaller.appspotmail.com
First crash: 192d, last: 130d
Similar bugs (2)
Kernel Title Repro Cause bisect Fix bisect Count Last Reported Patched Status
linux-5.15 possible deadlock in btrfs_dirty_inode 3 489d 508d 0/3 auto-obsoleted due to no activity on 2023/09/28 23:24
upstream possible deadlock in btrfs_dirty_inode btrfs C error done 48 696d 708d 0/28 auto-obsoleted due to no activity on 2023/05/16 05:18

Sample crash report:
======================================================
WARNING: possible circular locking dependency detected
5.15.160-syzkaller #0 Not tainted
------------------------------------------------------
syz-executor.3/6669 is trying to acquire lock:
ffff88807af5e650 (sb_internal#3){.+.+}-{0:0}, at: btrfs_dirty_inode+0xcc/0x1c0 fs/btrfs/inode.c:6428

but task is already holding lock:
ffff888023adea28 (&mm->mmap_lock){++++}-{3:3}, at: mmap_write_lock_killable include/linux/mmap_lock.h:87 [inline]
ffff888023adea28 (&mm->mmap_lock){++++}-{3:3}, at: vm_mmap_pgoff+0x175/0x2d0 mm/util.c:549

which lock already depends on the new lock.


the existing dependency chain (in reverse order) is:

-> #5 (&mm->mmap_lock){++++}-{3:3}:
       lock_acquire+0x1db/0x4f0 kernel/locking/lockdep.c:5623
       __might_fault+0xb4/0x110 mm/memory.c:5328
       _copy_to_user+0x28/0x130 lib/usercopy.c:35
       copy_to_user include/linux/uaccess.h:200 [inline]
       fat_ioctl_filldir+0x1d8/0x600 fs/fat/dir.c:759
       dir_emit include/linux/fs.h:3674 [inline]
       __fat_readdir+0x1485/0x1b40 fs/fat/dir.c:677
       fat_ioctl_readdir fs/fat/dir.c:777 [inline]
       fat_dir_ioctl+0x27e/0x3b0 fs/fat/dir.c:815
       vfs_ioctl fs/ioctl.c:51 [inline]
       __do_sys_ioctl fs/ioctl.c:874 [inline]
       __se_sys_ioctl+0xf1/0x160 fs/ioctl.c:860
       do_syscall_x64 arch/x86/entry/common.c:50 [inline]
       do_syscall_64+0x3b/0xb0 arch/x86/entry/common.c:80
       entry_SYSCALL_64_after_hwframe+0x66/0xd0

-> #4 (&sbi->s_lock#2){+.+.}-{3:3}:
       lock_acquire+0x1db/0x4f0 kernel/locking/lockdep.c:5623
       __mutex_lock_common+0x1da/0x25a0 kernel/locking/mutex.c:596
       __mutex_lock kernel/locking/mutex.c:729 [inline]
       mutex_lock_nested+0x17/0x20 kernel/locking/mutex.c:743
       __fat_readdir+0x1d4/0x1b40 fs/fat/dir.c:571
       iterate_dir+0x224/0x570
       __do_sys_getdents fs/readdir.c:286 [inline]
       __se_sys_getdents+0x1e8/0x4c0 fs/readdir.c:271
       do_syscall_x64 arch/x86/entry/common.c:50 [inline]
       do_syscall_64+0x3b/0xb0 arch/x86/entry/common.c:80
       entry_SYSCALL_64_after_hwframe+0x66/0xd0

-> #3 (&sb->s_type->i_mutex_key#40){.+.+}-{3:3}:
       lock_acquire+0x1db/0x4f0 kernel/locking/lockdep.c:5623
       down_read+0x45/0x2e0 kernel/locking/rwsem.c:1498
       inode_lock_shared include/linux/fs.h:799 [inline]
       lookup_slow+0x45/0x70 fs/namei.c:1679
       walk_component+0x48c/0x610 fs/namei.c:1976
       lookup_last fs/namei.c:2431 [inline]
       path_lookupat+0x16f/0x450 fs/namei.c:2455
       filename_lookup+0x230/0x5c0 fs/namei.c:2484
       kern_path+0x37/0x180 fs/namei.c:2582
       lookup_bdev+0xc1/0x280 block/bdev.c:979
       device_matched fs/btrfs/volumes.c:568 [inline]
       btrfs_free_stale_devices+0x71f/0xb00 fs/btrfs/volumes.c:608
       btrfs_forget_devices+0x52/0x80 fs/btrfs/volumes.c:1395
       btrfs_control_ioctl+0x108/0x210 fs/btrfs/super.c:2451
       vfs_ioctl fs/ioctl.c:51 [inline]
       __do_sys_ioctl fs/ioctl.c:874 [inline]
       __se_sys_ioctl+0xf1/0x160 fs/ioctl.c:860
       do_syscall_x64 arch/x86/entry/common.c:50 [inline]
       do_syscall_64+0x3b/0xb0 arch/x86/entry/common.c:80
       entry_SYSCALL_64_after_hwframe+0x66/0xd0

-> #2 (&fs_devs->device_list_mutex){+.+.}-{3:3}:
       lock_acquire+0x1db/0x4f0 kernel/locking/lockdep.c:5623
       __mutex_lock_common+0x1da/0x25a0 kernel/locking/mutex.c:596
       __mutex_lock kernel/locking/mutex.c:729 [inline]
       mutex_lock_nested+0x17/0x20 kernel/locking/mutex.c:743
       btrfs_run_dev_stats+0xeb/0xfd0 fs/btrfs/volumes.c:7949
       commit_cowonly_roots+0x1cb/0x9d0 fs/btrfs/transaction.c:1290
       btrfs_commit_transaction+0x13af/0x3800 fs/btrfs/transaction.c:2392
       sync_filesystem+0x1bc/0x220 fs/sync.c:66
       generic_shutdown_super+0x6e/0x2c0 fs/super.c:448
       kill_anon_super+0x37/0x60 fs/super.c:1076
       btrfs_kill_super+0x3d/0x50 fs/btrfs/super.c:2391
       deactivate_locked_super+0xa0/0x110 fs/super.c:335
       cleanup_mnt+0x44e/0x500 fs/namespace.c:1143
       task_work_run+0x129/0x1a0 kernel/task_work.c:164
       tracehook_notify_resume include/linux/tracehook.h:189 [inline]
       exit_to_user_mode_loop+0x106/0x130 kernel/entry/common.c:181
       exit_to_user_mode_prepare+0xb1/0x140 kernel/entry/common.c:214
       __syscall_exit_to_user_mode_work kernel/entry/common.c:296 [inline]
       syscall_exit_to_user_mode+0x5d/0x240 kernel/entry/common.c:307
       do_syscall_64+0x47/0xb0 arch/x86/entry/common.c:86
       entry_SYSCALL_64_after_hwframe+0x66/0xd0

-> #1 (&fs_info->tree_log_mutex){+.+.}-{3:3}:
       reacquire_held_locks+0x3a2/0x660 kernel/locking/lockdep.c:5150
       __lock_release kernel/locking/lockdep.c:5339 [inline]
       lock_release+0x369/0x9a0 kernel/locking/lockdep.c:5643
       __mutex_unlock_slowpath+0xde/0x750 kernel/locking/mutex.c:851
       btrfs_commit_transaction+0x1e34/0x3800 fs/btrfs/transaction.c:2439
       close_ctree+0x390/0x890 fs/btrfs/disk-io.c:4450
       generic_shutdown_super+0x136/0x2c0 fs/super.c:475
       kill_anon_super+0x37/0x60 fs/super.c:1076
       btrfs_kill_super+0x3d/0x50 fs/btrfs/super.c:2391
       deactivate_locked_super+0xa0/0x110 fs/super.c:335
       cleanup_mnt+0x44e/0x500 fs/namespace.c:1143
       task_work_run+0x129/0x1a0 kernel/task_work.c:164
       tracehook_notify_resume include/linux/tracehook.h:189 [inline]
       exit_to_user_mode_loop+0x106/0x130 kernel/entry/common.c:181
       exit_to_user_mode_prepare+0xb1/0x140 kernel/entry/common.c:214
       __syscall_exit_to_user_mode_work kernel/entry/common.c:296 [inline]
       syscall_exit_to_user_mode+0x5d/0x240 kernel/entry/common.c:307
       do_syscall_64+0x47/0xb0 arch/x86/entry/common.c:86
       entry_SYSCALL_64_after_hwframe+0x66/0xd0

-> #0 (sb_internal#3){.+.+}-{0:0}:
       check_prev_add kernel/locking/lockdep.c:3053 [inline]
       check_prevs_add kernel/locking/lockdep.c:3172 [inline]
       validate_chain+0x1649/0x5930 kernel/locking/lockdep.c:3788
       __lock_acquire+0x1295/0x1ff0 kernel/locking/lockdep.c:5012
       lock_acquire+0x1db/0x4f0 kernel/locking/lockdep.c:5623
       percpu_down_read include/linux/percpu-rwsem.h:51 [inline]
       __sb_start_write include/linux/fs.h:1811 [inline]
       sb_start_intwrite include/linux/fs.h:1928 [inline]
       start_transaction+0x5a8/0x11a0 fs/btrfs/transaction.c:678
       btrfs_dirty_inode+0xcc/0x1c0 fs/btrfs/inode.c:6428
       inode_update_time fs/inode.c:1829 [inline]
       touch_atime+0x34e/0x680 fs/inode.c:1902
       file_accessed include/linux/fs.h:2516 [inline]
       btrfs_file_mmap+0xbf/0x120 fs/btrfs/file.c:2424
       call_mmap include/linux/fs.h:2177 [inline]
       mmap_region+0x10e7/0x1670 mm/mmap.c:1791
       do_mmap+0x78d/0xe00 mm/mmap.c:1575
       vm_mmap_pgoff+0x1ca/0x2d0 mm/util.c:551
       ksys_mmap_pgoff+0x559/0x780 mm/mmap.c:1624
       do_syscall_x64 arch/x86/entry/common.c:50 [inline]
       do_syscall_64+0x3b/0xb0 arch/x86/entry/common.c:80
       entry_SYSCALL_64_after_hwframe+0x66/0xd0

other info that might help us debug this:

Chain exists of:
  sb_internal#3 --> &sbi->s_lock#2 --> &mm->mmap_lock

 Possible unsafe locking scenario:

       CPU0                    CPU1
       ----                    ----
  lock(&mm->mmap_lock);
                               lock(&sbi->s_lock#2);
                               lock(&mm->mmap_lock);
  lock(sb_internal#3);

 *** DEADLOCK ***

2 locks held by syz-executor.3/6669:
 #0: ffff888023adea28 (&mm->mmap_lock){++++}-{3:3}, at: mmap_write_lock_killable include/linux/mmap_lock.h:87 [inline]
 #0: ffff888023adea28 (&mm->mmap_lock){++++}-{3:3}, at: vm_mmap_pgoff+0x175/0x2d0 mm/util.c:549
 #1: ffff88807af5e460 (sb_writers#16){.+.+}-{0:0}, at: file_accessed include/linux/fs.h:2516 [inline]
 #1: ffff88807af5e460 (sb_writers#16){.+.+}-{0:0}, at: btrfs_file_mmap+0xbf/0x120 fs/btrfs/file.c:2424

stack backtrace:
CPU: 1 PID: 6669 Comm: syz-executor.3 Not tainted 5.15.160-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 06/07/2024
Call Trace:
 <TASK>
 __dump_stack lib/dump_stack.c:88 [inline]
 dump_stack_lvl+0x1e3/0x2d0 lib/dump_stack.c:106
 check_noncircular+0x2f8/0x3b0 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+0x1649/0x5930 kernel/locking/lockdep.c:3788
 __lock_acquire+0x1295/0x1ff0 kernel/locking/lockdep.c:5012
 lock_acquire+0x1db/0x4f0 kernel/locking/lockdep.c:5623
 percpu_down_read include/linux/percpu-rwsem.h:51 [inline]
 __sb_start_write include/linux/fs.h:1811 [inline]
 sb_start_intwrite include/linux/fs.h:1928 [inline]
 start_transaction+0x5a8/0x11a0 fs/btrfs/transaction.c:678
 btrfs_dirty_inode+0xcc/0x1c0 fs/btrfs/inode.c:6428
 inode_update_time fs/inode.c:1829 [inline]
 touch_atime+0x34e/0x680 fs/inode.c:1902
 file_accessed include/linux/fs.h:2516 [inline]
 btrfs_file_mmap+0xbf/0x120 fs/btrfs/file.c:2424
 call_mmap include/linux/fs.h:2177 [inline]
 mmap_region+0x10e7/0x1670 mm/mmap.c:1791
 do_mmap+0x78d/0xe00 mm/mmap.c:1575
 vm_mmap_pgoff+0x1ca/0x2d0 mm/util.c:551
 ksys_mmap_pgoff+0x559/0x780 mm/mmap.c:1624
 do_syscall_x64 arch/x86/entry/common.c:50 [inline]
 do_syscall_64+0x3b/0xb0 arch/x86/entry/common.c:80
 entry_SYSCALL_64_after_hwframe+0x66/0xd0
RIP: 0033:0x7fd4f55a2ea9
Code: 28 00 00 00 75 05 48 83 c4 28 c3 e8 e1 20 00 00 90 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 b0 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007fd4f40fb0c8 EFLAGS: 00000246 ORIG_RAX: 0000000000000009
RAX: ffffffffffffffda RBX: 00007fd4f56da050 RCX: 00007fd4f55a2ea9
RDX: 0000000000000003 RSI: 0000000000003000 RDI: 0000000020000000
RBP: 00007fd4f5611ff4 R08: 000000000000000a R09: 0000000000000000
R10: 0000000000000012 R11: 0000000000000246 R12: 0000000000000000
R13: 000000000000006e R14: 00007fd4f56da050 R15: 00007fffd2987268
 </TASK>

Crashes (2):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2024/06/14 15:53 linux-5.15.y c61bd26ae81a 8d849073 .config console log report info [disk image] [vmlinux] [kernel image] ci2-linux-5-15-kasan possible deadlock in btrfs_dirty_inode
2024/04/13 12:11 linux-5.15.y cdfd0a7f0139 c8349e48 .config console log report info [disk image] [vmlinux] [kernel image] ci2-linux-5-15-kasan possible deadlock in btrfs_dirty_inode
* Struck through repros no longer work on HEAD.