KVM: x86/mmu: Reject direct bits in gpa passed to KVM_PRE_FAULT_MEMORY
authorPaolo Bonzini <pbonzini@redhat.com>
Thu, 12 Jun 2025 04:47:44 +0000 (00:47 -0400)
committerPaolo Bonzini <pbonzini@redhat.com>
Thu, 12 Jun 2025 04:51:42 +0000 (00:51 -0400)
Only let userspace pass the same addresses that were used in KVM_SET_USER_MEMORY_REGION
(or KVM_SET_USER_MEMORY_REGION2); gpas in the the upper half of the address space
are an implementation detail of TDX and KVM.

Extracted from a patch by Sean Christopherson <seanjc@google.com>.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/kvm/mmu/mmu.c

index a4040578b5370cec275978453caece53b1a39d3a..4e06e2e89a8fa7e8710e9683346f8527182327d2 100644 (file)
@@ -4903,6 +4903,9 @@ long kvm_arch_vcpu_pre_fault_memory(struct kvm_vcpu *vcpu,
        if (!vcpu->kvm->arch.pre_fault_allowed)
                return -EOPNOTSUPP;
 
+       if (kvm_is_gfn_alias(vcpu->kvm, gpa_to_gfn(range->gpa)))
+               return -EINVAL;
+
        /*
         * reload is efficient when called repeatedly, so we can do it on
         * every iteration.