]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
efi/arm: Disable LPAE PAN when calling EFI runtime services
authorArd Biesheuvel <ardb@kernel.org>
Mon, 10 Jun 2024 12:12:45 +0000 (14:12 +0200)
committerArd Biesheuvel <ardb@kernel.org>
Sat, 15 Jun 2024 08:25:02 +0000 (10:25 +0200)
EFI runtime services are remapped into the lower 1 GiB of virtual
address space at boot, so they are guaranteed to be able to co-exist
with the kernel virtual mappings without the need to allocate space for
them in the kernel's vmalloc region, which is rather small.

This means those mappings are covered by TTBR0 when LPAE PAN is enabled,
and so 'user' access must be enabled while such calls are in progress.

Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
arch/arm/include/asm/efi.h

index 78282ced50387dd31f9c366d5b7423ebc1f4f92f..e408399d5f0e65b0d532931ba688ebd7693ba731 100644 (file)
@@ -14,6 +14,7 @@
 #include <asm/mach/map.h>
 #include <asm/mmu_context.h>
 #include <asm/ptrace.h>
+#include <asm/uaccess.h>
 
 #ifdef CONFIG_EFI
 void efi_init(void);
@@ -25,6 +26,18 @@ int efi_set_mapping_permissions(struct mm_struct *mm, efi_memory_desc_t *md, boo
 #define arch_efi_call_virt_setup()     efi_virtmap_load()
 #define arch_efi_call_virt_teardown()  efi_virtmap_unload()
 
+#ifdef CONFIG_CPU_TTBR0_PAN
+#undef arch_efi_call_virt
+#define arch_efi_call_virt(p, f, args...) ({                           \
+       unsigned int flags = uaccess_save_and_enable();                 \
+       efi_status_t res = _Generic((p)->f(args),                       \
+                       efi_status_t:   (p)->f(args),                   \
+                       default:        ((p)->f(args), EFI_ABORTED));   \
+       uaccess_restore(flags);                                         \
+       res;                                                            \
+})
+#endif
+
 #define ARCH_EFI_IRQ_FLAGS_MASK \
        (PSR_J_BIT | PSR_E_BIT | PSR_A_BIT | PSR_I_BIT | PSR_F_BIT | \
         PSR_T_BIT | MODE_MASK)