]> xenbits.xensource.com Git - xen.git/commitdiff
xen/arm: Place a speculation barrier sequence following an eret instruction
authorJulien Grall <julien@xen.org>
Thu, 19 Dec 2019 08:12:21 +0000 (08:12 +0000)
committerJulien Grall <julien@xen.org>
Tue, 14 Jan 2020 14:26:43 +0000 (14:26 +0000)
Some CPUs can speculate past an ERET instruction and potentially perform
speculative accesses to memory before processing the exception return.
Since the register state is often controlled by lower privilege level
at the point of an ERET, this could potentially be used as part of a
side-channel attack.

Newer CPUs may implement a new SB barrier instruction which acts
as an architected speculation barrier. For current CPUs, the sequence
DSB; ISB is known to prevent speculation.

The latter sequence is heavier than SB but it would never be executed
(this is speculation after all!).

Introduce a new macro 'sb' that could be used when a speculation barrier
is required. For now it is using dsb; isb but this could easily be
updated to cater SB in the future.

This is XSA-312.

Signed-off-by: Julien Grall <julien@xen.org>
xen/arch/arm/arm32/entry.S
xen/arch/arm/arm64/entry.S
xen/include/asm-arm/macros.h

index 16d9f9365331218f60bc3e18214cdc00a2693304..464c8b8645d43ab4e3801c107535c3647c44fc50 100644 (file)
@@ -1,4 +1,5 @@
 #include <asm/asm_defns.h>
+#include <asm/macros.h>
 #include <asm/regs.h>
 #include <asm/alternative.h>
 #include <public/xen.h>
@@ -379,6 +380,7 @@ return_to_hypervisor:
         add sp, #(UREGS_SP_usr - UREGS_sp); /* SP, LR, SPSR, PC */
         clrex
         eret
+        sb
 
 /*
  * struct vcpu *__context_switch(struct vcpu *prev, struct vcpu *next)
index 12df95e90181a724b717d68073ab0e97874a9a81..a42c51e489c32b2d5bd1e1dba70987dec66a61d4 100644 (file)
@@ -2,6 +2,7 @@
 #include <asm/regs.h>
 #include <asm/alternative.h>
 #include <asm/smccc.h>
+#include <asm/macros.h>
 #include <public/xen.h>
 
 /*
@@ -288,6 +289,7 @@ guest_sync:
          */
         mov     x1, xzr
         eret
+        sb
 
 1:
         /*
@@ -413,6 +415,7 @@ return_from_trap:
         ldr     lr, [sp], #(UREGS_SPSR_el1 - UREGS_LR) /* CPSR, PC, SP, LR */
 
         eret
+        sb
 
 /*
  * This function is used to check pending virtual SError in the gap of
index 5d837cb38b9a8b104cc8bad71e0fb6e2f1fd4e13..539f613ee543ec7641aff9d8e1755ac8b0719a56 100644 (file)
 # error "unknown ARM variant"
 #endif
 
+    /*
+     * Speculative barrier
+     * XXX: Add support for the 'sb' instruction
+     */
+    .macro sb
+    dsb nsh
+    isb
+    .endm
+
 #endif /* __ASM_ARM_MACROS_H */