|
|
b35c50 |
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
b35c50 |
From: Peter Jones <pjones@redhat.com>
|
|
|
b35c50 |
Date: Wed, 9 Feb 2022 16:08:20 -0500
|
|
|
b35c50 |
Subject: [PATCH] EFI: allocate kernel in EFI_RUNTIME_SERVICES_CODE instead of
|
|
|
b35c50 |
EFI_LOADER_DATA.
|
|
|
b35c50 |
|
|
|
b35c50 |
On some of the firmwares with more security mitigations, EFI_LOADER_DATA
|
|
|
b35c50 |
doesn't get you executable memory, and we take a fault and reboot when
|
|
|
b35c50 |
we enter kernel.
|
|
|
b35c50 |
|
|
|
b35c50 |
This patch correctly allocates the kernel code as EFI_RUNTIME_SERVICES_CODE
|
|
|
b35c50 |
rather than EFI_LOADER_DATA.
|
|
|
b35c50 |
|
|
|
b35c50 |
Signed-off-by: Peter Jones <pjones@redhat.com>
|
|
|
b35c50 |
[rharwood: use kernel_size]
|
|
|
b35c50 |
Signed-off-by: Robbie Harwood <rharwood@redhat.com>
|
|
|
b35c50 |
---
|
|
|
b35c50 |
grub-core/loader/i386/efi/linux.c | 19 +++++++++++++------
|
|
|
b35c50 |
1 file changed, 13 insertions(+), 6 deletions(-)
|
|
|
b35c50 |
|
|
|
b35c50 |
diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c
|
|
|
b35c50 |
index 9e5c11ac69..92b2fb5091 100644
|
|
|
b35c50 |
--- a/grub-core/loader/i386/efi/linux.c
|
|
|
b35c50 |
+++ b/grub-core/loader/i386/efi/linux.c
|
|
|
b35c50 |
@@ -86,7 +86,9 @@ kernel_free(void *addr, grub_efi_uintn_t size)
|
|
|
b35c50 |
}
|
|
|
b35c50 |
|
|
|
b35c50 |
static void *
|
|
|
b35c50 |
-kernel_alloc(grub_efi_uintn_t size, const char * const errmsg)
|
|
|
b35c50 |
+kernel_alloc(grub_efi_uintn_t size,
|
|
|
b35c50 |
+ grub_efi_memory_type_t memtype,
|
|
|
b35c50 |
+ const char * const errmsg)
|
|
|
b35c50 |
{
|
|
|
b35c50 |
void *addr = 0;
|
|
|
b35c50 |
unsigned int i;
|
|
|
b35c50 |
@@ -112,7 +114,7 @@ kernel_alloc(grub_efi_uintn_t size, const char * const errmsg)
|
|
|
b35c50 |
prev_max = max;
|
|
|
b35c50 |
addr = grub_efi_allocate_pages_real (max, pages,
|
|
|
b35c50 |
max_addresses[i].alloc_type,
|
|
|
b35c50 |
- GRUB_EFI_LOADER_DATA);
|
|
|
b35c50 |
+ memtype);
|
|
|
b35c50 |
if (addr)
|
|
|
b35c50 |
grub_dprintf ("linux", "Allocated at %p\n", addr);
|
|
|
b35c50 |
}
|
|
|
b35c50 |
@@ -242,7 +244,8 @@ grub_cmd_initrd (grub_command_t cmd, int argc, char *argv[])
|
|
|
b35c50 |
}
|
|
|
b35c50 |
}
|
|
|
b35c50 |
|
|
|
b35c50 |
- initrd_mem = kernel_alloc(size, N_("can't allocate initrd"));
|
|
|
b35c50 |
+ initrd_mem = kernel_alloc(size, GRUB_EFI_RUNTIME_SERVICES_DATA,
|
|
|
b35c50 |
+ N_("can't allocate initrd"));
|
|
|
b35c50 |
if (initrd_mem == NULL)
|
|
|
b35c50 |
goto fail;
|
|
|
b35c50 |
grub_dprintf ("linux", "initrd_mem = %p\n", initrd_mem);
|
|
|
b35c50 |
@@ -393,7 +396,8 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
|
|
b35c50 |
}
|
|
|
b35c50 |
#endif
|
|
|
b35c50 |
|
|
|
b35c50 |
- params = kernel_alloc (sizeof(*params), "cannot allocate kernel parameters");
|
|
|
b35c50 |
+ params = kernel_alloc (sizeof(*params), GRUB_EFI_RUNTIME_SERVICES_DATA,
|
|
|
b35c50 |
+ "cannot allocate kernel parameters");
|
|
|
b35c50 |
if (!params)
|
|
|
b35c50 |
goto fail;
|
|
|
b35c50 |
grub_dprintf ("linux", "params = %p\n", params);
|
|
|
b35c50 |
@@ -415,7 +419,9 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
|
|
b35c50 |
grub_dprintf ("linux", "new lh is at %p\n", lh);
|
|
|
b35c50 |
|
|
|
b35c50 |
grub_dprintf ("linux", "setting up cmdline\n");
|
|
|
b35c50 |
- cmdline = kernel_alloc (lh->cmdline_size + 1, N_("can't allocate cmdline"));
|
|
|
b35c50 |
+ cmdline = kernel_alloc (lh->cmdline_size + 1,
|
|
|
b35c50 |
+ GRUB_EFI_RUNTIME_SERVICES_DATA,
|
|
|
b35c50 |
+ N_("can't allocate cmdline"));
|
|
|
b35c50 |
if (!cmdline)
|
|
|
b35c50 |
goto fail;
|
|
|
b35c50 |
grub_dprintf ("linux", "cmdline = %p\n", cmdline);
|
|
|
b35c50 |
@@ -461,7 +467,8 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
|
|
b35c50 |
max_addresses[1].addr = GRUB_EFI_MAX_ALLOCATION_ADDRESS;
|
|
|
b35c50 |
max_addresses[2].addr = GRUB_EFI_MAX_ALLOCATION_ADDRESS;
|
|
|
b35c50 |
kernel_size = lh->init_size;
|
|
|
b35c50 |
- kernel_mem = kernel_alloc (kernel_size, N_("can't allocate kernel"));
|
|
|
b35c50 |
+ kernel_mem = kernel_alloc (kernel_size, GRUB_EFI_RUNTIME_SERVICES_CODE,
|
|
|
b35c50 |
+ N_("can't allocate kernel"));
|
|
|
b35c50 |
restore_addresses();
|
|
|
b35c50 |
if (!kernel_mem)
|
|
|
b35c50 |
goto fail;
|