syzbot


possible deadlock in __f2fs_ioctl

Status: fixed on 2023/01/11 16:14
Reported-by: syzbot+4793f6096d174c90b4f7@syzkaller.appspotmail.com
Fix commit: 344150999b7f f2fs: fix to avoid potential deadlock
First crash: 51d, last: 19d
similar bugs (1):
Kernel Title Repro Cause bisect Fix bisect Count Last Reported Patched Status
upstream possible deadlock in __f2fs_ioctl (2) f2fs 26 1h55m 12d 0/24 upstream: reported on 2023/01/17 02:57

Sample crash report:
======================================================
WARNING: possible circular locking dependency detected
6.2.0-rc3-syzkaller-00009-g5a41237ad1d4 #0 Not tainted
------------------------------------------------------
syz-executor.4/29931 is trying to acquire lock:
ffff8880754dad18 (&mm->mmap_lock){++++}-{3:3}, at: __might_fault+0x8f/0x110 mm/memory.c:5646

but task is already holding lock:
ffff888021c84088 (&sbi->sb_lock){++++}-{3:3}, at: f2fs_down_write fs/f2fs/f2fs.h:2213 [inline]
ffff888021c84088 (&sbi->sb_lock){++++}-{3:3}, at: f2fs_ioc_get_encryption_pwsalt fs/f2fs/file.c:2350 [inline]
ffff888021c84088 (&sbi->sb_lock){++++}-{3:3}, at: __f2fs_ioctl+0x3572/0xb540 fs/f2fs/file.c:4169

which lock already depends on the new lock.


the existing dependency chain (in reverse order) is:

-> #3 (&sbi->sb_lock){++++}-{3:3}:
       lock_acquire+0x182/0x3c0 kernel/locking/lockdep.c:5668
       down_write+0x9c/0x270 kernel/locking/rwsem.c:1562
       f2fs_down_write fs/f2fs/f2fs.h:2213 [inline]
       f2fs_handle_error+0xe0/0x230 fs/f2fs/super.c:3926
       scan_nat_page fs/f2fs/node.c:2387 [inline]
       __f2fs_build_free_nids fs/f2fs/node.c:2493 [inline]
       f2fs_build_free_nids+0xb8c/0x1190 fs/f2fs/node.c:2531
       f2fs_fill_super+0x4a5f/0x6ee0 fs/f2fs/super.c:4334
       mount_bdev+0x26c/0x3a0 fs/super.c:1359
       legacy_get_tree+0xea/0x180 fs/fs_context.c:610
       vfs_get_tree+0x88/0x270 fs/super.c:1489
       do_new_mount+0x289/0xad0 fs/namespace.c:3145
       do_mount fs/namespace.c:3488 [inline]
       __do_sys_mount fs/namespace.c:3697 [inline]
       __se_sys_mount+0x2d3/0x3c0 fs/namespace.c:3674
       do_syscall_x64 arch/x86/entry/common.c:50 [inline]
       do_syscall_64+0x3d/0xb0 arch/x86/entry/common.c:80
       entry_SYSCALL_64_after_hwframe+0x63/0xcd

-> #2 (&nm_i->nat_tree_lock){++++}-{3:3}:
       lock_acquire+0x182/0x3c0 kernel/locking/lockdep.c:5668
       down_read+0x39/0x50 kernel/locking/rwsem.c:1509
       f2fs_down_read fs/f2fs/f2fs.h:2188 [inline]
       f2fs_get_node_info+0x100/0x1720 fs/f2fs/node.c:564
       f2fs_do_write_data_page+0xf87/0x2570 fs/f2fs/data.c:2728
       f2fs_write_single_data_page+0x1162/0x1c90 fs/f2fs/data.c:2863
       f2fs_write_cache_pages+0xf6e/0x2330 fs/f2fs/data.c:3115
       __f2fs_write_data_pages fs/f2fs/data.c:3265 [inline]
       f2fs_write_data_pages+0x7d2/0xc30 fs/f2fs/data.c:3292
       do_writepages+0x3c3/0x680 mm/page-writeback.c:2581
       filemap_fdatawrite_wbc+0x11e/0x170 mm/filemap.c:388
       __filemap_fdatawrite_range mm/filemap.c:421 [inline]
       filemap_write_and_wait_range+0x1df/0x2e0 mm/filemap.c:674
       f2fs_insert_range+0x37c/0x3c0 fs/f2fs/file.c:1678
       f2fs_fallocate+0x4bd/0x6e0 fs/f2fs/file.c:1841
       vfs_fallocate+0x515/0x670 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+0xb9/0x100 fs/open.c:352
       do_syscall_x64 arch/x86/entry/common.c:50 [inline]
       do_syscall_64+0x3d/0xb0 arch/x86/entry/common.c:80
       entry_SYSCALL_64_after_hwframe+0x63/0xcd

