|
|
b35c50 |
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
b35c50 |
From: Peter Jones <pjones@redhat.com>
|
|
|
b35c50 |
Date: Fri, 25 Mar 2022 15:40:12 -0400
|
|
|
b35c50 |
Subject: [PATCH] pe: add the DOS header struct and fix some bad naming.
|
|
|
b35c50 |
|
|
|
b35c50 |
In order to properly validate a loaded kernel's support for being loaded
|
|
|
b35c50 |
without a writable stack or executable, we need to be able to properly
|
|
|
b35c50 |
parse arbitrary PE headers.
|
|
|
b35c50 |
|
|
|
b35c50 |
Currently, pe32.h is written in such a way that the MS-DOS header that
|
|
|
b35c50 |
tells us where to find the PE header in the binary can't be accessed.
|
|
|
b35c50 |
Further, for some reason it calls the DOS MZ magic "GRUB_PE32_MAGIC".
|
|
|
b35c50 |
|
|
|
b35c50 |
This patch adds the structure for the DOS header, renames the DOS magic
|
|
|
b35c50 |
define, and adds defines for the actual PE magic.
|
|
|
b35c50 |
|
|
|
b35c50 |
Signed-off-by: Peter Jones <pjones@redhat.com>
|
|
|
b35c50 |
---
|
|
|
b35c50 |
grub-core/loader/arm64/linux.c | 2 +-
|
|
|
b35c50 |
include/grub/efi/pe32.h | 28 ++++++++++++++++++++++++++--
|
|
|
b35c50 |
2 files changed, 27 insertions(+), 3 deletions(-)
|
|
|
b35c50 |
|
|
|
b35c50 |
diff --git a/grub-core/loader/arm64/linux.c b/grub-core/loader/arm64/linux.c
|
|
|
b35c50 |
index d2af47c2c0..cc67f43906 100644
|
|
|
b35c50 |
--- a/grub-core/loader/arm64/linux.c
|
|
|
b35c50 |
+++ b/grub-core/loader/arm64/linux.c
|
|
|
b35c50 |
@@ -58,7 +58,7 @@ grub_arch_efi_linux_check_image (struct linux_arch_kernel_header * lh)
|
|
|
b35c50 |
if (lh->magic != GRUB_LINUX_ARMXX_MAGIC_SIGNATURE)
|
|
|
b35c50 |
return grub_error(GRUB_ERR_BAD_OS, "invalid magic number");
|
|
|
b35c50 |
|
|
|
b35c50 |
- if ((lh->code0 & 0xffff) != GRUB_PE32_MAGIC)
|
|
|
b35c50 |
+ if ((lh->code0 & 0xffff) != GRUB_DOS_MAGIC)
|
|
|
b35c50 |
return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
|
|
|
b35c50 |
N_("plain image kernel not supported - rebuild with CONFIG_(U)EFI_STUB enabled"));
|
|
|
b35c50 |
|
|
|
b35c50 |
diff --git a/include/grub/efi/pe32.h b/include/grub/efi/pe32.h
|
|
|
b35c50 |
index a43adf2746..2a5e1ee003 100644
|
|
|
b35c50 |
--- a/include/grub/efi/pe32.h
|
|
|
b35c50 |
+++ b/include/grub/efi/pe32.h
|
|
|
b35c50 |
@@ -46,7 +46,30 @@
|
|
|
b35c50 |
|
|
|
b35c50 |
#define GRUB_PE32_MSDOS_STUB_SIZE 0x80
|
|
|
b35c50 |
|
|
|
b35c50 |
-#define GRUB_PE32_MAGIC 0x5a4d
|
|
|
b35c50 |
+#define GRUB_DOS_MAGIC 0x5a4d
|
|
|
b35c50 |
+
|
|
|
b35c50 |
+struct grub_dos_header
|
|
|
b35c50 |
+{
|
|
|
b35c50 |
+ grub_uint16_t magic;
|
|
|
b35c50 |
+ grub_uint16_t cblp;
|
|
|
b35c50 |
+ grub_uint16_t cp;
|
|
|
b35c50 |
+ grub_uint16_t crlc;
|
|
|
b35c50 |
+ grub_uint16_t cparhdr;
|
|
|
b35c50 |
+ grub_uint16_t minalloc;
|
|
|
b35c50 |
+ grub_uint16_t maxalloc;
|
|
|
b35c50 |
+ grub_uint16_t ss;
|
|
|
b35c50 |
+ grub_uint16_t sp;
|
|
|
b35c50 |
+ grub_uint16_t csum;
|
|
|
b35c50 |
+ grub_uint16_t ip;
|
|
|
b35c50 |
+ grub_uint16_t cs;
|
|
|
b35c50 |
+ grub_uint16_t lfarlc;
|
|
|
b35c50 |
+ grub_uint16_t ovno;
|
|
|
b35c50 |
+ grub_uint16_t res0[4];
|
|
|
b35c50 |
+ grub_uint16_t oemid;
|
|
|
b35c50 |
+ grub_uint16_t oeminfo;
|
|
|
b35c50 |
+ grub_uint16_t res1[10];
|
|
|
b35c50 |
+ grub_uint32_t lfanew;
|
|
|
b35c50 |
+};
|
|
|
b35c50 |
|
|
|
b35c50 |
/* According to the spec, the minimal alignment is 512 bytes...
|
|
|
b35c50 |
But some examples (such as EFI drivers in the Intel
|
|
|
b35c50 |
@@ -280,7 +303,8 @@ struct grub_pe32_section_table
|
|
|
b35c50 |
|
|
|
b35c50 |
|
|
|
b35c50 |
|
|
|
b35c50 |
-#define GRUB_PE32_SIGNATURE_SIZE 4
|
|
|
b35c50 |
+#define GRUB_PE32_SIGNATURE_SIZE 4
|
|
|
b35c50 |
+#define GRUB_PE32_SIGNATURE "PE\0\0"
|
|
|
b35c50 |
|
|
|
b35c50 |
struct grub_pe32_header
|
|
|
b35c50 |
{
|