Commit f30904cf authored by Marios Pomonis's avatar Marios Pomonis Committed by Khalid Elmously

KVM: x86: Protect kvm_hv_msr_[get|set]_crash_data() from Spectre-v1/L1TF attacks

BugLink: https://bugs.launchpad.net/bugs/1864775

commit 86187937 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: e7d9513b ("kvm/x86: added hyper-v crash msrs into kvm hyperv context")
Signed-off-by: default avatarNick Finco <nifi@google.com>
Signed-off-by: default avatarMarios Pomonis <pomonis@google.com>
Reviewed-by: default avatarAndrew Honig <ahonig@google.com>
Cc: stable@vger.kernel.org
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarKhalid Elmously <khalid.elmously@canonical.com>
Signed-off-by: default avatarKleber Sacilotto de Souza <kleber.souza@canonical.com>
parent b4fe193d
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include <linux/kvm_host.h> #include <linux/kvm_host.h>
#include <linux/highmem.h> #include <linux/highmem.h>
#include <asm/apicdef.h> #include <asm/apicdef.h>
#include <linux/nospec.h>
#include <trace/events/kvm.h> #include <trace/events/kvm.h>
#include "trace.h" #include "trace.h"
...@@ -686,11 +687,12 @@ static int kvm_hv_msr_get_crash_data(struct kvm_vcpu *vcpu, ...@@ -686,11 +687,12 @@ static int kvm_hv_msr_get_crash_data(struct kvm_vcpu *vcpu,
u32 index, u64 *pdata) u32 index, u64 *pdata)
{ {
struct kvm_hv *hv = &vcpu->kvm->arch.hyperv; 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; return -EINVAL;
*pdata = hv->hv_crash_param[index]; *pdata = hv->hv_crash_param[array_index_nospec(index, size)];
return 0; return 0;
} }
...@@ -729,11 +731,12 @@ static int kvm_hv_msr_set_crash_data(struct kvm_vcpu *vcpu, ...@@ -729,11 +731,12 @@ static int kvm_hv_msr_set_crash_data(struct kvm_vcpu *vcpu,
u32 index, u64 data) u32 index, u64 data)
{ {
struct kvm_hv *hv = &vcpu->kvm->arch.hyperv; 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; return -EINVAL;
hv->hv_crash_param[index] = data; hv->hv_crash_param[array_index_nospec(index, size)] = data;
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment