]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
KVM: x86: Sanity check inputs to kvm_handle_memory_failure()
authorSean Christopherson <seanjc@google.com>
Tue, 20 Dec 2022 15:34:27 +0000 (15:34 +0000)
committerPaolo Bonzini <pbonzini@redhat.com>
Fri, 23 Dec 2022 17:15:25 +0000 (12:15 -0500)
Add a sanity check in kvm_handle_memory_failure() to assert that a valid
x86_exception structure is provided if the memory "failure" wants to
propagate a fault into the guest.  If a memory failure happens during a
direct guest physical memory access, e.g. for nested VMX, KVM hardcodes
the failure to X86EMUL_IO_NEEDED and doesn't provide an exception pointer
(because the exception struct would just be filled with garbage).

Signed-off-by: Sean Christopherson <seanjc@google.com>
Message-Id: <20221220153427.514032-1-seanjc@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/kvm/x86.c

index fd6c01a39312820e1388fda4a3213b38c5fd1632..5c3ce39cdccbf9512b006dd4e8de3f59f8ef883c 100644 (file)
@@ -13132,6 +13132,9 @@ int kvm_handle_memory_failure(struct kvm_vcpu *vcpu, int r,
                              struct x86_exception *e)
 {
        if (r == X86EMUL_PROPAGATE_FAULT) {
+               if (KVM_BUG_ON(!e, vcpu->kvm))
+                       return -EIO;
+
                kvm_inject_emulated_page_fault(vcpu, e);
                return 1;
        }