Skip to contentSkip to conversation

x86/spec-ctrl: Protect against CALL/JMP straight-line speculation

PATCH In review Andrew Cooper 3 participants 3 messages Jul 1, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/spec-ctrl: Protect against CALL/JMP straight-line speculation

Some x86 CPUs speculatively execute beyond indirect CALL/JMP instructions.

With CONFIG_INDIRECT_THUNK / Retpolines, indirect CALL/JMP instructions are converted to direct CALL/JMP's to __x86_indirect_thunk_REG(), leaving just a handful of indirect JMPs implementing those stubs.

There is no architectrual execution beyond an indirect JMP, so use INT3 as recommended by vendors to halt speculative execution. This is shorter than LFENCE (which would also work fine), but also shows up in logs if we do unexpected execute them.

---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Paul Durrant <[email protected]>

This wants backporting to all release, possibly even into the security trees, and should therefore be considered for 4.14 at this point.

---
 xen/arch/x86/indirect-thunk.S | 2 ++
 1 file changed, 2 insertions(+)
xen/arch/x86/indirect-thunk.S +2 -0
index 3c17f75c23..7392aee127 100644
@@ -24,10 +24,12 @@
 .macro IND_THUNK_LFENCE reg:req
         lfence
         jmp *%\reg
+        int3 /* Halt straight-line speculation */
 .endm
 
 .macro IND_THUNK_JMP reg:req
         jmp *%\reg
+        int3 /* Halt straight-line speculation */
 .endm
 
 /*
Signature · 1 line
2.11.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Andrew Cooper

Some x86 CPUs speculatively execute beyond indirect CALL/JMP instructions.

With CONFIG_INDIRECT_THUNK / Retpolines, indirect CALL/JMP instructions are converted to direct CALL/JMP's to __x86_indirect_thunk_REG(), leaving just a handful of indirect JMPs implementing those stubs.

Quoted 6 lines

There is no architectrual execution beyond an indirect JMP, so use INT3 as recommended by vendors to halt speculative execution. This is shorter than LFENCE (which would also work fine), but also shows up in logs if we do unexpected execute them.

#2 lore raw
Quoted 15 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: 01 July 2020 13:27
To: Andrew Cooper <[email protected]>
Cc: Xen-devel <[email protected]>; Wei Liu <[email protected]>; Roger Pau Monné <[email protected]>; Paul Durrant <[email protected]>
Subject: Re: [PATCH for-4.14] x86/spec-ctrl: Protect against CALL/JMP straight-line speculation

Quoted 6 lines · Andrew Cooper

Some x86 CPUs speculatively execute beyond indirect CALL/JMP instructions.

With CONFIG_INDIRECT_THUNK / Retpolines, indirect CALL/JMP instructions are converted to direct CALL/JMP's to __x86_indirect_thunk_REG(), leaving just a handful of indirect JMPs implementing those stubs.

Quoted 8 lines
Quoted 6 lines

There is no architectrual execution beyond an indirect JMP, so use INT3 as recommended by vendors to halt speculative execution. This is shorter than LFENCE (which would also work fine), but also shows up in logs if we do unexpected execute them.