Skip to content

Commit 085331d

Browse files
djbwKAGA-KOKO
authored andcommitted
x86/kvm: Update spectre-v1 mitigation
Commit 75f139a "KVM: x86: Add memory barrier on vmcs field lookup" added a raw 'asm("lfence");' to prevent a bounds check bypass of 'vmcs_field_to_offset_table'. The lfence can be avoided in this path by using the array_index_nospec() helper designed for these types of fixes. Signed-off-by: Dan Williams <dan.j.williams@intel.com> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Acked-by: Paolo Bonzini <pbonzini@redhat.com> Cc: Andrew Honig <ahonig@google.com> Cc: kvm@vger.kernel.org Cc: Jim Mattson <jmattson@google.com> Link: https://lkml.kernel.org/r/151744959670.6342.3001723920950249067.stgit@dwillia2-desk3.amr.corp.intel.com
1 parent 12c69f1 commit 085331d

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

arch/x86/kvm/vmx.c

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include <linux/tboot.h>
3535
#include <linux/hrtimer.h>
3636
#include <linux/frame.h>
37+
#include <linux/nospec.h>
3738
#include "kvm_cache_regs.h"
3839
#include "x86.h"
3940

@@ -898,21 +899,18 @@ static const unsigned short vmcs_field_to_offset_table[] = {
898899

899900
static inline short vmcs_field_to_offset(unsigned long field)
900901
{
901-
BUILD_BUG_ON(ARRAY_SIZE(vmcs_field_to_offset_table) > SHRT_MAX);
902+
const size_t size = ARRAY_SIZE(vmcs_field_to_offset_table);
903+
unsigned short offset;
902904

903-
if (field >= ARRAY_SIZE(vmcs_field_to_offset_table))
905+
BUILD_BUG_ON(size > SHRT_MAX);
906+
if (field >= size)
904907
return -ENOENT;
905908

906-
/*
907-
* FIXME: Mitigation for CVE-2017-5753. To be replaced with a
908-
* generic mechanism.
909-
*/
910-
asm("lfence");
911-
912-
if (vmcs_field_to_offset_table[field] == 0)
909+
field = array_index_nospec(field, size);
910+
offset = vmcs_field_to_offset_table[field];
911+
if (offset == 0)
913912
return -ENOENT;
914-
915-
return vmcs_field_to_offset_table[field];
913+
return offset;
916914
}
917915

918916
static inline struct vmcs12 *get_vmcs12(struct kvm_vcpu *vcpu)

0 commit comments

Comments
 (0)