diff mbox series

[RFC,4/8] KVM: SVM: fix: add separate error for missing slot

Message ID 20230127025237.269680-5-jarkko@profian.com (mailing list archive)
State New, archived
Headers show
Series [RFC,1/8] KVM: SVM: fix: calculate end instead of passing size | expand

Commit Message

Jarkko Sakkinen Jan. 27, 2023, 2:52 a.m. UTC
From: Tom Dohrmann <erbse.13@gmx.de>

The next error message uses slot assuming that it's not NULL, but that's not
always true. A separate error message is used when slot is NULL.

This can be triggered by a malicious guest that sends an
`SVM_VMGEXIT_AP_CREATE` ap creation event that points to an invalid AP VMSA
address (one that isn't mapped). Currently the kernel just copies the values
provided by the guest into `snp_vmsa_gpa` (see arch/x86/kvm/svm/sev.c:3930).
This value is directly passed into `gfn_to_pfn_restricted` in
`__sev_snp_update_protected_guest_state` (see arch/x86/kvm/svm/sev.c:3792).

Signed-off-by: Tom Dohrmann <erbse.13@gmx.de>
Signed-off-by: Jarkko Sakkinen <jarkko@profian.com>
---
 arch/x86/kvm/svm/sev.c | 5 +++++
 1 file changed, 5 insertions(+)
diff mbox series

Patch

diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c
index 4a8e552d8cfe..d76127f1499a 100644
--- a/arch/x86/kvm/svm/sev.c
+++ b/arch/x86/kvm/svm/sev.c
@@ -3745,6 +3745,11 @@  static kvm_pfn_t gfn_to_pfn_restricted(struct kvm *kvm, gfn_t gfn)
 	int order = 0;
 
 	slot = gfn_to_memslot(kvm, gfn);
+	if (!slot) {
+		pr_err("SEV: Failure retrieving memslot for GFN 0x%llx\n", gfn);
+		return INVALID_PAGE;
+	}
+
 	if (!kvm_slot_can_be_private(slot)) {
 		pr_err("SEV: Failure retrieving restricted memslot for GFN 0x%llx, flags 0x%x, userspace_addr: 0x%lx\n",
 		       gfn, slot->flags, slot->userspace_addr);