syzbot


possible deadlock in ntfs_fallocate

Status: upstream: reported on 2022/12/09 08:57
Reported-by: syzbot+adacb2b0c896bc427962@syzkaller.appspotmail.com
First crash: 59d, last: 52d

Sample crash report:
======================================================
WARNING: possible circular locking dependency detected
6.1.0-syzkaller-11674-g84e57d292203 #0 Not tainted
------------------------------------------------------
syz-executor.3/14186 is trying to acquire lock:
ffff88803bd70fc0 (&ni->ni_lock/4){+.+.}-{3:3}, at: ni_lock fs/ntfs3/ntfs_fs.h:1108 [inline]
ffff88803bd70fc0 (&ni->ni_lock/4){+.+.}-{3:3}, at: ntfs_fallocate+0x823/0x1030 fs/ntfs3/file.c:601

but task is already holding lock:
ffff88803bd71400 (mapping.invalidate_lock#6){++++}-{3:3}, at: filemap_invalidate_lock include/linux/fs.h:801 [inline]
ffff88803bd71400 (mapping.invalidate_lock#6){++++}-{3:3}, at: ntfs_fallocate+0x5f9/0x1030 fs/ntfs3/file.c:583

which lock already depends on the new lock.


the existing dependency chain (in reverse order) is:

-> #3 (mapping.invalidate_lock#6){++++}-{3:3}:
       down_read+0x9c/0x450 kernel/locking/rwsem.c:1509
       filemap_invalidate_lock_shared include/linux/fs.h:811 [inline]
       filemap_fault+0xb99/0x23f0 mm/filemap.c:3146
       __do_fault+0x107/0x600 mm/memory.c:4163
       do_shared_fault mm/memory.c:4569 [inline]
       do_fault mm/memory.c:4647 [inline]
       handle_pte_fault mm/memory.c:4931 [inline]
       __handle_mm_fault+0x2080/0x3c40 mm/memory.c:5073
       handle_mm_fault+0x1b6/0x850 mm/memory.c:5219
       faultin_page mm/gup.c:926 [inline]
       __get_user_pages+0x4f8/0xfc0 mm/gup.c:1153
       __get_user_pages_locked mm/gup.c:1373 [inline]
       __gup_longterm_locked+0x1bd/0x25d0 mm/gup.c:2058
       get_user_pages_unlocked+0xe8/0x1b0 mm/gup.c:2250
       internal_get_user_pages_fast+0x160c/0x3160 mm/gup.c:2935
       get_user_pages_fast+0x6a/0xa0 mm/gup.c:3027
       __iov_iter_get_pages_alloc+0x39b/0x2430 lib/iov_iter.c:1461
       iov_iter_get_pages lib/iov_iter.c:1504 [inline]
       iov_iter_get_pages2+0xad/0x100 lib/iov_iter.c:1512
       dio_refill_pages fs/direct-io.c:172 [inline]
       dio_get_page fs/direct-io.c:215 [inline]
       do_direct_IO fs/direct-io.c:932 [inline]
       __blockdev_direct_IO+0x23e4/0x38e0 fs/direct-io.c:1266
       blockdev_direct_IO include/linux/fs.h:3213 [inline]
       ntfs_direct_IO+0x19b/0x460 fs/ntfs3/inode.c:769
       generic_file_read_iter+0x248/0x5b0 mm/filemap.c:2817
       ntfs_file_read_iter+0x1b8/0x270 fs/ntfs3/file.c:853
       call_read_iter include/linux/fs.h:2180 [inline]
       do_iter_readv_writev+0x2e0/0x3b0 fs/read_write.c:733
       do_iter_read+0x2f2/0x750 fs/read_write.c:796
       vfs_readv+0xe5/0x150 fs/read_write.c:916
       do_preadv+0x1b6/0x270 fs/read_write.c:1008
       __do_sys_preadv2 fs/read_write.c:1070 [inline]
       __se_sys_preadv2 fs/read_write.c:1061 [inline]
       __x64_sys_preadv2+0xef/0x150 fs/read_write.c:1061
       do_syscall_x64 arch/x86/entry/common.c:50 [inline]
       do_syscall_64+0x39/0xb0 arch/x86/entry/common.c:80
       entry_SYSCALL_64_after_hwframe+0x63/0xcd

-> #2 (&mm->mmap_lock#2){++++}-{3:3}:
       __might_fault mm/memory.c:5647 [inline]
       __might_fault+0x10c/0x180 mm/memory.c:5640
       _copy_to_user+0x29/0x150 lib/usercopy.c:29
       copy_to_user include/linux/uaccess.h:169 [inline]
       fiemap_fill_next_extent+0x217/0x370 fs/ioctl.c:144
       ni_fiemap+0x47d/0xc00 fs/ntfs3/frecord.c:2051
       ntfs_fiemap+0xcc/0x120 fs/ntfs3/file.c:1245
       ioctl_fiemap fs/ioctl.c:219 [inline]
       do_vfs_ioctl+0x466/0x15b0 fs/ioctl.c:810
       __do_sys_ioctl fs/ioctl.c:868 [inline]
       __se_sys_ioctl fs/ioctl.c:856 [inline]
       __x64_sys_ioctl+0x10c/0x210 fs/ioctl.c:856
       do_syscall_x64 arch/x86/entry/common.c:50 [inline]
       do_syscall_64+0x39/0xb0 arch/x86/entry/common.c:80
       entry_SYSCALL_64_after_hwframe+0x63/0xcd

-> #1 (&ni->file.run_lock#3){++++}-{3:3}:
       down_write+0x94/0x220 kernel/locking/rwsem.c:1562
       ntfs_truncate fs/ntfs3/file.c:493 [inline]
       ntfs3_setattr+0x50c/0xc10 fs/ntfs3/file.c:792
       notify_change+0xca7/0x1420 fs/attr.c:482
       do_truncate+0x143/0x200 fs/open.c:65
       handle_truncate fs/namei.c:3216 [inline]
       do_open fs/namei.c:3561 [inline]
       path_openat+0x2157/0x2a50 fs/namei.c:3714
       do_filp_open+0x1ba/0x410 fs/namei.c:3741
       do_sys_openat2+0x16d/0x4c0 fs/open.c:1310
       do_sys_open fs/open.c:1326 [inline]
       __do_sys_openat fs/open.c:1342 [inline]
       __se_sys_openat fs/open.c:1337 [inline]
       __x64_sys_openat+0x143/0x1f0 fs/open.c:1337
       do_syscall_x64 arch/x86/entry/common.c:50 [inline]
       do_syscall_64+0x39/0xb0 arch/x86/entry/common.c:80
       entry_SYSCALL_64_after_hwframe+0x63/0xcd

-> #0 (&ni->ni_lock/4){+.+.}-{3:3}:
       check_prev_add kernel/locking/lockdep.c:3097 [inline]
       check_prevs_add kernel/locking/lockdep.c:3216 [inline]
       validate_chain kernel/locking/lockdep.c:3831 [inline]
       __lock_acquire+0x2a43/0x56d0 kernel/locking/lockdep.c:5055
       lock_acquire kernel/locking/lockdep.c:5668 [inline]
       lock_acquire+0x1e3/0x630 kernel/locking/lockdep.c:5633
       __mutex_lock_common kernel/locking/mutex.c:603 [inline]
       __mutex_lock+0x12f/0x1360 kernel/locking/mutex.c:747
       ni_lock fs/ntfs3/ntfs_fs.h:1108 [inline]
       ntfs_fallocate+0x823/0x1030 fs/ntfs3/file.c:601
       vfs_fallocate+0x48b/0xe00 fs/open.c:323
       ksys_fallocate fs/open.c:346 [inline]
       __do_sys_fallocate fs/open.c:354 [inline]
       __se_sys_fallocate fs/open.c:352 [inline]
       __x64_sys_fallocate+0xd3/0x140 fs/open.c:352
       do_syscall_x64 arch/x86/entry/common.c:50 [inline]
       do_syscall_64+0x39/0xb0 arch/x86/entry/common.c:80
       entry_SYSCALL_64_after_hwframe+0x63/0xcd

other info that might help us debug this:

Chain exists of:
  &ni->ni_lock/4 --> &mm->mmap_lock#2 --> mapping.invalidate_lock#6

 Possible unsafe locking scenario:

       CPU0                    CPU1
       ----                    ----
  lock(mapping.invalidate_lock#6);
                               lock(&mm->mmap_lock#2);
                               lock(mapping.invalidate_lock#6);
  lock(&ni->ni_lock/4);

 *** DEADLOCK ***

3 locks held by syz-executor.3/14186:
 #0: ffff888078daa460 (sb_writers#14){.+.+}-{0:0}, at: ksys_fallocate fs/open.c:346 [inline]
 #0: ffff888078daa460 (sb_writers#14){.+.+}-{0:0}, at: __do_sys_fallocate fs/open.c:354 [inline]
 #0: ffff888078daa460 (sb_writers#14){.+.+}-{0:0}, at: __se_sys_fallocate fs/open.c:352 [inline]
 #0: ffff888078daa460 (sb_writers#14){.+.+}-{0:0}, at: __x64_sys_fallocate+0xd3/0x140 fs/open.c:352
 #1: ffff88803bd71260 (&sb->s_type->i_mutex_key#22){+.+.}-{3:3}, at: inode_lock include/linux/fs.h:756 [inline]
 #1: ffff88803bd71260 (&sb->s_type->i_mutex_key#22){+.+.}-{3:3}, at: ntfs_fallocate+0x26f/0x1030 fs/ntfs3/file.c:569
 #2: ffff88803bd71400 (mapping.invalidate_lock#6){++++}-{3:3}, at: filemap_invalidate_lock include/linux/fs.h:801 [inline]
 #2: ffff88803bd71400 (mapping.invalidate_lock#6){++++}-{3:3}, at: ntfs_fallocate+0x5f9/0x1030 fs/ntfs3/file.c:583

stack backtrace:
CPU: 0 PID: 14186 Comm: syz-executor.3 Not tainted 6.1.0-syzkaller-11674-g84e57d292203 #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 10/26/2022
Call Trace:
 <TASK>
 __dump_stack lib/dump_stack.c:88 [inline]
 dump_stack_lvl+0xd1/0x138 lib/dump_stack.c:106
 check_noncircular+0x25f/0x2e0 kernel/locking/lockdep.c:2177
 check_prev_add kernel/locking/lockdep.c:3097 [inline]
 check_prevs_add kernel/locking/lockdep.c:3216 [inline]
 validate_chain kernel/locking/lockdep.c:3831 [inline]
 __lock_acquire+0x2a43/0x56d0 kernel/locking/lockdep.c:5055
 lock_acquire kernel/locking/lockdep.c:5668 [inline]
 lock_acquire+0x1e3/0x630 kernel/locking/lockdep.c:5633
 __mutex_lock_common kernel/locking/mutex.c:603 [inline]
 __mutex_lock+0x12f/0x1360 kernel/locking/mutex.c:747
 ni_lock fs/ntfs3/ntfs_fs.h:1108 [inline]
 ntfs_fallocate+0x823/0x1030 fs/ntfs3/file.c:601
 vfs_fallocate+0x48b/0xe00 fs/open.c:323
 ksys_fallocate fs/open.c:346 [inline]
 __do_sys_fallocate fs/open.c:354 [inline]
 __se_sys_fallocate fs/open.c:352 [inline]
 __x64_sys_fallocate+0xd3/0x140 fs/open.c:352
 do_syscall_x64 arch/x86/entry/common.c:50 [inline]
 do_syscall_64+0x39/0xb0 arch/x86/entry/common.c:80
 entry_SYSCALL_64_after_hwframe+0x63/0xcd
RIP: 0033:0x7f9fe4a8c0d9
Code: 28 00 00 00 75 05 48 83 c4 28 c3 e8 f1 19 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 b8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007f9fe57f6168 EFLAGS: 00000246 ORIG_RAX: 000000000000011d
RAX: ffffffffffffffda RBX: 00007f9fe4bac050 RCX: 00007f9fe4a8c0d9
RDX: 0000000002000000 RSI: 0000000100000003 RDI: 0000000000000004
RBP: 00007f9fe4ae7ae9 R08: 0000000000000000 R09: 0000000000000000
R10: 000000000080fd10 R11: 0000000000000246 R12: 0000000000000000
R13: 00007ffc8438c58f R14: 00007f9fe57f6300 R15: 0000000000022000
 </TASK>

Crashes (4):
Manager Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets Title
ci-upstream-kasan-gce-root 2022/12/16 14:12 upstream 84e57d292203 79e1d513 .config console log report info [disk image] [vmlinux] [kernel image] possible deadlock in ntfs_fallocate
ci2-upstream-fs 2022/12/16 08:36 upstream 851f657a8642 6f9c033e .config console log report info [disk image] [vmlinux] [kernel image] possible deadlock in ntfs_fallocate
ci2-upstream-fs 2022/12/14 12:42 upstream 02bf43c7b7f7 f6511626 .config console log report info [disk image] [vmlinux] [kernel image] possible deadlock in ntfs_fallocate
ci2-upstream-fs 2022/12/09 03:02 upstream f3e8416619ce 1034e5fa .config console log report info [disk image] [vmlinux] [kernel image] possible deadlock in ntfs_fallocate
* Struck through repros no longer work on HEAD.