]> Git Repo - J-linux.git/commitdiff
KVM: Validate hva in kvm_gpc_activate_hva() to fix __kvm_gpc_refresh() WARN
authorPei Li <[email protected]>
Thu, 27 Jun 2024 15:03:56 +0000 (08:03 -0700)
committerSean Christopherson <[email protected]>
Fri, 28 Jun 2024 15:31:46 +0000 (08:31 -0700)
Check that the virtual address is "ok" when activating a gfn_to_pfn_cache
with a host VA to ensure that KVM never attempts to use a bad address.

This fixes a bug where KVM fails to check the incoming address when
handling KVM_XEN_VCPU_ATTR_TYPE_VCPU_INFO_HVA in kvm_xen_vcpu_set_attr().

Reported-by: [email protected]
Closes: https://syzkaller.appspot.com/bug?extid=fd555292a1da3180fc82
Tested-by: [email protected]
Signed-off-by: Pei Li <[email protected]>
Reviewed-by: Paul Durrant <[email protected]>
Reviewed-by: David Woodhouse <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
[sean: rewrite changelog with --verbose]
Signed-off-by: Sean Christopherson <[email protected]>
arch/x86/kvm/xen.c
virt/kvm/pfncache.c

index f65b35a05d91687b3a159af967a7408c8d73c27c..67bb4e89c399f1cf0c0400caf00423b611609679 100644 (file)
@@ -741,7 +741,7 @@ int kvm_xen_hvm_set_attr(struct kvm *kvm, struct kvm_xen_hvm_attr *data)
                } else {
                        void __user * hva = u64_to_user_ptr(data->u.shared_info.hva);
 
-                       if (!PAGE_ALIGNED(hva) || !access_ok(hva, PAGE_SIZE)) {
+                       if (!PAGE_ALIGNED(hva)) {
                                r = -EINVAL;
                        } else if (!hva) {
                                kvm_gpc_deactivate(&kvm->arch.xen.shinfo_cache);
index e3453e869e92c8f6546b7aa76ce8b3a2b486df4f..f0039efb9e1e34315450bcb589429a8cecb37a73 100644 (file)
@@ -430,6 +430,9 @@ int kvm_gpc_activate(struct gfn_to_pfn_cache *gpc, gpa_t gpa, unsigned long len)
 
 int kvm_gpc_activate_hva(struct gfn_to_pfn_cache *gpc, unsigned long uhva, unsigned long len)
 {
+       if (!access_ok((void __user *)uhva, len))
+               return -EINVAL;
+
        return __kvm_gpc_activate(gpc, INVALID_GPA, uhva, len);
 }
 
This page took 0.065591 seconds and 4 git commands to generate.