syzbot


possible deadlock in vm_mmap_pgoff

Status: upstream: reported C repro on 2021/04/27 15:18
Reported-by: syzbot+f619f7c0a2a5f87694e6@syzkaller.appspotmail.com
First crash: 529d, last: 79d

Cause bisection: the issue happens on the oldest tested release (bisect log)
Crash: possible deadlock in vm_mmap_pgoff (log)
Repro: C syz .config

Fix bisection: the fix commit could be any of (bisect log):
  7d2a07b76933 Linux 5.14
  3cc40a443a04 Merge tag 'nios2_fixes_v6.0' of git://git.kernel.org/pub/scm/linux/kernel/git/dinguyen/linux
similar bugs (1):
Kernel Title Repro Cause bisect Fix bisect Count Last Reported Patched Status
linux-4.19 possible deadlock in vm_mmap_pgoff 4 423d 545d 0/1 auto-closed as invalid on 2021/12/02 20:13

Sample crash report:
======================================================
WARNING: possible circular locking dependency detected
5.14.0-syzkaller #0 Not tainted
------------------------------------------------------
syz-executor391/8677 is trying to acquire lock:
ffffffff8b9ed108 (event_mutex){+.+.}-{3:3}, at: perf_trace_destroy+0x23/0xf0 kernel/trace/trace_event_perf.c:241