-> #1 (mapping.invalidate_lock#9){++++}-{3:3}:
       lock_acquire+0x182/0x3c0 kernel/locking/lockdep.c:5668
       down_read+0x39/0x50 kernel/locking/rwsem.c:1509
       filemap_invalidate_lock_shared include/linux/fs.h:811 [inline]
       filemap_fault+0x2fb/0x1060 mm/filemap.c:3146
       f2fs_filemap_fault+0x75/0xb0 fs/f2fs/file.c:44
       __do_fault+0x136/0x4f0 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 mm/memory.c:5073 [inline]
       handle_mm_fault+0x18bc/0x26b0 mm/memory.c:5219
       do_user_addr_fault+0x69b/0xcb0 arch/x86/mm/fault.c:1428
       handle_page_fault arch/x86/mm/fault.c:1519 [inline]
       exc_page_fault+0x7a/0x110 arch/x86/mm/fault.c:1575
       asm_exc_page_fault+0x22/0x30 arch/x86/include/asm/idtentry.h:570

-> #0 (&mm->mmap_lock){++++}-{3:3}:
       check_prev_add kernel/locking/lockdep.c:3097 [inline]
       check_prevs_add kernel/locking/lockdep.c:3216 [inline]
       validate_chain+0x1898/0x6ae0 kernel/locking/lockdep.c:3831
       __lock_acquire+0x1292/0x1f60 kernel/locking/lockdep.c:5055
       lock_acquire+0x182/0x3c0 kernel/locking/lockdep.c:5668
       __might_fault+0xb2/0x110 mm/memory.c:5647
       _copy_to_user+0x26/0x130 lib/usercopy.c:29
       copy_to_user include/linux/uaccess.h:169 [inline]
       f2fs_ioc_get_encryption_pwsalt fs/f2fs/file.c:2365 [inline]
       __f2fs_ioctl+0xaf72/0xb540 fs/f2fs/file.c:4169
       vfs_ioctl fs/ioctl.c:51 [inline]
       __do_sys_ioctl fs/ioctl.c:870 [inline]
       __se_sys_ioctl+0xfb/0x170 fs/ioctl.c:856
       do_syscall_x64 arch/x86/entry/common.c:50 [inline]
       do_syscall_64+0x3d/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:
  &mm->mmap_lock --> &nm_i->nat_tree_lock --> &sbi->sb_lock

 Possible unsafe locking scenario:

       CPU0                    CPU1
       ----                    ----
  lock(&sbi->sb_lock);
                               lock(&nm_i->nat_tree_lock);
                               lock(&sbi->sb_lock);
  lock(&mm->mmap_lock);

 *** DEADLOCK ***

2 locks held by syz-executor.4/29931:
 #0: ffff88807a0f8460 (sb_writers#25){.+.+}-{0:0}, at: mnt_want_write_file+0x5a/0x1f0 fs/namespace.c:552
 #1: ffff888021c84088 (&sbi->sb_lock){++++}-{3:3}, at: f2fs_down_write fs/f2fs/f2fs.h:2213 [inline]
 #1: ffff888021c84088 (&sbi->sb_lock){++++}-{3:3}, at: f2fs_ioc_get_encryption_pwsalt fs/f2fs/file.c:2350 [inline]
 #1: ffff888021c84088 (&sbi->sb_lock){++++}-{3:3}, at: __f2fs_ioctl+0x3572/0xb540 fs/f2fs/file.c:4169

stack backtrace:
CPU: 1 PID: 29931 Comm: syz-executor.4 Not tainted 6.2.0-rc3-syzkaller-00009-g5a41237ad1d4 #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+0x1b1/0x290 lib/dump_stack.c:106
 check_noncircular+0x2cc/0x390 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+0x1898/0x6ae0 kernel/locking/lockdep.c:3831
 __lock_acquire+0x1292/0x1f60 kernel/locking/lockdep.c:5055
 lock_acquire+0x182/0x3c0 kernel/locking/lockdep.c:5668
 __might_fault+0xb2/0x110 mm/memory.c:5647
 _copy_to_user+0x26/0x130 lib/usercopy.c:29
 copy_to_user include/linux/uaccess.h:169 [inline]
 f2fs_ioc_get_encryption_pwsalt fs/f2fs/file.c:2365 [inline]
 __f2fs_ioctl+0xaf72/0xb540 fs/f2fs/file.c:4169
 vfs_ioctl fs/ioctl.c:51 [inline]
 __do_sys_ioctl fs/ioctl.c:870 [inline]
 __se_sys_ioctl+0xfb/0x170 fs/ioctl.c:856
 do_syscall_x64 arch/x86/entry/common.c:50 [inline]
 do_syscall_64+0x3d/0xb0 arch/x86/entry/common.c:80
 entry_SYSCALL_64_after_hwframe+0x63/0xcd
