mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-10-10 18:53:38 +00:00
KVM: x86: Make indirect calls in emulator speculation safe
commit 1a29b5b7f3
Replace the indirect calls with CALL_NOSPEC.
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: David Woodhouse <dwmw@amazon.co.uk>
Cc: Andrea Arcangeli <aarcange@redhat.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Ashok Raj <ashok.raj@intel.com>
Cc: Greg KH <gregkh@linuxfoundation.org>
Cc: Jun Nakajima <jun.nakajima@intel.com>
Cc: David Woodhouse <dwmw2@infradead.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: rga@amazon.de
Cc: Dave Hansen <dave.hansen@intel.com>
Cc: Asit Mallick <asit.k.mallick@intel.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Jason Baron <jbaron@akamai.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Arjan Van De Ven <arjan.van.de.ven@intel.com>
Cc: Tim Chen <tim.c.chen@linux.intel.com>
Link: https://lkml.kernel.org/r/20180125095843.595615683@infradead.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
4ce354deed
commit
76bee09efb
1 changed files with 5 additions and 4 deletions
|
@ -25,6 +25,7 @@
|
||||||
#include <asm/kvm_emulate.h>
|
#include <asm/kvm_emulate.h>
|
||||||
#include <linux/stringify.h>
|
#include <linux/stringify.h>
|
||||||
#include <asm/debugreg.h>
|
#include <asm/debugreg.h>
|
||||||
|
#include <asm/nospec-branch.h>
|
||||||
|
|
||||||
#include "x86.h"
|
#include "x86.h"
|
||||||
#include "tss.h"
|
#include "tss.h"
|
||||||
|
@ -1021,8 +1022,8 @@ static __always_inline u8 test_cc(unsigned int condition, unsigned long flags)
|
||||||
void (*fop)(void) = (void *)em_setcc + 4 * (condition & 0xf);
|
void (*fop)(void) = (void *)em_setcc + 4 * (condition & 0xf);
|
||||||
|
|
||||||
flags = (flags & EFLAGS_MASK) | X86_EFLAGS_IF;
|
flags = (flags & EFLAGS_MASK) | X86_EFLAGS_IF;
|
||||||
asm("push %[flags]; popf; call *%[fastop]"
|
asm("push %[flags]; popf; " CALL_NOSPEC
|
||||||
: "=a"(rc) : [fastop]"r"(fop), [flags]"r"(flags));
|
: "=a"(rc) : [thunk_target]"r"(fop), [flags]"r"(flags));
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5350,9 +5351,9 @@ static int fastop(struct x86_emulate_ctxt *ctxt, void (*fop)(struct fastop *))
|
||||||
if (!(ctxt->d & ByteOp))
|
if (!(ctxt->d & ByteOp))
|
||||||
fop += __ffs(ctxt->dst.bytes) * FASTOP_SIZE;
|
fop += __ffs(ctxt->dst.bytes) * FASTOP_SIZE;
|
||||||
|
|
||||||
asm("push %[flags]; popf; call *%[fastop]; pushf; pop %[flags]\n"
|
asm("push %[flags]; popf; " CALL_NOSPEC " ; pushf; pop %[flags]\n"
|
||||||
: "+a"(ctxt->dst.val), "+d"(ctxt->src.val), [flags]"+D"(flags),
|
: "+a"(ctxt->dst.val), "+d"(ctxt->src.val), [flags]"+D"(flags),
|
||||||
[fastop]"+S"(fop), ASM_CALL_CONSTRAINT
|
[thunk_target]"+S"(fop), ASM_CALL_CONSTRAINT
|
||||||
: "c"(ctxt->src2.val));
|
: "c"(ctxt->src2.val));
|
||||||
|
|
||||||
ctxt->eflags = (ctxt->eflags & ~EFLAGS_MASK) | (flags & EFLAGS_MASK);
|
ctxt->eflags = (ctxt->eflags & ~EFLAGS_MASK) | (flags & EFLAGS_MASK);
|
||||||
|
|
Loading…
Reference in a new issue