summaryrefslogtreecommitdiffstats
path: root/arch/x86/kvm
diff options
context:
space:
mode:
authorMarios Pomonis <pomonis@google.com>2019-12-11 12:47:41 -0800
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2020-02-14 16:29:58 -0500
commitd216f65c74ddf8ae6547f8a9325f9ad15f688c97 (patch)
treefe2af895bb7e94d10c7cd625d238b7cfd60e6220 /arch/x86/kvm
parent0126c3ef8a3ff657bdd34c220111fdf3a365e655 (diff)
downloadlinux-stable-d216f65c74ddf8ae6547f8a9325f9ad15f688c97.tar.gz
linux-stable-d216f65c74ddf8ae6547f8a9325f9ad15f688c97.tar.bz2
linux-stable-d216f65c74ddf8ae6547f8a9325f9ad15f688c97.zip
KVM: x86: Protect x86_decode_insn from Spectre-v1/L1TF attacks
commit 3c9053a2cae7ba2ba73766a34cea41baa70f57f7 upstream. This fixes a Spectre-v1/L1TF vulnerability in x86_decode_insn(). kvm_emulate_instruction() (an ancestor of x86_decode_insn()) is an exported symbol, so KVM should treat it conservatively from a security perspective. Fixes: 045a282ca415 ("KVM: emulator: implement fninit, fnstsw, fnstcw") 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 Reviewed-by: Jim Mattson <jmattson@google.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'arch/x86/kvm')
-rw-r--r--arch/x86/kvm/emulate.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
index 52e8203bdc42..ffbdd201c1f1 100644
--- a/arch/x86/kvm/emulate.c
+++ b/arch/x86/kvm/emulate.c
@@ -23,6 +23,7 @@
#include <linux/kvm_host.h>
#include "kvm_cache_regs.h"
#include <linux/module.h>
+#include <linux/nospec.h>
#include <asm/kvm_emulate.h>
#include <linux/stringify.h>
#include <asm/debugreg.h>
@@ -5146,10 +5147,15 @@ done_prefixes:
}
break;
case Escape:
- if (ctxt->modrm > 0xbf)
- opcode = opcode.u.esc->high[ctxt->modrm - 0xc0];
- else
+ if (ctxt->modrm > 0xbf) {
+ size_t size = ARRAY_SIZE(opcode.u.esc->high);
+ u32 index = array_index_nospec(
+ ctxt->modrm - 0xc0, size);
+
+ opcode = opcode.u.esc->high[index];
+ } else {
opcode = opcode.u.esc->op[(ctxt->modrm >> 3) & 7];
+ }
break;
case InstrDual:
if ((ctxt->modrm >> 6) == 3)