]> xenbits.xensource.com Git - ovmf.git/commitdiff
MdePkg/BaseLib AARCH64: Make LongJump() BTI compatible
authorArd Biesheuvel <ardb@kernel.org>
Mon, 27 Mar 2023 10:32:42 +0000 (12:32 +0200)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Thu, 30 Mar 2023 11:05:22 +0000 (11:05 +0000)
Currently, the AArch64 implementation of LongJump() avoids using the RET
instruction to perform the jump, even though the target address is held
in the link register X30, as the nature of a long jump implies that the
ordinary return address prediction machinery will not be able to make a
correct prediction.

However, LongJump() is rarely used, and the return stack will be out of
sync in any case, so this optimization has little value in practice, and
given that indirect calls other than function returns require a BTI
landing pad at the call site, this optimization is not compatible with
BTI. So let's just use RET instead.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Reviewed-by: Leif Lindholm <quic_llindhol@quicinc.com>
Reviewed-by: Oliver Smith-Denny <osd@smith-denny.com>
MdePkg/Library/BaseLib/AArch64/SetJumpLongJump.S

index deefdf526b95ca93fb496e84894e0baa44118a8c..1d5cfbf64470452fabb590e495b8889b9fd525a1 100644 (file)
@@ -85,7 +85,6 @@ ASM_PFX(InternalLongJump):
         cmp     w1, #0\r
         mov     w0, #1\r
         csel    w0, w1, w0, ne\r
-        // use br not ret, as ret is guaranteed to mispredict\r
-        br      x30\r
+        ret\r
 \r
 ASM_FUNCTION_REMOVE_IF_UNREFERENCED\r