syzbot


possible deadlock in upgrade_mmap_lock_carefully (2)

Status: upstream: reported on 2025/07/08 05:57
Reported-by: syzbot+45163dde81b64236e72d@syzkaller.appspotmail.com
First crash: 8d05h, last: 8d05h
Similar bugs (3)
Kernel Title Rank 🛈 Repro Cause bisect Fix bisect Count Last Reported Patched Status
upstream possible deadlock in upgrade_mmap_lock_carefully (2) ntfs3 mm 4 C error 6 20d 37d 0/29 upstream: reported C repro on 2025/06/08 15:34
upstream possible deadlock in upgrade_mmap_lock_carefully mm 4 C done 30 259d 290d 0/29 closed as dup on 2024/10/03 02:52
linux-6.1 possible deadlock in upgrade_mmap_lock_carefully 4 13 118d 211d 0/3 auto-obsoleted due to no activity on 2025/06/28 07:47

Sample crash report:
======================================================
WARNING: possible circular locking dependency detected
6.1.143-syzkaller #0 Not tainted
------------------------------------------------------
syz.0.29/4479 is trying to acquire lock:
ffff88807bfee2d8 (&mm->mmap_lock){++++}-{3:3}, at: mmap_write_lock_killable include/linux/mmap_lock.h:87 [inline]
ffff88807bfee2d8 (&mm->mmap_lock){++++}-{3:3}, at: upgrade_mmap_lock_carefully+0xbb/0x140 mm/memory.c:5357

