From 911f2877da169db8feee683aad28f09b69a13fb7 Mon Sep 17 00:00:00 2001 From: Qiumiao Zhang Date: Thu, 15 Jun 2023 22:12:59 +0800 Subject: [PATCH] Revert "EFI: allocate kernel in EFI_RUNTIME_SERVICES_CODE instead of EFI_LOADER_DATA." Signed-off-by: Qiumiao Zhang (cherry picked from commit 581a5d3a1dc42d71afbc0d9cc6fae11a5d42084a) --- ...ate-kernel-in-EFI_RUNTIME_SERVICES_C.patch | 85 +++++++++++++++++++ grub.patches | 1 + grub2.spec | 9 +- 3 files changed, 93 insertions(+), 2 deletions(-) create mode 100644 Revert-EFI-allocate-kernel-in-EFI_RUNTIME_SERVICES_C.patch diff --git a/Revert-EFI-allocate-kernel-in-EFI_RUNTIME_SERVICES_C.patch b/Revert-EFI-allocate-kernel-in-EFI_RUNTIME_SERVICES_C.patch new file mode 100644 index 0000000..6bc2c97 --- /dev/null +++ b/Revert-EFI-allocate-kernel-in-EFI_RUNTIME_SERVICES_C.patch @@ -0,0 +1,85 @@ +From 53b5629c9402e2d504866b6934303a8f8c2a5641 Mon Sep 17 00:00:00 2001 +From: Qiumiao Zhang +Date: Wed, 10 May 2023 19:11:17 +0800 +Subject: [PATCH] Revert "EFI: allocate kernel in EFI_RUNTIME_SERVICES_CODE + instead of EFI_LOADER_DATA." + +Allocates the kernel code as EFI_RUNTIME_SERVICES_CODE will cause the allocated +memory to be marked as "reserved" by BIOS, which will result in this memory being +always unavailable to the kernel. + +Let's fix it by reverting backport-EFI-allocate-kernel-in-EFI_RUNTIME_SERVICES_CODE-ins.patch. + +Signed-off-by: Qiumiao Zhang +--- + grub-core/loader/i386/efi/linux.c | 19 ++++++------------- + 1 file changed, 6 insertions(+), 13 deletions(-) + +diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c +index 92b2fb5..9e5c11a 100644 +--- a/grub-core/loader/i386/efi/linux.c ++++ b/grub-core/loader/i386/efi/linux.c +@@ -86,9 +86,7 @@ kernel_free(void *addr, grub_efi_uintn_t size) + } + + static void * +-kernel_alloc(grub_efi_uintn_t size, +- grub_efi_memory_type_t memtype, +- const char * const errmsg) ++kernel_alloc(grub_efi_uintn_t size, const char * const errmsg) + { + void *addr = 0; + unsigned int i; +@@ -114,7 +112,7 @@ kernel_alloc(grub_efi_uintn_t size, + prev_max = max; + addr = grub_efi_allocate_pages_real (max, pages, + max_addresses[i].alloc_type, +- memtype); ++ GRUB_EFI_LOADER_DATA); + if (addr) + grub_dprintf ("linux", "Allocated at %p\n", addr); + } +@@ -244,8 +242,7 @@ grub_cmd_initrd (grub_command_t cmd, int argc, char *argv[]) + } + } + +- initrd_mem = kernel_alloc(size, GRUB_EFI_RUNTIME_SERVICES_DATA, +- N_("can't allocate initrd")); ++ initrd_mem = kernel_alloc(size, N_("can't allocate initrd")); + if (initrd_mem == NULL) + goto fail; + grub_dprintf ("linux", "initrd_mem = %p\n", initrd_mem); +@@ -396,8 +393,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + } + #endif + +- params = kernel_alloc (sizeof(*params), GRUB_EFI_RUNTIME_SERVICES_DATA, +- "cannot allocate kernel parameters"); ++ params = kernel_alloc (sizeof(*params), "cannot allocate kernel parameters"); + if (!params) + goto fail; + grub_dprintf ("linux", "params = %p\n", params); +@@ -419,9 +415,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + grub_dprintf ("linux", "new lh is at %p\n", lh); + + grub_dprintf ("linux", "setting up cmdline\n"); +- cmdline = kernel_alloc (lh->cmdline_size + 1, +- GRUB_EFI_RUNTIME_SERVICES_DATA, +- N_("can't allocate cmdline")); ++ cmdline = kernel_alloc (lh->cmdline_size + 1, N_("can't allocate cmdline")); + if (!cmdline) + goto fail; + grub_dprintf ("linux", "cmdline = %p\n", cmdline); +@@ -467,8 +461,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + max_addresses[1].addr = GRUB_EFI_MAX_ALLOCATION_ADDRESS; + max_addresses[2].addr = GRUB_EFI_MAX_ALLOCATION_ADDRESS; + kernel_size = lh->init_size; +- kernel_mem = kernel_alloc (kernel_size, GRUB_EFI_RUNTIME_SERVICES_CODE, +- N_("can't allocate kernel")); ++ kernel_mem = kernel_alloc (kernel_size, N_("can't allocate kernel")); + restore_addresses(); + if (!kernel_mem) + goto fail; +-- +2.19.1 + diff --git a/grub.patches b/grub.patches index 3938552..172a7c5 100644 --- a/grub.patches +++ b/grub.patches @@ -327,3 +327,4 @@ Patch0319: backport-fs-iso9660-Avoid-reading-past-the-entry-boundary.patch Patch0320: backport-net-bootp-Fix-unchecked-return-value.patch Patch0321: backport-osdep-linux-hostdisk-Modify-sector-by-sysfs-as-disk-sector.patch Patch0322: backport-Read-etc-default-grub.d-.cfg-after-etc-default-grub.patch +Patch0323: Revert-EFI-allocate-kernel-in-EFI_RUNTIME_SERVICES_C.patch diff --git a/grub2.spec b/grub2.spec index e407d82..190f4b4 100644 --- a/grub2.spec +++ b/grub2.spec @@ -14,7 +14,7 @@ Name: grub2 Epoch: 1 Version: 2.06 -Release: 29 +Release: 30 Summary: Bootloader with support for Linux, Multiboot and more License: GPLv3+ URL: http://www.gnu.org/software/grub/ @@ -379,7 +379,6 @@ fi %exclude %{_sbindir}/grub2-sparc64-setup %exclude %{_sbindir}/grub2-ofpathname %endif -%exclude %{_sbindir}/grub2-ofpathname %endif @@ -441,6 +440,12 @@ fi %{_datadir}/man/man* %changelog +* Thu Jun 15 2023 zhangqiumiao - 1:2.06-30 +- Type:bugfix +- CVE:NA +- SUG:NA +- DESC:Revert "EFI: allocate kernel in EFI_RUNTIME_SERVICES_CODE + * Sun Apr 23 2023 zhangqiumiao - 1:2.06-29 - Type:requirement - CVE:NA -- Gitee