From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 01FA015B10D; Mon, 28 Oct 2024 06:32:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730097140; cv=none; b=ImG/5uNgmtjeOOYPNsxc3oQzLC47HyeT8ta7U1tCIrjKA6e3r/qSd3YVVrXsYdKa8ylWPv9bLCZ0kFebXEMCJAtOl+g3wGbRkPLjkLk1yxq2QafTAIQ4Gk6IX/2DU1vHYCn4ScOHiY/QkdDFNYg3foPjv7fyuSRMNmJAgIjPceM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730097140; c=relaxed/simple; bh=832vqsWvf3xEtaFUYueKQhbmtwptwaFMDFaNB8XU9qs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hHrOmgYVo7zFILdkehzJzRTaKBPGiUzN+ZHEC5zpnb/bfhBi24KLXf7IjsDmwft5npNStnmSl6TeMjtq4B9FI4C4VSAKYBk8dmy2qhwD7rRAHzSMPD/FpBmyi+tJrBqEK0KiLSnekEhXtOQQCWZ58jynsWR7JC53BQ3s9TPygzE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=TrqZfSNn; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="TrqZfSNn" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8BE6FC4CEC7; Mon, 28 Oct 2024 06:32:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1730097139; bh=832vqsWvf3xEtaFUYueKQhbmtwptwaFMDFaNB8XU9qs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TrqZfSNndpyq84I5p9O5rHd55JcUOl8o9jZ7ESGDIF/5YVMTaGTwYorEuK1nsNt9V 33df1fbWM68DQZxnH9r31A6+mbeqysK3ebC8fnfyk7/JNAAlUQCFucEVkX3Gn9Y7Nm 7SW9qjTxPmYfMppX8fiK+vv5DllusVXkoEyQMNzc= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Kirk Swidowski , Andy Nguyen , 3pvd <3pvd@google.com>, Sean Christopherson , Paolo Bonzini Subject: [PATCH 5.15 73/80] KVM: nSVM: Ignore nCR3[4:0] when loading PDPTEs from memory Date: Mon, 28 Oct 2024 07:25:53 +0100 Message-ID: <20241028062254.637693813@linuxfoundation.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241028062252.611837461@linuxfoundation.org> References: <20241028062252.611837461@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Sean Christopherson commit f559b2e9c5c5308850544ab59396b7d53cfc67bd upstream. Ignore nCR3[4:0] when loading PDPTEs from memory for nested SVM, as bits 4:0 of CR3 are ignored when PAE paging is used, and thus VMRUN doesn't enforce 32-byte alignment of nCR3. In the absolute worst case scenario, failure to ignore bits 4:0 can result in an out-of-bounds read, e.g. if the target page is at the end of a memslot, and the VMM isn't using guard pages. Per the APM: The CR3 register points to the base address of the page-directory-pointer table. The page-directory-pointer table is aligned on a 32-byte boundary, with the low 5 address bits 4:0 assumed to be 0. And the SDM's much more explicit: 4:0 Ignored Note, KVM gets this right when loading PDPTRs, it's only the nSVM flow that is broken. Fixes: e4e517b4be01 ("KVM: MMU: Do not unconditionally read PDPTE from guest memory") Reported-by: Kirk Swidowski Cc: Andy Nguyen Cc: 3pvd <3pvd@google.com> Cc: stable@vger.kernel.org Signed-off-by: Sean Christopherson Message-ID: <20241009140838.1036226-1-seanjc@google.com> Signed-off-by: Paolo Bonzini Signed-off-by: Greg Kroah-Hartman --- arch/x86/kvm/svm/nested.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) --- a/arch/x86/kvm/svm/nested.c +++ b/arch/x86/kvm/svm/nested.c @@ -77,8 +77,12 @@ static u64 nested_svm_get_tdp_pdptr(stru u64 pdpte; int ret; + /* + * Note, nCR3 is "assumed" to be 32-byte aligned, i.e. the CPU ignores + * nCR3[4:0] when loading PDPTEs from memory. + */ ret = kvm_vcpu_read_guest_page(vcpu, gpa_to_gfn(cr3), &pdpte, - offset_in_page(cr3) + index * 8, 8); + (cr3 & GENMASK(11, 5)) + index * 8, 8); if (ret) return 0; return pdpte;