Re: Avoid speculative indirect calls in kernel

From: David Woodhouse
Date: Thu Jan 04 2018 - 11:15:30 EST


On Thu, 2018-01-04 at 15:29 +0000, Woodhouse, David wrote:
>
> > With the GCC -mindirect-branch=thunk-external support, and microcode,
> > Xen will make a boot-time choice between using Retpoline, Lfence (which
> > is the better AMD option, and more performant than retpoline), or IBRS
> > on Skylake and newer processors where it is strictly necessary, as well
> > as using IBPB whenever available.
>
> I need to pull in the AMD lfence alternative for retpoline, giving us a
> 3-way choice of the existing retpoline thunk, "lfence; jmp *%\reg", and
> a bare "jmp *%\reg".

I think I can abuse X86_FEATURE_SYSCALL for that, right? So it would
look something like this:

Â--- a/arch/x86/lib/retpoline.S
+++ b/arch/x86/lib/retpoline.S
@@ -12,7 +12,7 @@
Â
ÂENTRY(__x86.indirect_thunk.\reg)
ÂÂÂÂÂÂÂÂCFI_STARTPROC
-ÂÂÂÂÂÂÂALTERNATIVE "call 2f", __stringify(jmp *%\reg), X86_BUG_NO_RETPOLINE
+ÂÂÂÂÂÂÂALTERNATIVE_2 "call 2f", __stringify(lfence;jmp *%\reg), X86_FEATURE_SYSCALL, __stringify(jmp *%\reg), X86_BUG_NO_RETPOLINE
Â1:
ÂÂÂÂÂÂÂÂlfence
ÂÂÂÂÂÂÂÂASM_UNREACHABLE


However, I would very much like to see a categorical statement from AMD
that the lfence is sufficient in all cases. Remember, Intel were saying
that too for a while, before finding that it was not *quite* good
enough.

Attachment: smime.p7s
Description: S/MIME cryptographic signature