Skip to contentSkip to conversation

Choose retpoline only when it is safe to use

PATCH In review Zhenzhong Duan 2 participants 4 messages Feb 6, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Choose retpoline only when it is safe to use

When ( ibrs && thunk == THUNK_DEFAULT && !retpoline_safe() ) is true, thunk is set to THUNK_JMP rather than THUNK_RETPOLINE.

When (!ibrs && thunk == THUNK_DEFAULT && !retpoline_safe() ) is true, we should do the same.

---
 xen/arch/x86/spec_ctrl.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
xen/arch/x86/spec_ctrl.c +2 -2
index f10ffbf..ab4b244 100644
@@ -247,10 +247,10 @@ void __init init_speculation_mitigations(void)
 
     /*
      * If there are still no thunk preferences, the compiled default is
-     * actually retpoline, and it is better than nothing.
+     * actually retpoline, and it is better than nothing if it's retpoline safe.
      */
     if ( thunk == THUNK_DEFAULT )
-        thunk = THUNK_RETPOLINE;
+        thunk = retpoline_safe() ? THUNK_RETPOLINE : THUNK_JMP;
 
     /* Apply the chosen settings. */
     if ( thunk == THUNK_LFENCE )
Signature · 6 lines
1.7.3

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#1 lore raw
Quoted 7 lines · Zhenzhong Duan

When ( ibrs && thunk == THUNK_DEFAULT && !retpoline_safe() ) is true, thunk is set to THUNK_JMP rather than THUNK_RETPOLINE.

When (!ibrs && thunk == THUNK_DEFAULT && !retpoline_safe() ) is true, we should do the same.

Why?  What improvement is this intended to give?

(IOW, the logic here is deliberate, and has a specific purpose.)

~Andrew

Quoted 11 lines
---
 xen/arch/x86/spec_ctrl.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
xen/arch/x86/spec_ctrl.c +0 -0
index f10ffbf..ab4b244 100644
@@ -247,10 +247,10 @@ void __init init_speculation_mitigations(void)
 
     /*

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

Quoted 10 lines
xen/arch/x86/spec_ctrl.c +2 -2
      * If there are still no thunk preferences, the compiled default is
-     * actually retpoline, and it is better than nothing.
+     * actually retpoline, and it is better than nothing if it's retpoline safe.
      */
     if ( thunk == THUNK_DEFAULT )
-        thunk = THUNK_RETPOLINE;
+        thunk = retpoline_safe() ? THUNK_RETPOLINE : THUNK_JMP;
 
     /* Apply the chosen settings. */
     if ( thunk == THUNK_LFENCE )

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#2 lore raw
Quoted 9 lines · Andrew Cooper
Quoted 7 lines · Zhenzhong Duan

When ( ibrs && thunk == THUNK_DEFAULT && !retpoline_safe() ) is true, thunk is set to THUNK_JMP rather than THUNK_RETPOLINE.

When (!ibrs && thunk == THUNK_DEFAULT && !retpoline_safe() ) is true, we should do the same.

Why?  What improvement is this intended to give?

No improvement, I just feel if retpoline isn't safe, THUNK_JMP is better and safer. Above first check is working that way.

Quoted 2 lines

(IOW, the logic here is deliberate, and has a specific purpose.)

Ok, Just ignore the noise if it's deliberate.

Signature · 8 lines
thanks
zduan


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#3 lore raw
Quoted 5 lines · Zhenzhong Duan
Quoted 4 lines · Andrew Cooper
Quoted 3 lines · Zhenzhong Duan

When ( ibrs && thunk == THUNK_DEFAULT && !retpoline_safe() ) is true, thunk is set to THUNK_JMP rather than THUNK_RETPOLINE.

Quoted 8 lines
Quoted 5 lines
Quoted 4 lines

When (!ibrs && thunk == THUNK_DEFAULT && !retpoline_safe() ) is true, we should do the same.

Why?  What improvement is this intended to give?

No improvement, I just feel if retpoline isn't safe, THUNK_JMP is better and safer.
Above first check is working that way.

If your only two choices are unsafe repoline or plain jumps, then unsafe repoline is far far far safer.

Its unsafe properties only kick in on an RSB underflow, and an attacker would have to do call-depths analysis of the running binary to identify which rets to attempt to poison.

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel