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