syzbot


possible deadlock in __fat_readdir

Status: auto-obsoleted due to no activity on 2024/08/15 00:09
Reported-by: syzbot+43113a55f9a2c504493e@syzkaller.appspotmail.com
First crash: 205d, last: 198d

Sample crash report:
======================================================
WARNING: possible circular locking dependency detected
5.15.158-syzkaller #0 Not tainted
------------------------------------------------------
syz-executor.4/24618 is trying to acquire lock:
ffff888023428f28 (&mm->mmap_lock){++++}-{3:3}, at: __might_fault+0x91/0x110 mm/memory.c:5327

but task is already holding lock:
ffff88807dfdc1d0 (&sbi->s_lock#3){+.+.}-{3:3}, at: __fat_readdir+0x1d4/0x1b40 fs/fat/dir.c:571

which lock already depends on the new lock.


the existing dependency chain (in reverse order) is:

-> #5 (&sbi->s_lock#3){+.+.}-{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
       msdos_lookup+0xf9/0x4f0 fs/fat/namei_msdos.c:209
       __lookup_slow+0x275/0x3d0 fs/namei.c:1663
       lookup_slow+0x53/0x70 fs/namei.c:1680
       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:1388
       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

-> #4 (&sb->s_type->i_mutex_key#35){++++}-{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:1388
       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

-> #3 (&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
       write_all_supers+0x13fd/0x4650 fs/btrfs/disk-io.c:4159
       btrfs_sync_log+0x1f78/0x2a00 fs/btrfs/tree-log.c:3327
       btrfs_sync_file+0xb4e/0xfa0 fs/btrfs/file.c:2349
       generic_write_sync include/linux/fs.h:2984 [inline]
       btrfs_file_write_iter+0x896/0xc60 fs/btrfs/file.c:2093
       call_write_iter include/linux/fs.h:2172 [inline]
       new_sync_write fs/read_write.c:507 [inline]
       vfs_write+0xacf/0xe50 fs/read_write.c:594
       ksys_write+0x1a2/0x2c0 fs/read_write.c:647
       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_info->tree_log_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_sync_log+0x1e77/0x2a00 fs/btrfs/tree-log.c:3308
       btrfs_sync_file+0xb4e/0xfa0 fs/btrfs/file.c:2349
       generic_write_sync include/linux/fs.h:2984 [inline]
       btrfs_file_write_iter+0x896/0xc60 fs/btrfs/file.c:2093
       call_write_iter include/linux/fs.h:2172 [inline]
       new_sync_write fs/read_write.c:507 [inline]
       vfs_write+0xacf/0xe50 fs/read_write.c:594
       ksys_write+0x1a2/0x2c0 fs/read_write.c:647
       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

-> #1 (sb_internal#3){.+.+}-{0:0}:
       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

-> #0 (&mm->mmap_lock){++++}-{3:3}:
       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
       __might_fault+0xb4/0x110 mm/memory.c:5328
       fat_ioctl_filldir+0xd7/0x600 fs/fat/dir.c:759
       dir_emit_dot include/linux/fs.h:3678 [inline]
       dir_emit_dots include/linux/fs.h:3689 [inline]
       __fat_readdir+0x349/0x1b40 fs/fat/dir.c:576
       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

other info that might help us debug this:

Chain exists of:
  &mm->mmap_lock --> &sb->s_type->i_mutex_key#35 --> &sbi->s_lock#3

 Possible unsafe locking scenario:

       CPU0                    CPU1
       ----                    ----
  lock(&sbi->s_lock#3);
                               lock(&sb->s_type->i_mutex_key#35);
                               lock(&sbi->s_lock#3);
  lock(&mm->mmap_lock);

 *** DEADLOCK ***

2 locks held by syz-executor.4/24618:
 #0: ffff88804c83bac0 (&sb->s_type->i_mutex_key#34){++++}-{3:3}, at: inode_lock_shared include/linux/fs.h:799 [inline]
 #0: ffff88804c83bac0 (&sb->s_type->i_mutex_key#34){++++}-{3:3}, at: fat_ioctl_readdir fs/fat/dir.c:773 [inline]
 #0: ffff88804c83bac0 (&sb->s_type->i_mutex_key#34){++++}-{3:3}, at: fat_dir_ioctl+0x1bd/0x3b0 fs/fat/dir.c:815
 #1: ffff88807dfdc1d0 (&sbi->s_lock#3){+.+.}-{3:3}, at: __fat_readdir+0x1d4/0x1b40 fs/fat/dir.c:571

stack backtrace:
CPU: 1 PID: 24618 Comm: syz-executor.4 Not tainted 5.15.158-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 03/27/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
 __might_fault+0xb4/0x110 mm/memory.c:5328
 fat_ioctl_filldir+0xd7/0x600 fs/fat/dir.c:759
 dir_emit_dot include/linux/fs.h:3678 [inline]
 dir_emit_dots include/linux/fs.h:3689 [inline]
 __fat_readdir+0x349/0x1b40 fs/fat/dir.c:576
 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
RIP: 0033:0x7f7de12afca9
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:00007f7ddf8220c8 EFLAGS: 00000246 ORIG_RAX: 0000000000000010
RAX: ffffffffffffffda RBX: 00007f7de13ddf80 RCX: 00007f7de12afca9
RDX: 0000000020000f00 RSI: 0000000082307202 RDI: 0000000000000004
RBP: 00007f7de12fb47e R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
R13: 000000000000000b R14: 00007f7de13ddf80 R15: 00007ffc2c36dcc8
 </TASK>

Crashes (2):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2024/05/07 00:08 linux-5.15.y 284087d4f7d5 fa7a5cf0 .config console log report info [disk image] [vmlinux] [kernel image] ci2-linux-5-15-kasan possible deadlock in __fat_readdir
2024/04/29 15:52 linux-5.15.y b925f60c6ee7 27e33c58 .config console log report info [disk image] [vmlinux] [kernel image] ci2-linux-5-15-kasan possible deadlock in __fat_readdir
* Struck through repros no longer work on HEAD.