]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
KVM: x86: hyperv: enforce vp_index < KVM_MAX_VCPUS
authorVitaly Kuznetsov <vkuznets@redhat.com>
Wed, 22 Aug 2018 10:18:28 +0000 (12:18 +0200)
committerKhalid Elmously <khalid.elmously@canonical.com>
Thu, 26 Sep 2019 04:34:52 +0000 (00:34 -0400)
BugLink: https://bugs.launchpad.net/bugs/1844558
[ Upstream commit 9170200ec0ebad70e5b9902bc93e2b1b11456a3b ]

Hyper-V TLFS (5.0b) states:

> Virtual processors are identified by using an index (VP index). The
> maximum number of virtual processors per partition supported by the
> current implementation of the hypervisor can be obtained through CPUID
> leaf 0x40000005. A virtual processor index must be less than the
> maximum number of virtual processors per partition.

Forbid userspace to set VP_INDEX above KVM_MAX_VCPUS. get_vcpu_by_vpidx()
can now be optimized to bail early when supplied vpidx is >= KVM_MAX_VCPUS.

Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
Reviewed-by: Roman Kagan <rkagan@virtuozzo.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Khalid Elmously <khalid.elmously@canonical.com>
arch/x86/kvm/hyperv.c

index 4b94a8a84b5fe7379470a7189fb98d90a3b79bf4..11b2573cee51765694744e4923f9defac315acde 100644 (file)
@@ -111,8 +111,10 @@ static struct kvm_vcpu *get_vcpu_by_vpidx(struct kvm *kvm, u32 vpidx)
        struct kvm_vcpu *vcpu = NULL;
        int i;
 
-       if (vpidx < KVM_MAX_VCPUS)
-               vcpu = kvm_get_vcpu(kvm, vpidx);
+       if (vpidx >= KVM_MAX_VCPUS)
+               return NULL;
+
+       vcpu = kvm_get_vcpu(kvm, vpidx);
        if (vcpu && vcpu_to_hv_vcpu(vcpu)->vp_index == vpidx)
                return vcpu;
        kvm_for_each_vcpu(i, vcpu, kvm)
@@ -1011,7 +1013,7 @@ static int kvm_hv_set_msr(struct kvm_vcpu *vcpu, u32 msr, u64 data, bool host)
 
        switch (msr) {
        case HV_X64_MSR_VP_INDEX:
-               if (!host)
+               if (!host || (u32)data >= KVM_MAX_VCPUS)
                        return 1;
                hv->vp_index = (u32)data;
                break;