RIP: 0033:0x7fa10988c0c9
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:00007fa10a502168 EFLAGS: 00000246 ORIG_RAX: 0000000000000010
RAX: ffffffffffffffda RBX: 00007fa1099ac120 RCX: 00007fa10988c0c9
RDX: 0000000020008000 RSI: 0000000040106614 RDI: 0000000000000006
RBP: 00007fa1098e7ae9 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
R13: 00007ffdcbde18af R14: 00007fa10a502300 R15: 0000000000022000
 </TASK>

Crashes (17):
Manager Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets Title
ci2-upstream-fs 2023/01/10 16:28 upstream 5a41237ad1d4 48bc529a .config console log report info [disk image] [vmlinux] [kernel image] possible deadlock in __f2fs_ioctl
ci2-upstream-fs 2023/01/10 08:20 upstream 5a41237ad1d4 48bc529a .config console log report info [disk image] [vmlinux] [kernel image] possible deadlock in __f2fs_ioctl
ci2-upstream-fs 2023/01/08 19:31 upstream 9b43a525db12 1dac8c7a .config console log report info [disk image] [vmlinux] [kernel image] possible deadlock in __f2fs_ioctl
ci2-upstream-fs 2023/01/08 10:27 upstream 9b43a525db12 1dac8c7a .config console log report info [disk image] [vmlinux] [kernel image] possible deadlock in __f2fs_ioctl
ci2-upstream-fs 2023/01/08 04:35 upstream 0a71553536d2 1dac8c7a .config console log report info [disk image] [vmlinux] [kernel image] possible deadlock in __f2fs_ioctl
ci2-upstream-fs 2023/01/07 15:41 upstream 0a71553536d2 1dac8c7a .config console log report info [disk image] [vmlinux] [kernel image] possible deadlock in __f2fs_ioctl
ci2-upstream-fs 2023/01/06 18:36 upstream 1f5abbd77e2c 1dac8c7a .config console log report info [disk image] [vmlinux] [kernel image] possible deadlock in __f2fs_ioctl
ci2-upstream-fs 2022/12/31 16:39 upstream c8451c141e07 ab32d508 .config console log report info [disk image] [vmlinux] [kernel image] possible deadlock in __f2fs_ioctl
ci2-upstream-fs 2022/12/30 01:10 upstream 2258c2dc850b 44712fbc .config console log report info [disk image] [vmlinux] [kernel image] possible deadlock in __f2fs_ioctl
ci2-upstream-fs 2022/12/28 23:35 upstream 1b929c02afd3 44712fbc .config console log report info [disk image] [vmlinux] [kernel image] possible deadlock in __f2fs_ioctl
ci2-upstream-fs 2022/12/27 19:02 upstream 1b929c02afd3 44712fbc .config console log report info [disk image] [vmlinux] [kernel image] possible deadlock in __f2fs_ioctl
ci2-upstream-fs 2022/12/19 07:05 upstream f9ff5644bcc0 05494336 .config console log report info [disk image] [vmlinux] [kernel image] possible deadlock in __f2fs_ioctl
ci-upstream-linux-next-kasan-gce-root 2023/01/09 12:12 linux-next 543b9b2fe10b 1dac8c7a .config console log report info [disk image] [vmlinux] [kernel image] possible deadlock in __f2fs_ioctl
ci-upstream-gce-arm64 2022/12/27 19:08 git://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git for-kernelci a5541c0811a0 44712fbc .config console log report info [disk image] [vmlinux] [kernel image] possible deadlock in __f2fs_ioctl
ci-upstream-gce-arm64 2022/12/14 04:33 git://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git for-kernelci a5541c0811a0 e660de91 .config console log report info [disk image] [vmlinux] [kernel image] possible deadlock in __f2fs_ioctl
ci-upstream-gce-arm64 2022/12/13 18:14 git://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git for-kernelci a5541c0811a0 e660de91 .config console log report info [disk image] [vmlinux] [kernel image] possible deadlock in __f2fs_ioctl
ci-upstream-gce-arm64 2022/12/09 06:42 git://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git for-kernelci a5541c0811a0 1034e5fa .config console log report info [disk image] [vmlinux] [kernel image] possible deadlock in __f2fs_ioctl
* Struck through repros no longer work on HEAD.