syzbot


possible deadlock in f2fs_do_map_lock

Status: auto-obsoleted due to no activity on 2023/06/22 15:48
Subsystems: f2fs
[Documentation on labels]
Reported-by: syzbot+b392b861663de30af8e0@syzkaller.appspotmail.com
First crash: 489d, last: 425d
Discussions (1)
Title Replies (including bot) Last reply
[syzbot] [f2fs?] possible deadlock in f2fs_do_map_lock 0 (1) 2022/12/24 11:20

Sample crash report:
======================================================
WARNING: possible circular locking dependency detected
6.2.0-syzkaller-05251-g5b7c4cabbb65 #0 Not tainted
------------------------------------------------------
syz-executor.2/19683 is trying to acquire lock:
ffff8880412604e0 (&sbi->node_change){++++}-{3:3}, at: f2fs_down_read fs/f2fs/f2fs.h:2188 [inline]
ffff8880412604e0 (&sbi->node_change){++++}-{3:3}, at: f2fs_lock_op fs/f2fs/f2fs.h:2231 [inline]
ffff8880412604e0 (&sbi->node_change){++++}-{3:3}, at: f2fs_do_map_lock+0x4e/0x80 fs/f2fs/data.c:1464

but task is already holding lock:
ffff888071847430 (mapping.invalidate_lock#6){++++}-{3:3}, at: filemap_invalidate_lock_shared include/linux/fs.h:811 [inline]
ffff888071847430 (mapping.invalidate_lock#6){++++}-{3:3}, at: f2fs_vm_page_mkwrite+0x630/0x1cf0 fs/f2fs/file.c:104

which lock already depends on the new lock.


the existing dependency chain (in reverse order) is:

-> #4 (mapping.invalidate_lock#6){++++}-{3:3}:
       down_read+0x3d/0x50 kernel/locking/rwsem.c:1520
       filemap_invalidate_lock_shared include/linux/fs.h:811 [inline]
       filemap_fault+0xb99/0x2450 mm/filemap.c:3147
       f2fs_filemap_fault+0x82/0x400 fs/f2fs/file.c:44
       __do_fault+0x107/0x600 mm/memory.c:4166
       do_shared_fault mm/memory.c:4572 [inline]
       do_fault mm/memory.c:4650 [inline]
       handle_pte_fault mm/memory.c:4934 [inline]
       __handle_mm_fault+0x236e/0x3c90 mm/memory.c:5076
       handle_mm_fault+0x21e/0x910 mm/memory.c:5222
       do_user_addr_fault+0x475/0x1230 arch/x86/mm/fault.c:1428
       handle_page_fault arch/x86/mm/fault.c:1519 [inline]
       exc_page_fault+0x98/0x170 arch/x86/mm/fault.c:1575
       asm_exc_page_fault+0x26/0x30 arch/x86/include/asm/idtentry.h:570
       copy_user_short_string+0xd/0x40 arch/x86/lib/copy_user_64.S:232
       copy_user_generic arch/x86/include/asm/uaccess_64.h:37 [inline]
       raw_copy_to_user arch/x86/include/asm/uaccess_64.h:58 [inline]
       _copy_to_user lib/usercopy.c:41 [inline]
       _copy_to_user+0x127/0x150 lib/usercopy.c:34
       copy_to_user include/linux/uaccess.h:169 [inline]
       do_pipe2+0x128/0x1b0 fs/pipe.c:1012
       __do_sys_pipe2 fs/pipe.c:1028 [inline]
       __se_sys_pipe2 fs/pipe.c:1026 [inline]
       __x64_sys_pipe2+0x54/0x80 fs/pipe.c:1026
       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

-> #3 (&mm->mmap_lock){++++}-{3:3}:
       __might_fault mm/memory.c:5650 [inline]
       __might_fault+0x10c/0x180 mm/memory.c:5643
       _copy_to_user+0x29/0x150 lib/usercopy.c:36
       copy_to_user include/linux/uaccess.h:169 [inline]
       f2fs_ioc_get_encryption_pwsalt+0x2b2/0x370 fs/f2fs/file.c:2365
       __f2fs_ioctl+0x29db/0xabf0 fs/f2fs/file.c:4169
       f2fs_ioctl+0x18e/0x220 fs/f2fs/file.c:4242
       vfs_ioctl fs/ioctl.c:51 [inline]
       __do_sys_ioctl fs/ioctl.c:870 [inline]
       __se_sys_ioctl fs/ioctl.c:856 [inline]
       __x64_sys_ioctl+0x197/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

-> #2 (&sbi->sb_lock){++++}-{3:3}:
       down_write+0x92/0x200 kernel/locking/rwsem.c:1573
       f2fs_down_write fs/f2fs/f2fs.h:2213 [inline]
       f2fs_handle_error+0x8e/0x220 fs/f2fs/super.c:3920
       f2fs_check_nid_range.part.0+0x4d/0x60 fs/f2fs/node.c:39
       f2fs_check_nid_range fs/f2fs/node.c:2278 [inline]
       add_free_nid.isra.0+0x781/0x940 fs/f2fs/node.c:2285
       scan_nat_page fs/f2fs/node.c:2387 [inline]
       __f2fs_build_free_nids+0x5b5/0xe10 fs/f2fs/node.c:2493
       f2fs_build_free_nids fs/f2fs/node.c:2531 [inline]
       f2fs_build_node_manager+0x2072/0x3000 fs/f2fs/node.c:3316
       f2fs_fill_super+0x39ad/0x8b90 fs/f2fs/super.c:4328
       mount_bdev+0x351/0x410 fs/super.c:1371
       legacy_get_tree+0x109/0x220 fs/fs_context.c:610
       vfs_get_tree+0x8d/0x350 fs/super.c:1501
       do_new_mount fs/namespace.c:3031 [inline]
       path_mount+0x1342/0x1e40 fs/namespace.c:3361
       do_mount fs/namespace.c:3374 [inline]
       __do_sys_mount fs/namespace.c:3583 [inline]
       __se_sys_mount fs/namespace.c:3560 [inline]
       __x64_sys_mount+0x283/0x300 fs/namespace.c:3560
       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 (&nm_i->nat_tree_lock){++++}-{3:3}:
       down_read+0x3d/0x50 kernel/locking/rwsem.c:1520
       f2fs_down_read fs/f2fs/f2fs.h:2188 [inline]
       f2fs_get_node_info+0x1ac/0x1070 fs/f2fs/node.c:564
       __write_node_page+0x89f/0x2160 fs/f2fs/node.c:1616
       f2fs_sync_node_pages+0x141b/0x2330 fs/f2fs/node.c:2020
       block_operations+0x60c/0xc40 fs/f2fs/checkpoint.c:1275
       f2fs_write_checkpoint+0x606/0x4cb0 fs/f2fs/checkpoint.c:1655
       __write_checkpoint_sync fs/f2fs/checkpoint.c:1772 [inline]
       __checkpoint_and_complete_reqs+0xea/0x350 fs/f2fs/checkpoint.c:1791
       issue_checkpoint_thread+0xe3/0x250 fs/f2fs/checkpoint.c:1822
       kthread+0x2e8/0x3a0 kernel/kthread.c:376
       ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:308

-> #0 (&sbi->node_change){++++}-{3:3}:
       check_prev_add kernel/locking/lockdep.c:3098 [inline]
       check_prevs_add kernel/locking/lockdep.c:3217 [inline]
       validate_chain kernel/locking/lockdep.c:3832 [inline]
       __lock_acquire+0x2ec7/0x5d40 kernel/locking/lockdep.c:5056
       lock_acquire kernel/locking/lockdep.c:5669 [inline]
       lock_acquire+0x1e3/0x670 kernel/locking/lockdep.c:5634
       down_read+0x3d/0x50 kernel/locking/rwsem.c:1520
       f2fs_down_read fs/f2fs/f2fs.h:2188 [inline]
       f2fs_lock_op fs/f2fs/f2fs.h:2231 [inline]
       f2fs_do_map_lock+0x4e/0x80 fs/f2fs/data.c:1464
       f2fs_vm_page_mkwrite+0x1293/0x1cf0 fs/f2fs/file.c:116
       do_page_mkwrite+0x19b/0x680 mm/memory.c:2943
       do_shared_fault mm/memory.c:4582 [inline]
       do_fault mm/memory.c:4650 [inline]
       handle_pte_fault mm/memory.c:4934 [inline]
       __handle_mm_fault+0x23ee/0x3c90 mm/memory.c:5076
       handle_mm_fault+0x21e/0x910 mm/memory.c:5222
       do_user_addr_fault+0x475/0x1230 arch/x86/mm/fault.c:1428
       handle_page_fault arch/x86/mm/fault.c:1519 [inline]
       exc_page_fault+0x98/0x170 arch/x86/mm/fault.c:1575
       asm_exc_page_fault+0x26/0x30 arch/x86/include/asm/idtentry.h:570
       copy_user_short_string+0xd/0x40 arch/x86/lib/copy_user_64.S:232
       copy_user_generic arch/x86/include/asm/uaccess_64.h:37 [inline]
       raw_copy_to_user arch/x86/include/asm/uaccess_64.h:58 [inline]
       _copy_to_user lib/usercopy.c:41 [inline]
       _copy_to_user+0x127/0x150 lib/usercopy.c:34
       copy_to_user include/linux/uaccess.h:169 [inline]
       do_pipe2+0x128/0x1b0 fs/pipe.c:1012
       __do_sys_pipe2 fs/pipe.c:1028 [inline]
       __se_sys_pipe2 fs/pipe.c:1026 [inline]
       __x64_sys_pipe2+0x54/0x80 fs/pipe.c:1026
       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:
  &sbi->node_change --> &mm->mmap_lock --> mapping.invalidate_lock#6

 Possible unsafe locking scenario:

       CPU0                    CPU1
       ----                    ----
  lock(mapping.invalidate_lock#6);
                               lock(&mm->mmap_lock);
                               lock(mapping.invalidate_lock#6);
  lock(&sbi->node_change);

 *** DEADLOCK ***

3 locks held by syz-executor.2/19683:
 #0: ffff88802eb23518 (&mm->mmap_lock){++++}-{3:3}, at: mmap_read_lock include/linux/mmap_lock.h:117 [inline]
 #0: ffff88802eb23518 (&mm->mmap_lock){++++}-{3:3}, at: do_user_addr_fault+0xa51/0x1230 arch/x86/mm/fault.c:1379
 #1: ffff888042262558 (sb_pagefaults#3){.+.+}-{0:0}, at: do_page_mkwrite+0x19b/0x680 mm/memory.c:2943
 #2: ffff888071847430 (mapping.invalidate_lock#6){++++}-{3:3}, at: filemap_invalidate_lock_shared include/linux/fs.h:811 [inline]
 #2: ffff888071847430 (mapping.invalidate_lock#6){++++}-{3:3}, at: f2fs_vm_page_mkwrite+0x630/0x1cf0 fs/f2fs/file.c:104

stack backtrace:
CPU: 1 PID: 19683 Comm: syz-executor.2 Not tainted 6.2.0-syzkaller-05251-g5b7c4cabbb65 #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/21/2023
Call Trace:
 <TASK>
 __dump_stack lib/dump_stack.c:88 [inline]
 dump_stack_lvl+0xd9/0x150 lib/dump_stack.c:106
 check_noncircular+0x25f/0x2e0 kernel/locking/lockdep.c:2178
 check_prev_add kernel/locking/lockdep.c:3098 [inline]
 check_prevs_add kernel/locking/lockdep.c:3217 [inline]
 validate_chain kernel/locking/lockdep.c:3832 [inline]
 __lock_acquire+0x2ec7/0x5d40 kernel/locking/lockdep.c:5056
 lock_acquire kernel/locking/lockdep.c:5669 [inline]
 lock_acquire+0x1e3/0x670 kernel/locking/lockdep.c:5634
 down_read+0x3d/0x50 kernel/locking/rwsem.c:1520
 f2fs_down_read fs/f2fs/f2fs.h:2188 [inline]
 f2fs_lock_op fs/f2fs/f2fs.h:2231 [inline]
 f2fs_do_map_lock+0x4e/0x80 fs/f2fs/data.c:1464
 f2fs_vm_page_mkwrite+0x1293/0x1cf0 fs/f2fs/file.c:116
 do_page_mkwrite+0x19b/0x680 mm/memory.c:2943
 do_shared_fault mm/memory.c:4582 [inline]
 do_fault mm/memory.c:4650 [inline]
 handle_pte_fault mm/memory.c:4934 [inline]
 __handle_mm_fault+0x23ee/0x3c90 mm/memory.c:5076
 handle_mm_fault+0x21e/0x910 mm/memory.c:5222
 do_user_addr_fault+0x475/0x1230 arch/x86/mm/fault.c:1428
 handle_page_fault arch/x86/mm/fault.c:1519 [inline]
 exc_page_fault+0x98/0x170 arch/x86/mm/fault.c:1575
 asm_exc_page_fault+0x26/0x30 arch/x86/include/asm/idtentry.h:570
RIP: 0010:copy_user_short_string+0xd/0x40 arch/x86/lib/copy_user_64.S:233
Code: 74 0a 89 d1 f3 a4 89 c8 0f 01 ca c3 89 d0 0f 01 ca c3 01 ca eb e7 0f 1f 80 00 00 00 00 89 d1 83 e2 07 c1 e9 03 74 12 4c 8b 06 <4c> 89 07 48 8d 76 08 48 8d 7f 08 ff c9 75 ee 21 d2 74 10 89 d1 8a
RSP: 0018:ffffc90004c07e50 EFLAGS: 00050202
RAX: 0000000000000001 RBX: 0000000000000008 RCX: 0000000000000001
RDX: 0000000000000000 RSI: ffffc90004c07ea0 RDI: 0000000020000040
RBP: 0000000020000040 R08: 0000000600000005 R09: ffffc90004c07ea7
R10: fffff52000980fd4 R11: 0000000000000000 R12: 00007fffffffeff8
R13: ffffc90004c07ea0 R14: 0000000000000000 R15: 0000000000000000
 copy_user_generic arch/x86/include/asm/uaccess_64.h:37 [inline]
 raw_copy_to_user arch/x86/include/asm/uaccess_64.h:58 [inline]
 _copy_to_user lib/usercopy.c:41 [inline]
 _copy_to_user+0x127/0x150 lib/usercopy.c:34
 copy_to_user include/linux/uaccess.h:169 [inline]
 do_pipe2+0x128/0x1b0 fs/pipe.c:1012
 __do_sys_pipe2 fs/pipe.c:1028 [inline]
 __se_sys_pipe2 fs/pipe.c:1026 [inline]
 __x64_sys_pipe2+0x54/0x80 fs/pipe.c:1026
 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:0x7feaf0e8c0f9
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:00007feaf1bd7168 EFLAGS: 00000246 ORIG_RAX: 0000000000000125
RAX: ffffffffffffffda RBX: 00007feaf0fabf80 RCX: 00007feaf0e8c0f9
RDX: 0000000000000000 RSI: 0000000000000080 RDI: 0000000020000040
RBP: 00007feaf0ee7ae9 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
R13: 00007ffce2cf1aaf R14: 00007feaf1bd7300 R15: 0000000000022000
 </TASK>
----------------
Code disassembly (best guess):
   0:	74 0a                	je     0xc
   2:	89 d1                	mov    %edx,%ecx
   4:	f3 a4                	rep movsb %ds:(%rsi),%es:(%rdi)
   6:	89 c8                	mov    %ecx,%eax
   8:	0f 01 ca             	clac
   b:	c3                   	retq
   c:	89 d0                	mov    %edx,%eax
   e:	0f 01 ca             	clac
  11:	c3                   	retq
  12:	01 ca                	add    %ecx,%edx
  14:	eb e7                	jmp    0xfffffffd
  16:	0f 1f 80 00 00 00 00 	nopl   0x0(%rax)
  1d:	89 d1                	mov    %edx,%ecx
  1f:	83 e2 07             	and    $0x7,%edx
  22:	c1 e9 03             	shr    $0x3,%ecx
  25:	74 12                	je     0x39
  27:	4c 8b 06             	mov    (%rsi),%r8
* 2a:	4c 89 07             	mov    %r8,(%rdi) <-- trapping instruction
  2d:	48 8d 76 08          	lea    0x8(%rsi),%rsi
  31:	48 8d 7f 08          	lea    0x8(%rdi),%rdi
  35:	ff c9                	dec    %ecx
  37:	75 ee                	jne    0x27
  39:	21 d2                	and    %edx,%edx
  3b:	74 10                	je     0x4d
  3d:	89 d1                	mov    %edx,%ecx
  3f:	8a                   	.byte 0x8a

Crashes (3):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2023/02/22 15:48 upstream 5b7c4cabbb65 409945bc .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-kasan-gce-selinux-root possible deadlock in f2fs_do_map_lock
2023/01/19 07:41 upstream 7287904c8771 42660d9e .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-kasan-gce-selinux-root possible deadlock in f2fs_do_map_lock
2022/12/20 11:17 git://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git for-kernelci a5541c0811a0 d3e76707 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-gce-arm64 possible deadlock in f2fs_do_map_lock
* Struck through repros no longer work on HEAD.