From nobody Tue Apr 7 04:42:32 2026 Received: from xmbghk7.mail.qq.com (xmbghk7.mail.qq.com [43.163.128.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4F3E72DC767 for ; Mon, 16 Mar 2026 03:11:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=43.163.128.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773630678; cv=none; b=fOCxz68xdGYgD2DPyaZQGLflCb9ZzFgGTLsZ74Dzb6BsSWsSlVF7x7XX/HaOlynpBEgBoPm/XFLheDl/ty1GJkbQNfoj9hjWajkO+RK0ZKf6TmmyyVV65bUh/HR1i7KV5/7/EM53shKm5ZW0Fxr3giPQiLYeoHoB9e3psMreglk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773630678; c=relaxed/simple; bh=V3ki2q4aeWjLbsbhyKimhEJhbKaqUB3No9RNvypA4VQ=; h=Message-ID:From:To:Cc:Subject:Date:In-Reply-To:References: MIME-Version; b=caCp6c0FVPjFUBdx5cUhG5Mc+MWNoWwtawYx1LjYEV+Okq6cUvCXtf3nxflz+6DVsf3N8fEUNNFK6A5AwKsp0UkKwBpK8uBLtzv0vsfoC/WgHzhtxS7SEel2UhJMhWN6TlDIfCCBgHtmCXdVqZn8ezPml7qC+odgeg3+k6tU+mY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=qq.com; spf=pass smtp.mailfrom=qq.com; dkim=pass (1024-bit key) header.d=qq.com header.i=@qq.com header.b=Yu1LUMKn; arc=none smtp.client-ip=43.163.128.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=qq.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=qq.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=qq.com header.i=@qq.com header.b="Yu1LUMKn" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qq.com; s=s201512; t=1773630666; bh=VsExrWsQ3TdTm+Z66cknxvj6Y+enEEHRqpyOaJkvHxQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Yu1LUMKnJ8SLXnELcv521mJlQFprPngfkEAW/bJkSXmyy1hj8GC0rsn6G48c1UqUJ QB6ix8kS55+PoHM/KZjKL6O40MQw/AA4bZ2XoMENVyOYqxkD1QBabYonJ0/08AFUlj tW39reMY7+UEHisadImcocI2n8/JH+Z9MXcIGQX4= Received: from lxu-ped-host.. ([111.198.231.89]) by newxmesmtplogicsvrsza53-0.qq.com (NewEsmtp) with SMTP id 2C38265B; Mon, 16 Mar 2026 11:11:03 +0800 X-QQ-mid: xmsmtpt1773630663t7uxyew6v Message-ID: X-QQ-XMAILINFO: OYPw5v5I6lYzdd5v/VRKtjyLCIvI18eJBRu5n2hBgKUeG6obNoBooEPKfrI0zJ PLYqlPtlCgI6msCfUlsOT90JmaPWTec/99lipqINpmAI7jYHESGYhkdAEIVZ7cBGUXn0DGGeJu4d BAzMAwiuGJl0GSSX/dldSX1pyyx8iFmp/mzrg1QO3apEQzecZ19loj75cChR2MLqH+a/NroEehJU xV3vkfwrtrGAgfNRmpFmk2U4/sVUdJ0Gg4pn8UJW6wXzxZPjbQhHo/f+VMQ+k/YpyByuJSzmVjlp h5C+odIf16X4H2TzIFqH4Q4OqAvUCFcvAv0ojo62KZR8nFCxzJ2T6MN7boYdV7+DfiGa3iyuP/rt pLMlenwZwbGCK6RBGnWrQ/0JDEqzI591N1JEd8zlIfo2z9wDEK0BKHL9iga+RS9o+gnHHqN+BkSj p4uV6VcqffC36eUYNqHFYFmevq5rMcsiLYmFWSD0f3qhnG9lOp93iJ3IbrxAdDbTnbTQEjqzM739 ycdi/QQqbEw7uuYI4dDf8uCOyLTNp4MdfyEKGlpjywtvumH1qYtUdwh4McDdfocIHTFoJbJgJdGz 9Y3J9r/S31SrbBEkLYRCkV8pektpou16iOULjvuLdKMKr2hkxG5CJWelivIPfq8D6dPYPOPSmjPN XTDUy1jnObL2B6EBUeepRNFJbLmT1dkXAi5xNePWudlF5sa97uMjrs1V/grjZ4/Z5OvMsLPju66f +zPzid1rwjYJ8t+iDo6NO2X8lfAQtRoyWSdIusu2P+PezBE5dz+kyx+vNjYO1kZNV7URqQ0yBMM8 cpxWMAEhQCH/wB5YePiQax6qkyp5/1icYyIFpTD09vrUHR0G3JVFdRo8A35M5BM5aHSxsKD4riwK FikfvTqSdixMRqeDhdsUCZvGCGnLajpKRh+X1Dw5f75G0Uuypyk4t1ap7GL+lOZsc6/lFtAdCbmX 2BkX4qxjh+OwTeZ7lhWg8Q0AwkCPpkSWLTYlUipg2s3DpXDNhHU1eIo2SYxWkAOOPgfizPhb4= X-QQ-XMRINFO: NI4Ajvh11aEjEMj13RCX7UuhPEoou2bs1g== From: Edward Adam Davis To: syzbot+c473aa669b5e8a6f48d2@syzkaller.appspotmail.com Cc: akpm@linux-foundation.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, peterx@redhat.com, rppt@kernel.org, syzkaller-bugs@googlegroups.com Subject: [PATCH next] userfaultfd: unassigned vma leads to a potential unreleased locks Date: Mon, 16 Mar 2026 11:11:03 +0800 X-OQ-MSGID: <20260316031102.126301-2-eadavis@qq.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <69b6fc68.a00a0220.3b25d1.001e.GAE@google.com> References: <69b6fc68.a00a0220.3b25d1.001e.GAE@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" A deadlock [1] occurs in mfill_get_vma() because the locks mmap_lock and map_changing_lock are not released; the failure to release them properly stems from the assignment of the vma variable occurring at an inappropriate stage. Moving the vma assignment operation within mfill_get_vma() to after the vma has been got. [1] WARNING: possible circular locking dependency detected syzkaller #0 Not tainted Reported-by: syzbot+c473aa669b5e8a6f48d2@syzkaller.appspotmail.com Tested-by: syzbot+c473aa669b5e8a6f48d2@syzkaller.appspotmail.com ------------------------------------------------------ syz.0.17/5990 is trying to acquire lock: ffff88802caef3b8 (&mm->mmap_lock){++++}-{4:4}, at: __might_fault+0xaf/0x130= mm/memory.c:7249 but task is already holding lock: ffff88807cdbccf0 (&ctx->map_changing_lock){.+.+}-{4:4}, at: mfill_get_vma+0= x162/0x660 mm/userfaultfd.c:226 which lock already depends on the new lock. the existing dependency chain (in reverse order) is: -> #2 (&ctx->map_changing_lock){.+.+}-{4:4}: down_read+0x47/0x2e0 kernel/locking/rwsem.c:1568 mfill_get_vma+0x162/0x660 mm/userfaultfd.c:226 mfill_atomic mm/userfaultfd.c:900 [inline] mfill_atomic_continue+0x189/0x12c0 mm/userfaultfd.c:974 userfaultfd_continue fs/userfaultfd.c:1806 [inline] userfaultfd_ioctl+0x232d/0x4c70 fs/userfaultfd.c:2071 vfs_ioctl fs/ioctl.c:51 [inline] __do_sys_ioctl fs/ioctl.c:597 [inline] __se_sys_ioctl+0xfc/0x170 fs/ioctl.c:583 do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline] do_syscall_64+0x14d/0xf80 arch/x86/entry/syscall_64.c:94 entry_SYSCALL_64_after_hwframe+0x77/0x7f -> #1 (vm_lock){++++}-{0:0}: __vma_start_exclude_readers+0x28a/0x940 mm/mmap_lock.c:125 __vma_start_write+0xdc/0x290 mm/mmap_lock.c:148 vma_start_write include/linux/mmap_lock.h:303 [inline] mprotect_fixup+0x5eb/0xa80 mm/mprotect.c:768 setup_arg_pages+0x565/0xac0 fs/exec.c:670 load_elf_binary+0xc5e/0x2980 fs/binfmt_elf.c:1029 search_binary_handler fs/exec.c:1664 [inline] exec_binprm fs/exec.c:1696 [inline] bprm_execve+0x949/0x1470 fs/exec.c:1748 kernel_execve+0x844/0x930 fs/exec.c:1892 try_to_run_init_process+0x13/0x60 init/main.c:1514 kernel_init+0xad/0x1d0 init/main.c:1642 ret_from_fork+0x51e/0xb90 arch/x86/kernel/process.c:158 ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:245 -> #0 (&mm->mmap_lock){++++}-{4:4}: check_prev_add kernel/locking/lockdep.c:3165 [inline] check_prevs_add kernel/locking/lockdep.c:3284 [inline] validate_chain kernel/locking/lockdep.c:3908 [inline] __lock_acquire+0x15a5/0x2cf0 kernel/locking/lockdep.c:5237 lock_acquire+0xf0/0x2e0 kernel/locking/lockdep.c:5868 __might_fault+0xcb/0x130 mm/memory.c:7249 userfaultfd_continue fs/userfaultfd.c:1813 [inline] userfaultfd_ioctl+0x2372/0x4c70 fs/userfaultfd.c:2071 vfs_ioctl fs/ioctl.c:51 [inline] __do_sys_ioctl fs/ioctl.c:597 [inline] __se_sys_ioctl+0xfc/0x170 fs/ioctl.c:583 do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline] do_syscall_64+0x14d/0xf80 arch/x86/entry/syscall_64.c:94 entry_SYSCALL_64_after_hwframe+0x77/0x7f other info that might help us debug this: Chain exists of: &mm->mmap_lock --> vm_lock --> &ctx->map_changing_lock Possible unsafe locking scenario: CPU0 CPU1 ---- ---- rlock(&ctx->map_changing_lock); lock(vm_lock); lock(&ctx->map_changing_lock); rlock(&mm->mmap_lock); *** DEADLOCK *** Fixes: 7d4d4de3ac3e ("userfaultfd: introduce mfill_get_vma() and mfill_put_= vma()") Reported-by: syzbot+c473aa669b5e8a6f48d2@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=3Dc473aa669b5e8a6f48d2 Tested-by: syzbot+c473aa669b5e8a6f48d2@syzkaller.appspotmail.com Signed-off-by: Edward Adam Davis --- mm/userfaultfd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c index 9ffc80d0a51b..a3333d5c6454 100644 --- a/mm/userfaultfd.c +++ b/mm/userfaultfd.c @@ -218,6 +218,7 @@ static int mfill_get_vma(struct mfill_state *state) if (IS_ERR(dst_vma)) return PTR_ERR(dst_vma); =20 + state->vma =3D dst_vma; /* * If memory mappings are changing because of non-cooperative * operation (e.g. mremap) running in parallel, bail out and @@ -257,7 +258,6 @@ static int mfill_get_vma(struct mfill_state *state) goto out_unlock; =20 out: - state->vma =3D dst_vma; return 0; =20 out_unlock: --=20 2.43.0