nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

Blame SOURCES/0220-Arm-check-for-the-PE-magic-for-the-compiled-arch.patch

8e15ce
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
8e15ce
From: Peter Jones <pjones@redhat.com>
8e15ce
Date: Thu, 9 Sep 2021 10:59:28 -0400
8e15ce
Subject: [PATCH] Arm: check for the PE magic for the compiled arch
8e15ce
8e15ce
In "arm64: Fix EFI loader kernel image allocation", Ben fixed the kernel
8e15ce
alignment to match the alignment given in the PE header.  In doing so, a
8e15ce
check for valid PE magic was added, which was hard-coded to the value
8e15ce
seen on Aarch64 (GRUB_PE32_PE64_MAGIC).
8e15ce
8e15ce
Unfortunately, this code is shared between 64-bit and 32-bit, and so
8e15ce
that value broke 32-bit Arm systems.
8e15ce
8e15ce
This patch adds a constant definition for GRUB_PE32_PEXX_MAGIC, which is
8e15ce
either GRUB_PE32_PE64_MAGIC or GRUB_PE32_PE32_MAGIC, depending on which
8e15ce
platform is being built, and uses it in the header magic check.
8e15ce
8e15ce
Resolves: rhbz#2000756
8e15ce
8e15ce
Signed-off-by: Peter Jones <pjones@redhat.com>
8e15ce
---
8e15ce
 grub-core/loader/arm64/linux.c | 2 +-
8e15ce
 include/grub/arm/linux.h       | 1 +
8e15ce
 include/grub/arm64/linux.h     | 1 +
8e15ce
 3 files changed, 3 insertions(+), 1 deletion(-)
8e15ce
8e15ce
diff --git a/grub-core/loader/arm64/linux.c b/grub-core/loader/arm64/linux.c
8e15ce
index 4a252d5e7e9..f18d90bd749 100644
8e15ce
--- a/grub-core/loader/arm64/linux.c
8e15ce
+++ b/grub-core/loader/arm64/linux.c
8e15ce
@@ -322,7 +322,7 @@ parse_pe_header (void *kernel, grub_uint64_t *total_size,
8e15ce
 
8e15ce
   pe = (void *)((unsigned long)kernel + lh->hdr_offset);
8e15ce
 
8e15ce
-  if (pe->opt.magic != GRUB_PE32_PE64_MAGIC)
8e15ce
+  if (pe->opt.magic != GRUB_PE32_PEXX_MAGIC)
8e15ce
     return grub_error(GRUB_ERR_BAD_OS, "Invalid PE optional header magic");
8e15ce
 
8e15ce
   *total_size   = pe->opt.image_size;
8e15ce
diff --git a/include/grub/arm/linux.h b/include/grub/arm/linux.h
8e15ce
index b582f67f661..966a5074f53 100644
8e15ce
--- a/include/grub/arm/linux.h
8e15ce
+++ b/include/grub/arm/linux.h
8e15ce
@@ -44,6 +44,7 @@ struct grub_arm_linux_pe_header
8e15ce
 
8e15ce
 #if defined(__arm__)
8e15ce
 # define GRUB_LINUX_ARMXX_MAGIC_SIGNATURE GRUB_LINUX_ARM_MAGIC_SIGNATURE
8e15ce
+# define GRUB_PE32_PEXX_MAGIC GRUB_PE32_PE32_MAGIC
8e15ce
 # define linux_arch_kernel_header linux_arm_kernel_header
8e15ce
 # define grub_armxx_linux_pe_header grub_arm_linux_pe_header
8e15ce
 #endif
8e15ce
diff --git a/include/grub/arm64/linux.h b/include/grub/arm64/linux.h
8e15ce
index ea030312df3..422bf2bf24b 100644
8e15ce
--- a/include/grub/arm64/linux.h
8e15ce
+++ b/include/grub/arm64/linux.h
8e15ce
@@ -48,6 +48,7 @@ struct grub_arm64_linux_pe_header
8e15ce
 
8e15ce
 #if defined(__aarch64__)
8e15ce
 # define GRUB_LINUX_ARMXX_MAGIC_SIGNATURE GRUB_LINUX_ARM64_MAGIC_SIGNATURE
8e15ce
+# define GRUB_PE32_PEXX_MAGIC GRUB_PE32_PE64_MAGIC
8e15ce
 # define linux_arch_kernel_header linux_arm64_kernel_header
8e15ce
 # define grub_armxx_linux_pe_header grub_arm64_linux_pe_header
8e15ce
 #endif