but task is already holding lock:
ffff8880172642e8 (&mm->mmap_lock#2){++++}-{3:3}, at: mmap_write_lock_killable include/linux/mmap_lock.h:87 [inline]
ffff8880172642e8 (&mm->mmap_lock#2){++++}-{3:3}, at: vm_mmap_pgoff+0x15c/0x290 mm/util.c:517

which lock already depends on the new lock.


the existing dependency chain (in reverse order) is:

-> #3 (&mm->mmap_lock#2){++++}-{3:3}:
       down_write_killable+0x95/0x170 kernel/locking/rwsem.c:1417
       mmap_write_lock_killable include/linux/mmap_lock.h:87 [inline]
       dup_mmap kernel/fork.c:484 [inline]
       dup_mm+0x12e/0x1380 kernel/fork.c:1379
       copy_mm kernel/fork.c:1431 [inline]
       copy_process+0x71ec/0x74d0 kernel/fork.c:2119
       kernel_clone+0xe7/0xac0 kernel/fork.c:2509
       __do_sys_clone+0xc8/0x110 kernel/fork.c:2626
       do_syscall_x64 arch/x86/entry/common.c:50 [inline]
       do_syscall_64+0x35/0xb0 arch/x86/entry/common.c:80
       entry_SYSCALL_64_after_hwframe+0x44/0xae

-> #2 (dup_mmap_sem){++++}-{0:0}:
       percpu_down_write+0x4f/0x3e0 kernel/locking/percpu-rwsem.c:217
       register_for_each_vma+0x2c/0xc10 kernel/events/uprobes.c:1041
       __uprobe_register+0x5c2/0x850 kernel/events/uprobes.c:1182
       trace_uprobe_enable kernel/trace/trace_uprobe.c:1065 [inline]
       probe_event_enable+0x357/0x9f0 kernel/trace/trace_uprobe.c:1134
       trace_uprobe_register+0x443/0x880 kernel/trace/trace_uprobe.c:1461
       perf_trace_event_reg kernel/trace/trace_event_perf.c:129 [inline]
       perf_trace_event_init+0x549/0xa20 kernel/trace/trace_event_perf.c:204
       perf_uprobe_init+0x16f/0x210 kernel/trace/trace_event_perf.c:336
       perf_uprobe_event_init+0xff/0x1c0 kernel/events/core.c:9875
       perf_try_init_event+0x12a/0x560 kernel/events/core.c:11192
       perf_init_event kernel/events/core.c:11256 [inline]
       perf_event_alloc.part.0+0xf16/0x3b10 kernel/events/core.c:11547
       perf_event_alloc kernel/events/core.c:11970 [inline]
       __do_sys_perf_event_open+0x4ae/0x3130 kernel/events/core.c:12068
       do_syscall_x64 arch/x86/entry/common.c:50 [inline]
       do_syscall_64+0x35/0xb0 arch/x86/entry/common.c:80
       entry_SYSCALL_64_after_hwframe+0x44/0xae

-> #1 (&uprobe->register_rwsem){+.+.}-{3:3}:
       down_write+0x92/0x150 kernel/locking/rwsem.c:1406
       __uprobe_register+0x531/0x850 kernel/events/uprobes.c:1178
       trace_uprobe_enable kernel/trace/trace_uprobe.c:1065 [inline]
       probe_event_enable+0x357/0x9f0 kernel/trace/trace_uprobe.c:1134
       trace_uprobe_register+0x443/0x880 kernel/trace/trace_uprobe.c:1461
       perf_trace_event_reg kernel/trace/trace_event_perf.c:129 [inline]
       perf_trace_event_init+0x549/0xa20 kernel/trace/trace_event_perf.c:204
       perf_uprobe_init+0x16f/0x210 kernel/trace/trace_event_perf.c:336
       perf_uprobe_event_init+0xff/0x1c0 kernel/events/core.c:9875
       perf_try_init_event+0x12a/0x560 kernel/events/core.c:11192
       perf_init_event kernel/events/core.c:11256 [inline]
       perf_event_alloc.part.0+0xf16/0x3b10 kernel/events/core.c:11547
       perf_event_alloc kernel/events/core.c:11970 [inline]
       __do_sys_perf_event_open+0x4ae/0x3130 kernel/events/core.c:12068
       do_syscall_x64 arch/x86/entry/common.c:50 [inline]
       do_syscall_64+0x35/0xb0 arch/x86/entry/common.c:80
       entry_SYSCALL_64_after_hwframe+0x44/0xae

-> #0 (event_mutex){+.+.}-{3:3}:
       check_prev_add kernel/locking/lockdep.c:3051 [inline]
       check_prevs_add kernel/locking/lockdep.c:3174 [inline]
       validate_chain kernel/locking/lockdep.c:3789 [inline]
       __lock_acquire+0x2a07/0x54a0 kernel/locking/lockdep.c:5015
       lock_acquire kernel/locking/lockdep.c:5625 [inline]
       lock_acquire+0x1ab/0x510 kernel/locking/lockdep.c:5590
       __mutex_lock_common kernel/locking/mutex.c:959 [inline]
       __mutex_lock+0x12a/0x10a0 kernel/locking/mutex.c:1104
       perf_trace_destroy+0x23/0xf0 kernel/trace/trace_event_perf.c:241
       _free_event+0x2ee/0x1390 kernel/events/core.c:4959
       put_event kernel/events/core.c:5053 [inline]
       perf_mmap_close+0x540/0xe30 kernel/events/core.c:6098
       remove_vma+0xae/0x170 mm/mmap.c:186
       remove_vma_list mm/mmap.c:2656 [inline]
       __do_munmap+0x715/0x11c0 mm/mmap.c:2914
       do_munmap mm/mmap.c:2922 [inline]
       munmap_vma_range mm/mmap.c:604 [inline]
       mmap_region+0x85a/0x1760 mm/mmap.c:1753
       do_mmap+0x86e/0x1180 mm/mmap.c:1584
       vm_mmap_pgoff+0x1b7/0x290 mm/util.c:519
       ksys_mmap_pgoff+0x4a8/0x620 mm/mmap.c:1635
       do_syscall_x64 arch/x86/entry/common.c:50 [inline]
       do_syscall_64+0x35/0xb0 arch/x86/entry/common.c:80
       entry_SYSCALL_64_after_hwframe+0x44/0xae

other info that might help us debug this:

Chain exists of:
  event_mutex --> dup_mmap_sem --> &mm->mmap_lock#2

 Possible unsafe locking scenario:

       CPU0                    CPU1
       ----                    ----
  lock(&mm->mmap_lock#2);
                               lock(dup_mmap_sem);
                               lock(&mm->mmap_lock#2);
  lock(event_mutex);

 *** DEADLOCK ***

1 lock held by syz-executor391/8677:
 #0: ffff8880172642e8 (&mm->mmap_lock#2){++++}-{3:3}, at: mmap_write_lock_killable include/linux/mmap_lock.h:87 [inline]
 #0: ffff8880172642e8 (&mm->mmap_lock#2){++++}-{3:3}, at: vm_mmap_pgoff+0x15c/0x290 mm/util.c:517

stack backtrace:
CPU: 0 PID: 8677 Comm: syz-executor391 Not tainted 5.14.0-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
Call Trace:
 __dump_stack lib/dump_stack.c:88 [inline]
 dump_stack_lvl+0xcd/0x134 lib/dump_stack.c:105
 check_noncircular+0x25f/0x2e0 kernel/locking/lockdep.c:2131
 check_prev_add kernel/locking/lockdep.c:3051 [inline]
 check_prevs_add kernel/locking/lockdep.c:3174 [inline]
 validate_chain kernel/locking/lockdep.c:3789 [inline]
 __lock_acquire+0x2a07/0x54a0 kernel/locking/lockdep.c:5015
 lock_acquire kernel/locking/lockdep.c:5625 [inline]
 lock_acquire+0x1ab/0x510 kernel/locking/lockdep.c:5590
 __mutex_lock_common kernel/locking/mutex.c:959 [inline]
 __mutex_lock+0x12a/0x10a0 kernel/locking/mutex.c:1104
 perf_trace_destroy+0x23/0xf0 kernel/trace/trace_event_perf.c:241
 _free_event+0x2ee/0x1390 kernel/events/core.c:4959
 put_event kernel/events/core.c:5053 [inline]
 perf_mmap_close+0x540/0xe30 kernel/events/core.c:6098
 remove_vma+0xae/0x170 mm/mmap.c:186
 remove_vma_list mm/mmap.c:2656 [inline]
 __do_munmap+0x715/0x11c0 mm/mmap.c:2914
 do_munmap mm/mmap.c:2922 [inline]
 munmap_vma_range mm/mmap.c:604 [inline]
 mmap_region+0x85a/0x1760 mm/mmap.c:1753
 do_mmap+0x86e/0x1180 mm/mmap.c:1584
 vm_mmap_pgoff+0x1b7/0x290 mm/util.c:519
 ksys_mmap_pgoff+0x4a8/0x620 mm/mmap.c:1635
 do_syscall_x64 arch/x86/entry/common.c:50 [inline]
 do_syscall_64+0x35/0xb0 arch/x86/entry/common.c:80
 entry_SYSCALL_64_after_hwframe+0x44/0xae
RIP: 0033:0x453bf9
Code: 28 00 00 00 75 05 48 83 c4 28 c3 e8 91 18 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 bc ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007f10392621f8 EFLAGS: 00000246 ORIG_RAX: 0000000000000009
RAX: ffffffffffffffda RBX: 00000000004d24e8 RCX: 0000000000453bf9
RDX: 0000000000000000 RSI: 0000000000003000 RDI: 0000000020ffc000
RBP: 00000000004d24e0 R08: 0000000000000005 R09: 0000000000000000
R10: 0000000000000011 R11: 0000000000000246 R12: 00000000004d24ec
R13: 00007ffe172fb3ef R14: 00007f1039262300 R15: 0000000000022000

Crashes (8):
Manager Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Title
ci-upstream-kasan-gce-selinux-root 2021/08/31 09:40 upstream 7d2a07b76933 8f58a0ef .config log report syz C possible deadlock in vm_mmap_pgoff
ci-upstream-kasan-gce-smack-root 2021/07/23 15:15 upstream 9bead1b58c4c bc5f1d88 .config log report syz C possible deadlock in vm_mmap_pgoff
ci-upstream-kasan-gce-root 2021/10/17 04:18 upstream 304040fb4909 0c5d9412 .config log report info possible deadlock in vm_mmap_pgoff
ci-upstream-kasan-gce-smack-root 2021/09/25 12:16 upstream 7d42e9818258 8cac236e .config log report info possible deadlock in vm_mmap_pgoff
ci-upstream-kasan-gce-smack-root 2021/09/25 08:31 upstream 4c4f0c2bf341 8cac236e .config log report info possible deadlock in vm_mmap_pgoff
ci-upstream-kasan-gce-smack-root 2021/09/24 22:43 upstream 4c4f0c2bf341 8cac236e .config log report info possible deadlock in vm_mmap_pgoff
ci-upstream-kasan-gce-smack-root 2021/09/24 21:29 upstream 4c4f0c2bf341 8cac236e .config log report info possible deadlock in vm_mmap_pgoff
ci-qemu-upstream 2021/04/20 10:31 upstream 7af08140979a c0ced557 .config log report info possible deadlock in vm_mmap_pgoff
* Struck through repros no longer work on HEAD.