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