]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
KVM: x86: Protect kvm_hv_msr_[get|set]_crash_data() from Spectre-v1/L1TF attacks
authorMarios Pomonis <pomonis@google.com>
Wed, 11 Dec 2019 20:47:42 +0000 (12:47 -0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 11 Feb 2020 12:34:09 +0000 (04:34 -0800)
commit 8618793750071d66028584a83ed0b4fa7eb4f607 upstream.

This fixes Spectre-v1/L1TF vulnerabilities in kvm_hv_msr_get_crash_data()
and kvm_hv_msr_set_crash_data().
These functions contain index computations that use the
(attacker-controlled) MSR number.

Fixes: e7d9513b60e8 ("kvm/x86: added hyper-v crash msrs into kvm hyperv context")
Signed-off-by: Nick Finco <nifi@google.com>
Signed-off-by: Marios Pomonis <pomonis@google.com>
Reviewed-by: Andrew Honig <ahonig@google.com>
Cc: stable@vger.kernel.org
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
arch/x86/kvm/hyperv.c

index 5842c5f587fe910b9358eda88cb619bd958413c4..3fd6c4b2c2b7bf8d66bf8a6fd708b2398d5a797c 100644 (file)
@@ -792,11 +792,12 @@ static int kvm_hv_msr_get_crash_data(struct kvm_vcpu *vcpu,
                                     u32 index, u64 *pdata)
 {
        struct kvm_hv *hv = &vcpu->kvm->arch.hyperv;
+       size_t size = ARRAY_SIZE(hv->hv_crash_param);
 
-       if (WARN_ON_ONCE(index >= ARRAY_SIZE(hv->hv_crash_param)))
+       if (WARN_ON_ONCE(index >= size))
                return -EINVAL;
 
-       *pdata = hv->hv_crash_param[index];
+       *pdata = hv->hv_crash_param[array_index_nospec(index, size)];
        return 0;
 }
 
@@ -835,11 +836,12 @@ static int kvm_hv_msr_set_crash_data(struct kvm_vcpu *vcpu,
                                     u32 index, u64 data)
 {
        struct kvm_hv *hv = &vcpu->kvm->arch.hyperv;
+       size_t size = ARRAY_SIZE(hv->hv_crash_param);
 
-       if (WARN_ON_ONCE(index >= ARRAY_SIZE(hv->hv_crash_param)))
+       if (WARN_ON_ONCE(index >= size))
                return -EINVAL;
 
-       hv->hv_crash_param[index] = data;
+       hv->hv_crash_param[array_index_nospec(index, size)] = data;
        return 0;
 }