| .. | .. |
|---|
| 1 | +/* SPDX-License-Identifier: GPL-2.0-only */ |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Copyright (C) 2018 Linaro Ltd <ard.biesheuvel@linaro.org> |
|---|
| 3 | | - * |
|---|
| 4 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 5 | | - * it under the terms of the GNU General Public License version 2 as |
|---|
| 6 | | - * published by the Free Software Foundation. |
|---|
| 7 | 4 | */ |
|---|
| 8 | 5 | |
|---|
| 9 | 6 | #include <linux/linkage.h> |
|---|
| 7 | +#include <asm/assembler.h> |
|---|
| 10 | 8 | |
|---|
| 11 | | -ENTRY(__efi_rt_asm_wrapper) |
|---|
| 9 | +SYM_FUNC_START(__efi_rt_asm_wrapper) |
|---|
| 12 | 10 | stp x29, x30, [sp, #-32]! |
|---|
| 13 | 11 | mov x29, sp |
|---|
| 14 | 12 | |
|---|
| .. | .. |
|---|
| 18 | 16 | * (such as UEFI) should never touch it. |
|---|
| 19 | 17 | */ |
|---|
| 20 | 18 | stp x1, x18, [sp, #16] |
|---|
| 19 | + |
|---|
| 20 | + ldr_l x16, efi_rt_stack_top |
|---|
| 21 | + mov sp, x16 |
|---|
| 22 | +#ifdef CONFIG_SHADOW_CALL_STACK |
|---|
| 23 | + str x18, [sp, #-16]! |
|---|
| 24 | +#endif |
|---|
| 21 | 25 | |
|---|
| 22 | 26 | /* |
|---|
| 23 | 27 | * We are lucky enough that no EFI runtime services take more than |
|---|
| .. | .. |
|---|
| 32 | 36 | mov x4, x6 |
|---|
| 33 | 37 | blr x8 |
|---|
| 34 | 38 | |
|---|
| 39 | + mov sp, x29 |
|---|
| 35 | 40 | ldp x1, x2, [sp, #16] |
|---|
| 36 | 41 | cmp x2, x18 |
|---|
| 37 | 42 | ldp x29, x30, [sp], #32 |
|---|
| 38 | 43 | b.ne 0f |
|---|
| 39 | 44 | ret |
|---|
| 40 | 45 | 0: |
|---|
| 41 | | -#ifdef CONFIG_SHADOW_CALL_STACK |
|---|
| 42 | 46 | /* |
|---|
| 43 | | - * Restore x18 before returning to instrumented code. This is |
|---|
| 44 | | - * safe because the wrapper is called with preemption disabled and |
|---|
| 45 | | - * a separate shadow stack is used for interrupts. |
|---|
| 47 | + * With CONFIG_SHADOW_CALL_STACK, the kernel uses x18 to store a |
|---|
| 48 | + * shadow stack pointer, which we need to restore before returning to |
|---|
| 49 | + * potentially instrumented code. This is safe because the wrapper is |
|---|
| 50 | + * called with preemption disabled and a separate shadow stack is used |
|---|
| 51 | + * for interrupts. |
|---|
| 46 | 52 | */ |
|---|
| 47 | | - mov x18, x2 |
|---|
| 53 | +#ifdef CONFIG_SHADOW_CALL_STACK |
|---|
| 54 | + ldr_l x18, efi_rt_stack_top |
|---|
| 55 | + ldr x18, [x18, #-16] |
|---|
| 48 | 56 | #endif |
|---|
| 57 | + |
|---|
| 49 | 58 | b efi_handle_corrupted_x18 // tail call |
|---|
| 50 | | -ENDPROC(__efi_rt_asm_wrapper) |
|---|
| 59 | +SYM_FUNC_END(__efi_rt_asm_wrapper) |
|---|