syzbot


possible deadlock in lock_vma

Status: upstream: reported C repro on 2024/02/16 06:07
Subsystems: mm
[Documentation on labels]
Reported-by: syzbot+27f783f9d240834c9d44@syzkaller.appspotmail.com
First crash: 61d, last: 60d
Cause bisection: introduced by (bisect log) :
commit 31d97016c80a83daa4c938014c81282810a14773
Author: Lokesh Gidra <lokeshgidra@google.com>
Date: Thu Feb 8 21:22:04 2024 +0000

  userfaultfd: use per-vma locks in userfaultfd operations

Crash: possible deadlock in lock_vma (log)
Repro: C syz .config
  
Discussions (1)
Title Replies (including bot) Last reply
[syzbot] [mm?] possible deadlock in lock_vma 0 (1) 2024/02/16 06:07
Last patch testing requests (1)
Created Duration User Patch Repo Result
2024/02/28 06:50 23m retest repro linux-next error OK

Sample crash report:
======================================================
WARNING: possible circular locking dependency detected
6.8.0-rc4-next-20240212-syzkaller #0 Not tainted
------------------------------------------------------
syz-executor800/5064 is trying to acquire lock:
ffff888021d401a0 (&mm->mmap_lock){++++}-{3:3}, at: mmap_read_lock include/linux/mmap_lock.h:146 [inline]
ffff888021d401a0 (&mm->mmap_lock){++++}-{3:3}, at: lock_vma+0xc5/0x260 mm/userfaultfd.c:73

but task is already holding lock:
ffff88802b989730 (&vma->vm_lock->lock){++++}-{3:3}, at: lock_vma+0x1a1/0x260 mm/userfaultfd.c:87

which lock already depends on the new lock.


the existing dependency chain (in reverse order) is:

-> #1 (&vma->vm_lock->lock){++++}-{3:3}:
       lock_acquire+0x1e4/0x530 kernel/locking/lockdep.c:5754
       down_write+0x3a/0x50 kernel/locking/rwsem.c:1579
       vma_start_write include/linux/mm.h:716 [inline]
       vma_link+0x2c6/0x550 mm/mmap.c:416
       insert_vm_struct+0x1a3/0x260 mm/mmap.c:3331
       __bprm_mm_init fs/exec.c:282 [inline]
       bprm_mm_init fs/exec.c:384 [inline]
       alloc_bprm+0x543/0xa00 fs/exec.c:1579
       kernel_execve+0x99/0xa10 fs/exec.c:2008
       try_to_run_init_process init/main.c:1361 [inline]
       kernel_init+0xe8/0x2b0 init/main.c:1488
       ret_from_fork+0x4b/0x80 arch/x86/kernel/process.c:147
       ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:242

-> #0 (&mm->mmap_lock){++++}-{3:3}:
       check_prev_add kernel/locking/lockdep.c:3134 [inline]
       check_prevs_add kernel/locking/lockdep.c:3253 [inline]
       validate_chain+0x18cb/0x58e0 kernel/locking/lockdep.c:3869
       __lock_acquire+0x1346/0x1fd0 kernel/locking/lockdep.c:5137
       lock_acquire+0x1e4/0x530 kernel/locking/lockdep.c:5754
       down_read+0xb1/0xa40 kernel/locking/rwsem.c:1526
       mmap_read_lock include/linux/mmap_lock.h:146 [inline]
       lock_vma+0xc5/0x260 mm/userfaultfd.c:73
       find_and_lock_vmas mm/userfaultfd.c:1405 [inline]
       move_pages+0x18c/0xff0 mm/userfaultfd.c:1546
       userfaultfd_move fs/userfaultfd.c:2008 [inline]
       userfaultfd_ioctl+0x5c10/0x72c0 fs/userfaultfd.c:2126
       vfs_ioctl fs/ioctl.c:51 [inline]
       __do_sys_ioctl fs/ioctl.c:871 [inline]
       __se_sys_ioctl+0xfc/0x170 fs/ioctl.c:857
       do_syscall_64+0xfb/0x240
       entry_SYSCALL_64_after_hwframe+0x6d/0x75

other info that might help us debug this:

 Possible unsafe locking scenario:

       CPU0                    CPU1
       ----                    ----
  rlock(&vma->vm_lock->lock);
                               lock(&mm->mmap_lock);
                               lock(&vma->vm_lock->lock);
  rlock(&mm->mmap_lock);

 *** DEADLOCK ***

1 lock held by syz-executor800/5064:
 #0: ffff88802b989730 (&vma->vm_lock->lock){++++}-{3:3}, at: lock_vma+0x1a1/0x260 mm/userfaultfd.c:87

