Skip to contentSkip to conversation

x86/spec-ctrl: Disable retpolines with CET-IBT

PATCH In review Andrew Cooper 2 participants 2 messages Feb 28, 2022 – Mar 1, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/spec-ctrl: Disable retpolines with CET-IBT

CET-IBT depend on executing indirect branches for protections to apply. Extend the clobber for CET-SS to all of CET.

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

I can't decide if this wants a fixes tag or not. If I'd remembered during the CET series, it would have been its own patch. Functionally, it depends on c/s cdbe2b0a1aec which sets CR4.CET fairly early during boot.

---
 xen/arch/x86/spec_ctrl.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
xen/arch/x86/spec_ctrl.c +4 -3
index 2d4cf5c7ef80..12bf1c5722f9 100644
@@ -944,10 +944,11 @@ void __init init_speculation_mitigations(void)
                      boot_cpu_has(X86_FEATURE_IBRS));
 
     /*
-     * First, disable the use of retpolines if Xen is using shadow stacks, as
-     * they are incompatible.
+     * First, disable the use of retpolines if Xen is using CET.  Retpolines
+     * are a ROP gadget so incompatbile with Shadow Stacks, while IBT depends
+     * on executing indirect branches for the safety properties to apply.
      */
-    if ( cpu_has_xen_shstk &&
+    if ( (read_cr4() & X86_CR4_CET) &&
          (opt_thunk == THUNK_DEFAULT || opt_thunk == THUNK_RETPOLINE) )
         thunk = THUNK_JMP;
 
Signature · 1 line
2.11.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 4 lines · Andrew Cooper

CET-IBT depend on executing indirect branches for protections to apply. Extend the clobber for CET-SS to all of CET.

Quoted 2 lines

I can't decide if this wants a fixes tag or not. If I'd remembered during the CET series, it would have been its own patch.

On this basis I'd say no Fixes: tag.

Quoted 6 lines
xen/arch/x86/spec_ctrl.c +0 -0
@@ -944,10 +944,11 @@ void __init init_speculation_mitigations(void)
                      boot_cpu_has(X86_FEATURE_IBRS));
 
     /*

xen/arch/x86/spec_ctrl.c void __init init_speculation_mitigations(void) · line 953

Quoted 10 lines
xen/arch/x86/spec_ctrl.c +4 -3
-     * First, disable the use of retpolines if Xen is using shadow stacks, as
-     * they are incompatible.
+     * First, disable the use of retpolines if Xen is using CET.  Retpolines
+     * are a ROP gadget so incompatbile with Shadow Stacks, while IBT depends
+     * on executing indirect branches for the safety properties to apply.
      */
-    if ( cpu_has_xen_shstk &&
+    if ( (read_cr4() & X86_CR4_CET) &&
          (opt_thunk == THUNK_DEFAULT || opt_thunk == THUNK_RETPOLINE) )
         thunk = THUNK_JMP;

Just for my own understanding: Why unconditionally THUNK_JMP and not possibly THUNK_LFENCE?

Jan