From a09be092dca3b51351c550c8c282cea184b4103e Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Thu, 9 Sep 2021 11:05:44 -0400 Subject: [PATCH] Fix the 32-bit Arm PE header magic check Resolves: rhbz#2000756 Signed-off-by: Peter Jones --- ...r-the-PE-magic-for-the-compiled-arch.patch | 61 +++++++++++++++++++ grub.patches | 1 + grub2.spec | 6 +- 3 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 0217-Arm-check-for-the-PE-magic-for-the-compiled-arch.patch diff --git a/0217-Arm-check-for-the-PE-magic-for-the-compiled-arch.patch b/0217-Arm-check-for-the-PE-magic-for-the-compiled-arch.patch new file mode 100644 index 0000000..9b8e1f2 --- /dev/null +++ b/0217-Arm-check-for-the-PE-magic-for-the-compiled-arch.patch @@ -0,0 +1,61 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Thu, 9 Sep 2021 10:59:28 -0400 +Subject: [PATCH] Arm: check for the PE magic for the compiled arch + +In "arm64: Fix EFI loader kernel image allocation", Ben fixed the kernel +alignment to match the alignment given in the PE header. In doing so, a +check for valid PE magic was added, which was hard-coded to the value +seen on Aarch64 (GRUB_PE32_PE64_MAGIC). + +Unfortunately, this code is shared between 64-bit and 32-bit, and so +that value broke 32-bit Arm systems. + +This patch adds a constant definition for GRUB_PE32_PEXX_MAGIC, which is +either GRUB_PE32_PE64_MAGIC or GRUB_PE32_PE32_MAGIC, depending on which +platform is being built, and uses it in the header magic check. + +Signed-off-by: Peter Jones +--- + grub-core/loader/arm64/linux.c | 2 +- + include/grub/arm/linux.h | 1 + + include/grub/arm64/linux.h | 1 + + 3 files changed, 3 insertions(+), 1 deletion(-) + +diff --git a/grub-core/loader/arm64/linux.c b/grub-core/loader/arm64/linux.c +index 4a252d5e7e9..f18d90bd749 100644 +--- a/grub-core/loader/arm64/linux.c ++++ b/grub-core/loader/arm64/linux.c +@@ -322,7 +322,7 @@ parse_pe_header (void *kernel, grub_uint64_t *total_size, + + pe = (void *)((unsigned long)kernel + lh->hdr_offset); + +- if (pe->opt.magic != GRUB_PE32_PE64_MAGIC) ++ if (pe->opt.magic != GRUB_PE32_PEXX_MAGIC) + return grub_error(GRUB_ERR_BAD_OS, "Invalid PE optional header magic"); + + *total_size = pe->opt.image_size; +diff --git a/include/grub/arm/linux.h b/include/grub/arm/linux.h +index b582f67f661..966a5074f53 100644 +--- a/include/grub/arm/linux.h ++++ b/include/grub/arm/linux.h +@@ -44,6 +44,7 @@ struct grub_arm_linux_pe_header + + #if defined(__arm__) + # define GRUB_LINUX_ARMXX_MAGIC_SIGNATURE GRUB_LINUX_ARM_MAGIC_SIGNATURE ++# define GRUB_PE32_PEXX_MAGIC GRUB_PE32_PE32_MAGIC + # define linux_arch_kernel_header linux_arm_kernel_header + # define grub_armxx_linux_pe_header grub_arm_linux_pe_header + #endif +diff --git a/include/grub/arm64/linux.h b/include/grub/arm64/linux.h +index ea030312df3..422bf2bf24b 100644 +--- a/include/grub/arm64/linux.h ++++ b/include/grub/arm64/linux.h +@@ -48,6 +48,7 @@ struct grub_arm64_linux_pe_header + + #if defined(__aarch64__) + # define GRUB_LINUX_ARMXX_MAGIC_SIGNATURE GRUB_LINUX_ARM64_MAGIC_SIGNATURE ++# define GRUB_PE32_PEXX_MAGIC GRUB_PE32_PE64_MAGIC + # define linux_arch_kernel_header linux_arm64_kernel_header + # define grub_armxx_linux_pe_header grub_arm64_linux_pe_header + #endif diff --git a/grub.patches b/grub.patches index 4940f65..f7bf1e3 100644 --- a/grub.patches +++ b/grub.patches @@ -214,3 +214,4 @@ Patch0213: 0213-Remove-outdated-URL-for-BLS-document.patch Patch0214: 0214-templates-Check-for-EFI-at-runtime-instead-of-config.patch Patch0215: 0215-efi-Print-an-error-if-boot-to-firmware-setup-is-not-.patch Patch0216: 0216-arm64-Fix-EFI-loader-kernel-image-allocation.patch +Patch0217: 0217-Arm-check-for-the-PE-magic-for-the-compiled-arch.patch diff --git a/grub2.spec b/grub2.spec index 6c82b03..4826b54 100644 --- a/grub2.spec +++ b/grub2.spec @@ -14,7 +14,7 @@ Name: grub2 Epoch: 1 Version: 2.06 -Release: 4%{?dist} +Release: 5%{?dist} Summary: Bootloader with support for Linux, Multiboot and more License: GPLv3+ URL: http://www.gnu.org/software/grub/ @@ -523,6 +523,10 @@ mv ${EFI_HOME}/grub.cfg.stb ${EFI_HOME}/grub.cfg %endif %changelog +* Thu Sep 09 2021 Peter Jones - 2.06-5 +- Fix the 32-bit Arm PE header magic check + Resolves: rhbz#2000756 + * Tue Aug 24 2021 Peter Jones - 2.06-4 - Fix aarch64 kernel alignment. - Fix annobin regexp on ppc64le