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