Skip to content

Commit 7e611e7

Browse files
Ard Biesheuvelingomolnar
authored andcommitted
efi/arm64: Check whether x18 is preserved by runtime services calls
Whether or not we will ever decide to start using x18 as a platform register in Linux is uncertain, but by that time, we will need to ensure that UEFI runtime services calls don't corrupt it. So let's start issuing warnings now for this, and increase the likelihood that these firmware images have all been replaced by that time. This has been fixed on the EDK2 side in commit: 6d73863b5464 ("BaseTools/tools_def AARCH64: mark register x18 as reserved") dated July 13, 2017. Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Acked-by: Will Deacon <will.deacon@arm.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Matt Fleming <matt@codeblueprint.co.uk> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: linux-efi@vger.kernel.org Link: http://lkml.kernel.org/r/20180308080020.22828-6-ard.biesheuvel@linaro.org Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent 1832e64 commit 7e611e7

4 files changed

Lines changed: 52 additions & 2 deletions

File tree

‎arch/arm64/include/asm/efi.h‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ int efi_set_mapping_permissions(struct mm_struct *mm, efi_memory_desc_t *md);
3131
({ \
3232
efi_##f##_t *__f; \
3333
__f = p->f; \
34-
__f(args); \
34+
__efi_rt_asm_wrapper(__f, #f, args); \
3535
})
3636

3737
#define arch_efi_call_virt_teardown() \
@@ -40,6 +40,8 @@ int efi_set_mapping_permissions(struct mm_struct *mm, efi_memory_desc_t *md);
4040
efi_virtmap_unload(); \
4141
})
4242

43+
efi_status_t __efi_rt_asm_wrapper(void *, const char *, ...);
44+
4345
#define ARCH_EFI_IRQ_FLAGS_MASK (PSR_D_BIT | PSR_A_BIT | PSR_I_BIT | PSR_F_BIT)
4446

4547
/* arch specific definitions used by the stub code */

‎arch/arm64/kernel/Makefile‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ arm64-obj-$(CONFIG_CPU_PM) += sleep.o suspend.o
3838
arm64-obj-$(CONFIG_CPU_IDLE) += cpuidle.o
3939
arm64-obj-$(CONFIG_JUMP_LABEL) += jump_label.o
4040
arm64-obj-$(CONFIG_KGDB) += kgdb.o
41-
arm64-obj-$(CONFIG_EFI) += efi.o efi-entry.stub.o
41+
arm64-obj-$(CONFIG_EFI) += efi.o efi-entry.stub.o \
42+
efi-rt-wrapper.o
4243
arm64-obj-$(CONFIG_PCI) += pci.o
4344
arm64-obj-$(CONFIG_ARMV8_DEPRECATED) += armv8_deprecated.o
4445
arm64-obj-$(CONFIG_ACPI) += acpi.o

‎arch/arm64/kernel/efi-rt-wrapper.S‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* 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+
*/
8+
9+
#include <linux/linkage.h>
10+
11+
ENTRY(__efi_rt_asm_wrapper)
12+
stp x29, x30, [sp, #-32]!
13+
mov x29, sp
14+
15+
/*
16+
* Register x18 is designated as the 'platform' register by the AAPCS,
17+
* which means firmware running at the same exception level as the OS
18+
* (such as UEFI) should never touch it.
19+
*/
20+
stp x1, x18, [sp, #16]
21+
22+
/*
23+
* We are lucky enough that no EFI runtime services take more than
24+
* 5 arguments, so all are passed in registers rather than via the
25+
* stack.
26+
*/
27+
mov x8, x0
28+
mov x0, x2
29+
mov x1, x3
30+
mov x2, x4
31+
mov x3, x5
32+
mov x4, x6
33+
blr x8
34+
35+
ldp x1, x2, [sp, #16]
36+
cmp x2, x18
37+
ldp x29, x30, [sp], #32
38+
b.ne 0f
39+
ret
40+
0: b efi_handle_corrupted_x18 // tail call
41+
ENDPROC(__efi_rt_asm_wrapper)

‎arch/arm64/kernel/efi.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,9 @@ bool efi_poweroff_required(void)
126126
{
127127
return efi_enabled(EFI_RUNTIME_SERVICES);
128128
}
129+
130+
asmlinkage efi_status_t efi_handle_corrupted_x18(efi_status_t s, const char *f)
131+
{
132+
pr_err_ratelimited(FW_BUG "register x18 corrupted by EFI %s\n", f);
133+
return s;
134+
}

0 commit comments

Comments
 (0)