syzbot


possible deadlock in filemap_fault

Status: upstream: reported on 2022/11/03 22:14
Reported-by: syzbot+7736960b837908f3a81d@syzkaller.appspotmail.com
First crash: 27d, last: 2d15h

Sample crash report:
exfat: Deprecated parameter 'utf8'
exFAT-fs (loop3): failed to load upcase table (idx : 0x00010000, chksum : 0x207d53fc, utbl_chksum : 0xe619d30d)
======================================================
WARNING: possible circular locking dependency detected
6.1.0-rc6-syzkaller-00012-g4312098baf37 #0 Not tainted
------------------------------------------------------
syz-executor.3/10562 is trying to acquire lock:
ffff888031041e50 (mapping.invalidate_lock#7){.+.+}-{3:3}, at: filemap_invalidate_lock_shared include/linux/fs.h:811 [inline]
ffff888031041e50 (mapping.invalidate_lock#7){.+.+}-{3:3}, at: filemap_fault+0x2fb/0x1060 mm/filemap.c:3127

but task is already holding lock:
ffff888077d8e0e0 (&sbi->s_lock){+.+.}-{3:3}, at: exfat_iterate+0x1c1/0x3190 fs/exfat/dir.c:228

which lock already depends on the new lock.


the existing dependency chain (in reverse order) is:

-> #1 (&sbi->s_lock){+.+.}-{3:3}:
       lock_acquire+0x182/0x3c0 kernel/locking/lockdep.c:5668
       __mutex_lock_common+0x1bd/0x26e0 kernel/locking/mutex.c:603
       __mutex_lock kernel/locking/mutex.c:747 [inline]
       mutex_lock_nested+0x17/0x20 kernel/locking/mutex.c:799
       exfat_get_block+0x191/0x1e20 fs/exfat/inode.c:282
       do_mpage_readpage+0x970/0x1c50 fs/mpage.c:208
       mpage_readahead+0x210/0x380 fs/mpage.c:361
       read_pages+0x169/0x9c0 mm/readahead.c:161
       page_cache_ra_unbounded+0x703/0x820 mm/readahead.c:270
       page_cache_sync_readahead include/linux/pagemap.h:1213 [inline]
       filemap_get_pages+0x465/0x10d0 mm/filemap.c:2581
       filemap_read+0x3cf/0xea0 mm/filemap.c:2675
       __kernel_read+0x3fc/0x830 fs/read_write.c:428
       integrity_kernel_read+0xac/0xf0 security/integrity/iint.c:199
       ima_calc_file_hash_tfm security/integrity/ima/ima_crypto.c:485 [inline]
       ima_calc_file_shash security/integrity/ima/ima_crypto.c:516 [inline]
       ima_calc_file_hash+0x178f/0x1ca0 security/integrity/ima/ima_crypto.c:573
       ima_collect_measurement+0x444/0x8c0 security/integrity/ima/ima_api.c:292
       process_measurement+0xf4b/0x1bd0 security/integrity/ima/ima_main.c:337
       ima_file_check+0xd8/0x130 security/integrity/ima/ima_main.c:517
       do_open fs/namei.c:3559 [inline]
       path_openat+0x2642/0x2df0 fs/namei.c:3713
       do_filp_open+0x264/0x4f0 fs/namei.c:3740
       do_sys_openat2+0x124/0x4e0 fs/open.c:1310
       do_sys_open fs/open.c:1326 [inline]
       __do_sys_open fs/open.c:1334 [inline]
       __se_sys_open fs/open.c:1330 [inline]
       __x64_sys_open+0x221/0x270 fs/open.c:1330
       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

-> #0 (mapping.invalidate_lock#7){.+.+}-{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
       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:3127
       __do_fault+0x136/0x4f0 mm/memory.c:4203
       do_shared_fault mm/memory.c:4609 [inline]
       do_fault mm/memory.c:4687 [inline]
       handle_pte_fault mm/memory.c:4955 [inline]
       __handle_mm_fault mm/memory.c:5097 [inline]
       handle_mm_fault+0x1bca/0x3630 mm/memory.c:5218
       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
       filldir+0x2e8/0x670 fs/readdir.c:249
       dir_emit_dot include/linux/fs.h:3561 [inline]
       dir_emit_dots include/linux/fs.h:3572 [inline]
       exfat_iterate+0x2d3/0x3190 fs/exfat/dir.c:231
       iterate_dir+0x257/0x5f0
       __do_sys_getdents fs/readdir.c:286 [inline]
       __se_sys_getdents+0x1db/0x4d0 fs/readdir.c:271
       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:

 Possible unsafe locking scenario:

       CPU0                    CPU1
       ----                    ----
  lock(&sbi->s_lock);
                               lock(mapping.invalidate_lock#7);
                               lock(&sbi->s_lock);
  lock(mapping.invalidate_lock#7);

 *** DEADLOCK ***

4 locks held by syz-executor.3/10562:
 #0: ffff8880221a5268 (&f->f_pos_lock){+.+.}-{3:3}, at: __fdget_pos+0x242/0x2e0 fs/file.c:1037
 #1: ffff888031045db0 (&sb->s_type->i_mutex_key#24){++++}-{3:3}, at: iterate_dir+0x147/0x5f0 fs/readdir.c:57
 #2: ffff888077d8e0e0 (&sbi->s_lock){+.+.}-{3:3}, at: exfat_iterate+0x1c1/0x3190 fs/exfat/dir.c:228
 #3: ffff8880195ba598 (&mm->mmap_lock#2){++++}-{3:3}, at: mmap_read_trylock include/linux/mmap_lock.h:136 [inline]
 #3: ffff8880195ba598 (&mm->mmap_lock#2){++++}-{3:3}, at: do_user_addr_fault+0x2e2/0xcb0 arch/x86/mm/fault.c:1369

stack backtrace:
CPU: 1 PID: 10562 Comm: syz-executor.3 Not tainted 6.1.0-rc6-syzkaller-00012-g4312098baf37 #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/0x28e 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
 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:3127
 __do_fault+0x136/0x4f0 mm/memory.c:4203
 do_shared_fault mm/memory.c:4609 [inline]
 do_fault mm/memory.c:4687 [inline]
 handle_pte_fault mm/memory.c:4955 [inline]
 __handle_mm_fault mm/memory.c:5097 [inline]
 handle_mm_fault+0x1bca/0x3630 mm/memory.c:5218
 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
RIP: 0010:filldir+0x2e8/0x670 fs/readdir.c:253
Code: 24 10 e8 5b 98 97 ff 48 8b 4c 24 10 83 3c 24 00 0f 88 4c 02 00 00 48 39 cd 0f 82 43 02 00 00 0f 01 cb 0f ae e8 48 8b 44 24 60 <48> 89 41 08 e8 ef 95 97 ff 48 8b 44 24 20 49 89 45 00 e8 e1 95 97
RSP: 0018:ffffc90015807760 EFLAGS: 00050206
RAX: 0000000000000000 RBX: ffffffff8b06fe80 RCX: 0000000020000500
RDX: ffff888027081d40 RSI: 0000000020000500 RDI: 00007fffffffefe8
RBP: 00007fffffffefe8 R08: ffffffff81f30255 R09: 0000000000000004
R10: 0000000000000003 R11: ffff888027081d40 R12: dffffc0000000000
R13: 0000000020000500 R14: 0000000000000001 R15: ffffc90015807e70
 dir_emit_dot include/linux/fs.h:3561 [inline]
 dir_emit_dots include/linux/fs.h:3572 [inline]
 exfat_iterate+0x2d3/0x3190 fs/exfat/dir.c:231
 iterate_dir+0x257/0x5f0
 __do_sys_getdents fs/readdir.c:286 [inline]
 __se_sys_getdents+0x1db/0x4d0 fs/readdir.c:271
 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:0x7fa486c8c0d9
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:00007fa48799f168 EFLAGS: 00000246 ORIG_RAX: 000000000000004e
RAX: ffffffffffffffda RBX: 00007fa486dabf80 RCX: 00007fa486c8c0d9
RDX: 000000000000e807 RSI: 0000000020000500 RDI: 0000000000000004
RBP: 00007fa486ce7ae9 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
R13: 00007ffde6b35aff R14: 00007fa48799f300 R15: 0000000000022000
 </TASK>
----------------
Code disassembly (best guess):
   0:	24 10                	and    $0x10,%al
   2:	e8 5b 98 97 ff       	callq  0xff979862
   7:	48 8b 4c 24 10       	mov    0x10(%rsp),%rcx
   c:	83 3c 24 00          	cmpl   $0x0,(%rsp)
  10:	0f 88 4c 02 00 00    	js     0x262
  16:	48 39 cd             	cmp    %rcx,%rbp
  19:	0f 82 43 02 00 00    	jb     0x262
  1f:	0f 01 cb             	stac
  22:	0f ae e8             	lfence
  25:	48 8b 44 24 60       	mov    0x60(%rsp),%rax
* 2a:	48 89 41 08          	mov    %rax,0x8(%rcx) <-- trapping instruction
  2e:	e8 ef 95 97 ff       	callq  0xff979622
  33:	48 8b 44 24 20       	mov    0x20(%rsp),%rax
  38:	49 89 45 00          	mov    %rax,0x0(%r13)
  3c:	e8                   	.byte 0xe8
  3d:	e1 95                	loope  0xffffffd4
  3f:	97                   	xchg   %eax,%edi

Crashes (7):
Manager Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Title
ci2-upstream-fs 2022/11/24 09:30 upstream 4312098baf37 ff68ff8f .config log report info possible deadlock in filemap_fault
ci2-upstream-fs 2022/11/22 23:25 upstream eb7081409f94 9da37ae8 .config log report info possible deadlock in filemap_fault
ci2-upstream-fs 2022/11/22 03:16 upstream eb7081409f94 1c576c23 .config log report info possible deadlock in filemap_fault
ci2-upstream-fs 2022/11/17 19:51 upstream 81ac25651a62 4ba8ab94 .config log report info possible deadlock in filemap_fault
ci-upstream-gce-arm64 2022/11/19 09:47 git://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git for-kernelci 9500fc6e9e60 5bb70014 .config log report info possible deadlock in filemap_fault
ci-upstream-gce-arm64 2022/11/06 16:09 git://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git for-kernelci bbed346d5a96 6d752409 .config log report info possible deadlock in filemap_fault
ci-upstream-gce-arm64 2022/10/30 22:06 git://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git for-kernelci bbed346d5a96 2a71366b .config log report info possible deadlock in filemap_fault
* Struck through repros no longer work on HEAD.