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