From 0db85aae47c6408fb330a3863243e6bf8a47368a Mon Sep 17 00:00:00 2001 From: Sami Tolvanen Date: Wed, 2 Oct 2019 13:37:45 -0700 Subject: [PATCH] FROMLIST: arm64: efi: restore x18 if it was corrupted If we detect a corrupted x18 and SCS is enabled, restore the register before jumping back to instrumented code. This is safe, because the wrapper is called with preemption disabled and a separate shadow stack is used for interrupt handling. Bug: 145210207 Change-Id: Idb75117e38c895231a14f5573261861e722c1264 (am from https://lore.kernel.org/patchwork/patch/1149060/) Reviewed-by: Kees Cook Signed-off-by: Sami Tolvanen --- arch/arm64/kernel/efi-rt-wrapper.S | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kernel/efi-rt-wrapper.S b/arch/arm64/kernel/efi-rt-wrapper.S index 3fc71106cb2b..62f0260f5c17 100644 --- a/arch/arm64/kernel/efi-rt-wrapper.S +++ b/arch/arm64/kernel/efi-rt-wrapper.S @@ -34,5 +34,14 @@ ENTRY(__efi_rt_asm_wrapper) ldp x29, x30, [sp], #32 b.ne 0f ret -0: b efi_handle_corrupted_x18 // tail call +0: +#ifdef CONFIG_SHADOW_CALL_STACK + /* + * Restore x18 before returning to instrumented code. This is + * safe because the wrapper is called with preemption disabled and + * a separate shadow stack is used for interrupts. + */ + mov x18, x2 +#endif + b efi_handle_corrupted_x18 // tail call ENDPROC(__efi_rt_asm_wrapper)