From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793210011; b=4PtUqUNTzqj/XtHCXvj2FYG3PHlRCo3c6zOgPeDKF4yqB0ljMbEVpEy2tcqJbOZrCr7b tF5oEbQDmBv6bbUjST91IBGYACud7GHKRmkH6joWz32+4sb10sRKVCTVGFsIQAzb1Ur/5 7EvsbJA7+ESk6shS/uxkXiG/JlRktZLAvvXVJC4hCFJBA2YG0VMTCoJMHbTfRRMQ3JXDv xENUbz5laIhn2Rs3VdBph/UPp/CaLs33tT7qa9wvXJKEM0P5Ynueuivq4bGidsEl2H+aV KAIXoL7awgRaxFMcn846vZiE/J28mm2xAmIKvp8Jms39Al54mzWsnYXSKXHY9pL9Dzg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793210011; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=Ljo2bwrVfFvHDCbnlCyA7eZ8ft3+wQJnZuzx6zy1A5k=; b=CU0M3eSWKbBJ7qWyzEPseTVMQJ8fUqp+ZeNiywZI2m13BROB6jiw89A4Jb0DXWPwSqtP X/XN/DHjw6zhay7/nJRNNZjGT1WUbOPys86Aw6PUMe0NelmUx/5srk0iBYY3L9Bmf+0MV vBkGWdM/XFVn8RHzvEg1hD/TCdYEYWxubWMeeTVqYSuMtPofF/iWotybkO4C2IiAuwHUO MmZ/qfVvBnFDI/2m6y0edNb+p0JmAu5EtUdiSDsUVLo0+XdcEEihZ6j85NdNjIGHs0ArY xhozPl+nNUrkylKo8xs7W3mAj1ThHTcrf4F1AESXbMo7McH75dQrj/brPoffpE8b7SQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=rdKZKry5; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0FF95606A323; Wed, 28 Oct 2026 17:53:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=rdKZKry5 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 669371F01828; Wed, 28 Oct 2026 17:53:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1793210010; bh=Ljo2bwrVfFvHDCbnlCyA7eZ8ft3+wQJnZuzx6zy1A5k=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=rdKZKry58HN0kZHyelqEpvWOlpmqPrDVBJmZH8CsSS6HJhXzqFgnOQho0b3cesv+k ibZXgH2goT2kGWeyc92bnvieqfidvKOExujQg5AysImgJ8BR8vFmKOPZIYlY/xQoOO OE5a50O2ajSQqHoC32Up7DyGKwSYDsK2EmrZvXZc= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, David Woodhouse , Amirmohammad Eftekhar , Sean Christopherson , Paolo Bonzini Subject: [PATCH 6.6 043/168] KVM: nVMX: Reset MMU back to the root MMU if loading L2 state fails for !VM-Entry Date: Wed, 28 Oct 2026 17:59:39 +0100 Message-ID: <20261028165944.109549901@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261028165943.089486480@linuxfoundation.org> References: <20261028165943.089486480@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Amirmohammad Eftekhar commit c8f4cfe1cf93bce924e27f2abead7a4c4a487505 upstream. Reset the vCPU's MMU pointer back to the root MMU if loading L2 state fails in the "not from VM-Entry" case, i.e. when emulating RSM or handling KVM_SET_NESTED_STATE. Failure to unwind the MMU pointer results in KVM trying to run L1 with a nested MMU, and is especially problematic if the vCPU manages to free its nested state before the VM crashes. Constructing the root for a nested EPT MMU goes through vmcs12, which is dynamically allocated/freed when nVMX is enabled/disabled. And so if the nested state is freed with the MMU still pointing at the nested MMU, KVM will hit a NULL pointer deref when attempting to get L1=>L2 EPTP. BUG: kernel NULL pointer dereference, address: 0000000000000078 #PF: supervisor read access in kernel mode #PF: error_code(0x0000) - not-present page PGD 114a2d067 P4D 111743067 PUD 11141f067 PMD 0 Oops: Oops: 0000 [#1] SMP CPU: 20 UID: 1000 PID: 1272 Comm: nested_tdp_faul Not tainted 7.3.0-rc4-8c89f11d1a99b-sink-vm #1914 PREEMPTLAZY Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 0.0.0 02/06/2015 RIP: 0010:nested_ept_get_eptp+0xb/0x10 [kvm_intel] Call Trace: kvm_mmu_load+0xcd/0x870 [kvm] kvm_arch_vcpu_ioctl_run+0x18f5/0x1f80 [kvm] kvm_vcpu_ioctl+0x2c7/0x970 [kvm] __x64_sys_ioctl+0x90/0xd0 do_syscall_64+0x9c/0x4d0 entry_SYSCALL_64_after_hwframe+0x4b/0x53 RIP: 0033:0x47491b Modules linked in: kvm_intel kvm irqbypass CR2: 0000000000000078 ---[ end trace 0000000000000000 ]--- RIP: 0010:nested_ept_get_eptp+0xb/0x10 [kvm_intel] Cc: David Woodhouse Fixes: 72e9cbdb4338 ("KVM: nVMX: fix SMI injection in guest mode") Fixes: 8fcc4b5923af ("kvm: nVMX: Introduce KVM_CAP_NESTED_STATE") Cc: stable@vger.kernel.org Signed-off-by: Amirmohammad Eftekhar [sean: write changelog] Signed-off-by: Sean Christopherson Link: https://patch.msgid.link/20261001214356.3825100-2-seanjc@google.com Signed-off-by: Paolo Bonzini Signed-off-by: Greg Kroah-Hartman --- arch/x86/kvm/vmx/nested.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) --- a/arch/x86/kvm/vmx/nested.c +++ b/arch/x86/kvm/vmx/nested.c @@ -3568,8 +3568,10 @@ vmentry_fail_vmexit_guest_mode: vmentry_fail_vmexit: vmx_switch_vmcs(vcpu, &vmx->vmcs01); - if (!from_vmentry) + if (!from_vmentry) { + nested_ept_uninit_mmu_context(vcpu); return NVMX_VMENTRY_VMEXIT; + } kvm_vcpu_unmap(vcpu, &vmx->nested.apic_access_page_map, false); kvm_vcpu_unmap(vcpu, &vmx->nested.virtual_apic_map, true);