but task is already holding lock:
ffff888075015af0 (&sb->s_type->i_mutex_key#12){+.+.}-{3:3}, at: inode_lock include/linux/fs.h:758 [inline]
ffff888075015af0 (&sb->s_type->i_mutex_key#12){+.+.}-{3:3}, at: generic_file_write_iter+0x7f/0x2e0 mm/filemap.c:4003

which lock already depends on the new lock.


the existing dependency chain (in reverse order) is:

-> #1 (&sb->s_type->i_mutex_key#12){+.+.}-{3:3}:
       down_write+0x36/0x60 kernel/locking/rwsem.c:1573
       inode_lock include/linux/fs.h:758 [inline]
       process_measurement+0x33c/0x1a10 security/integrity/ima/ima_main.c:242
       ima_file_mmap+0x104/0x150 security/integrity/ima/ima_main.c:429
       __do_sys_remap_file_pages mm/mmap.c:3032 [inline]
       __se_sys_remap_file_pages+0x53e/0x770 mm/mmap.c:2964
       do_syscall_x64 arch/x86/entry/common.c:51 [inline]
       do_syscall_64+0x4c/0xa0 arch/x86/entry/common.c:81
       entry_SYSCALL_64_after_hwframe+0x68/0xd2

-> #0 (&mm->mmap_lock){++++}-{3:3}:
       check_prev_add kernel/locking/lockdep.c:3090 [inline]
       check_prevs_add kernel/locking/lockdep.c:3209 [inline]
       validate_chain kernel/locking/lockdep.c:3825 [inline]
       __lock_acquire+0x2cf8/0x7c50 kernel/locking/lockdep.c:5049
       lock_acquire+0x1b4/0x490 kernel/locking/lockdep.c:5662
       down_write_killable+0x45/0x90 kernel/locking/rwsem.c:1584
       mmap_write_lock_killable include/linux/mmap_lock.h:87 [inline]
       upgrade_mmap_lock_carefully+0xbb/0x140 mm/memory.c:5357
       lock_mm_and_find_vma+0x117/0x2f0 mm/memory.c:5410
       do_user_addr_fault+0x2db/0xb10 arch/x86/mm/fault.c:1312
       handle_page_fault arch/x86/mm/fault.c:1431 [inline]
       exc_page_fault+0x60/0x100 arch/x86/mm/fault.c:1487
       asm_exc_page_fault+0x22/0x30 arch/x86/include/asm/idtentry.h:608
       fault_in_readable+0x13e/0x1f0 mm/gup.c:1914
       fault_in_iov_iter_readable+0x18e/0x2e0 lib/iov_iter.c:370
       generic_perform_write+0x1d2/0x560 mm/filemap.c:3836
       __generic_file_write_iter+0x172/0x430 mm/filemap.c:3974
       generic_file_write_iter+0xab/0x2e0 mm/filemap.c:4006
       do_iter_readv_writev fs/read_write.c:-1 [inline]
       do_iter_write+0x62d/0xaf0 fs/read_write.c:861
       vfs_writev fs/read_write.c:934 [inline]
       do_pwritev+0x201/0x340 fs/read_write.c:1031
       do_syscall_x64 arch/x86/entry/common.c:51 [inline]
       do_syscall_64+0x4c/0xa0 arch/x86/entry/common.c:81
       entry_SYSCALL_64_after_hwframe+0x68/0xd2

other info that might help us debug this:

 Possible unsafe locking scenario:

       CPU0                    CPU1
       ----                    ----
  lock(&sb->s_type->i_mutex_key#12);
                               lock(&mm->mmap_lock);
                               lock(&sb->s_type->i_mutex_key#12);
  lock(&mm->mmap_lock);

 *** DEADLOCK ***

2 locks held by syz.0.29/4479:
 #0: ffff888075d02460 (sb_writers#5){.+.+}-{0:0}, at: vfs_writev fs/read_write.c:933 [inline]
 #0: ffff888075d02460 (sb_writers#5){.+.+}-{0:0}, at: do_pwritev+0x1ef/0x340 fs/read_write.c:1031
 #1: ffff888075015af0 (&sb->s_type->i_mutex_key#12){+.+.}-{3:3}, at: inode_lock include/linux/fs.h:758 [inline]
 #1: ffff888075015af0 (&sb->s_type->i_mutex_key#12){+.+.}-{3:3}, at: generic_file_write_iter+0x7f/0x2e0 mm/filemap.c:4003

stack backtrace:
CPU: 1 PID: 4479 Comm: syz.0.29 Not tainted 6.1.143-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 05/07/2025
Call Trace:
 <TASK>
 dump_stack_lvl+0x168/0x22e lib/dump_stack.c:106
 check_noncircular+0x274/0x310 kernel/locking/lockdep.c:2170
 check_prev_add kernel/locking/lockdep.c:3090 [inline]
 check_prevs_add kernel/locking/lockdep.c:3209 [inline]
 validate_chain kernel/locking/lockdep.c:3825 [inline]
 __lock_acquire+0x2cf8/0x7c50 kernel/locking/lockdep.c:5049
 lock_acquire+0x1b4/0x490 kernel/locking/lockdep.c:5662
 down_write_killable+0x45/0x90 kernel/locking/rwsem.c:1584
 mmap_write_lock_killable include/linux/mmap_lock.h:87 [inline]
 upgrade_mmap_lock_carefully+0xbb/0x140 mm/memory.c:5357
 lock_mm_and_find_vma+0x117/0x2f0 mm/memory.c:5410
 do_user_addr_fault+0x2db/0xb10 arch/x86/mm/fault.c:1312
 handle_page_fault arch/x86/mm/fault.c:1431 [inline]
 exc_page_fault+0x60/0x100 arch/x86/mm/fault.c:1487
 asm_exc_page_fault+0x22/0x30 arch/x86/include/asm/idtentry.h:608
RIP: 0010:fault_in_readable+0x13e/0x1f0 mm/gup.c:1915
Code: 48 8c c3 ff 4d 89 f4 49 81 cc ff 0f 00 00 4d 89 f7 49 01 dc 49 81 e4 00 f0 ff ff 4d 39 e6 77 44 e8 27 8c c3 ff 4d 39 e7 74 47 <41> 8a 07 88 44 24 07 49 81 c7 00 10 00 00 4d 39 e7 74 07 e8 0a 8c
RSP: 0018:ffffc90004ebf970 EFLAGS: 00050287
RAX: ffffffff81bd4b59 RBX: 0000000000001000 RCX: 0000000000080000
RDX: ffffc90005679000 RSI: 0000000000000189 RDI: 000000000000018a
RBP: 0000000000000000 R08: ffff88801a32bb80 R09: 0000000000000002
R10: 0000000000000006 R11: 0000000000000002 R12: 0000200000002000
R13: 0000000000001000 R14: 0000200000000205 R15: 0000200000001000
 fault_in_iov_iter_readable+0x18e/0x2e0 lib/iov_iter.c:370
 generic_perform_write+0x1d2/0x560 mm/filemap.c:3836
 __generic_file_write_iter+0x172/0x430 mm/filemap.c:3974
 generic_file_write_iter+0xab/0x2e0 mm/filemap.c:4006
 do_iter_readv_writev fs/read_write.c:-1 [inline]
 do_iter_write+0x62d/0xaf0 fs/read_write.c:861
 vfs_writev fs/read_write.c:934 [inline]
 do_pwritev+0x201/0x340 fs/read_write.c:1031
 do_syscall_x64 arch/x86/entry/common.c:51 [inline]
 do_syscall_64+0x4c/0xa0 arch/x86/entry/common.c:81
 entry_SYSCALL_64_after_hwframe+0x68/0xd2
RIP: 0033:0x7f82f4d8e929
Code: ff ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 40 00 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 a8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007f82f4bff038 EFLAGS: 00000246 ORIG_RAX: 0000000000000148
RAX: ffffffffffffffda RBX: 00007f82f4fb5fa0 RCX: 00007f82f4d8e929
RDX: 0000000000000001 RSI: 00002000000001c0 RDI: 0000000000000003
RBP: 00007f82f4e10b39 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000e7b R11: 0000000000000246 R12: 0000000000000000
R13: 0000000000000000 R14: 00007f82f4fb5fa0 R15: 00007ffdb42254f8
 </TASK>
----------------
Code disassembly (best guess):
   0:	48 8c c3             	mov    %es,%rbx
   3:	ff 4d 89             	decl   -0x77(%rbp)
   6:	f4                   	hlt
   7:	49 81 cc ff 0f 00 00 	or     $0xfff,%r12
   e:	4d 89 f7             	mov    %r14,%r15
  11:	49 01 dc             	add    %rbx,%r12
  14:	49 81 e4 00 f0 ff ff 	and    $0xfffffffffffff000,%r12
  1b:	4d 39 e6             	cmp    %r12,%r14
  1e:	77 44                	ja     0x64
  20:	e8 27 8c c3 ff       	call   0xffc38c4c
  25:	4d 39 e7             	cmp    %r12,%r15
  28:	74 47                	je     0x71
* 2a:	41 8a 07             	mov    (%r15),%al <-- trapping instruction
  2d:	88 44 24 07          	mov    %al,0x7(%rsp)
  31:	49 81 c7 00 10 00 00 	add    $0x1000,%r15
  38:	4d 39 e7             	cmp    %r12,%r15
  3b:	74 07                	je     0x44
  3d:	e8                   	.byte 0xe8
  3e:	0a                   	.byte 0xa
  3f:	8c                   	.byte 0x8c

Crashes (1):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2025/07/08 05:56 linux-6.1.y 04d1ccaa9c28 4f67c4ae .config console log report info [disk image] [vmlinux] [kernel image] ci2-linux-6-1-kasan possible deadlock in upgrade_mmap_lock_carefully
* Struck through repros no longer work on HEAD.