stack backtrace:
CPU: 1 PID: 5064 Comm: syz-executor800 Not tainted 6.8.0-rc4-next-20240212-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/25/2024
Call Trace:
 <TASK>
 __dump_stack lib/dump_stack.c:88 [inline]
 dump_stack_lvl+0x241/0x360 lib/dump_stack.c:114
 check_noncircular+0x36a/0x4a0 kernel/locking/lockdep.c:2187
 check_prev_add kernel/locking/lockdep.c:3134 [inline]
 check_prevs_add kernel/locking/lockdep.c:3253 [inline]
 validate_chain+0x18cb/0x58e0 kernel/locking/lockdep.c:3869
 __lock_acquire+0x1346/0x1fd0 kernel/locking/lockdep.c:5137
 lock_acquire+0x1e4/0x530 kernel/locking/lockdep.c:5754
 down_read+0xb1/0xa40 kernel/locking/rwsem.c:1526
 mmap_read_lock include/linux/mmap_lock.h:146 [inline]
 lock_vma+0xc5/0x260 mm/userfaultfd.c:73
 find_and_lock_vmas mm/userfaultfd.c:1405 [inline]
 move_pages+0x18c/0xff0 mm/userfaultfd.c:1546
 userfaultfd_move fs/userfaultfd.c:2008 [inline]
 userfaultfd_ioctl+0x5c10/0x72c0 fs/userfaultfd.c:2126
 vfs_ioctl fs/ioctl.c:51 [inline]
 __do_sys_ioctl fs/ioctl.c:871 [inline]
 __se_sys_ioctl+0xfc/0x170 fs/ioctl.c:857
 do_syscall_64+0xfb/0x240
 entry_SYSCALL_64_after_hwframe+0x6d/0x75
RIP: 0033:0x7f86fc35f329
Code: 48 83 c4 28 c3 e8 37 17 00 00 0f 1f 80 00 00 00 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 b8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007ffd53428e38 EFLAGS: 00000246 ORIG_RAX: 0000000000000010
RAX: ffffffffffffffda RBX: 00007ffd53429008 RCX: 00007f86fc35f329
RDX: 0000000020000040 RSI: 00000000c028aa05 RDI: 

Crashes (18):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2024/02/12 08:33 linux-next ae00c445390b 77b23aa1 .config strace log report syz C [disk image] [vmlinux] [kernel image] ci-upstream-linux-next-kasan-gce-root possible deadlock in lock_vma
2024/02/14 02:38 linux-next 46d4e2eb58e1 d902085f .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-linux-next-kasan-gce-root possible deadlock in lock_vma
2024/02/14 01:06 linux-next 46d4e2eb58e1 d902085f .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-linux-next-kasan-gce-root possible deadlock in lock_vma
2024/02/13 14:33 linux-next 46d4e2eb58e1 e66542d7 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-linux-next-kasan-gce-root possible deadlock in lock_vma
2024/02/13 12:43 linux-next 46d4e2eb58e1 e66542d7 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-linux-next-kasan-gce-root possible deadlock in lock_vma
2024/02/13 11:23 linux-next 46d4e2eb58e1 77b23aa1 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-linux-next-kasan-gce-root possible deadlock in lock_vma
2024/02/13 07:56 linux-next 46d4e2eb58e1 77b23aa1 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-linux-next-kasan-gce-root possible deadlock in lock_vma
2024/02/13 07:15 linux-next 46d4e2eb58e1 77b23aa1 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-linux-next-kasan-gce-root possible deadlock in lock_vma
2024/02/13 06:32 linux-next 46d4e2eb58e1 77b23aa1 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-linux-next-kasan-gce-root possible deadlock in lock_vma
2024/02/13 05:54 linux-next 46d4e2eb58e1 77b23aa1 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-linux-next-kasan-gce-root possible deadlock in lock_vma
2024/02/12 08:10 linux-next ae00c445390b 77b23aa1 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-linux-next-kasan-gce-root possible deadlock in lock_vma
2024/02/12 08:05 linux-next ae00c445390b 77b23aa1 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-linux-next-kasan-gce-root possible deadlock in lock_vma
2024/02/12 07:32 linux-next ae00c445390b 77b23aa1 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-linux-next-kasan-gce-root possible deadlock in lock_vma
2024/02/12 07:25 linux-next ae00c445390b 77b23aa1 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-linux-next-kasan-gce-root possible deadlock in lock_vma
2024/02/12 06:55 linux-next ae00c445390b 77b23aa1 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-linux-next-kasan-gce-root possible deadlock in lock_vma
2024/02/12 06:38 linux-next ae00c445390b 77b23aa1 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-linux-next-kasan-gce-root possible deadlock in lock_vma
2024/02/12 06:37 linux-next ae00c445390b 77b23aa1 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-linux-next-kasan-gce-root possible deadlock in lock_vma
2024/02/12 05:55 linux-next ae00c445390b 77b23aa1 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-linux-next-kasan-gce-root possible deadlock in lock_vma
* Struck through repros no longer work on HEAD.