Skip to contentSkip to conversation

efi_loader: Check machine type in the image header

PATCH New Ivan Gorinov 2 participants 3 messages Apr 6, 2018

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 efi_loader: Check machine type in the image header

Check FileHeader.Machine to make sure the EFI executable image is built for the same architecture. For example, 32-bit U-Boot on x86 will print an error message instead of loading an x86_64 image and crashing.

---
 include/pe.h                      |  4 +++
 lib/efi_loader/efi_image_loader.c | 51 ++++++++++++++++++++++++++++++---------
 2 files changed, 43 insertions(+), 12 deletions(-)
include/pe.h +4 -0
index c3a19ce..e7845bb 100644
@@ -38,11 +38,15 @@ typedef struct _IMAGE_DOS_HEADER {
 #define IMAGE_DOS_SIGNATURE		0x5A4D     /* MZ   */
 #define IMAGE_NT_SIGNATURE		0x00004550 /* PE00 */
 
+#define IMAGE_FILE_MACHINE_I386		0x014c
 #define IMAGE_FILE_MACHINE_ARM		0x01c0
 #define IMAGE_FILE_MACHINE_THUMB	0x01c2
 #define IMAGE_FILE_MACHINE_ARMNT	0x01c4
 #define IMAGE_FILE_MACHINE_AMD64	0x8664
 #define IMAGE_FILE_MACHINE_ARM64	0xaa64
+#define IMAGE_FILE_MACHINE_RISCV32	0x5032
+#define IMAGE_FILE_MACHINE_RISCV64	0x5064
+
 #define IMAGE_NT_OPTIONAL_HDR32_MAGIC	0x10b
 #define IMAGE_NT_OPTIONAL_HDR64_MAGIC	0x20b
 #define IMAGE_SUBSYSTEM_EFI_APPLICATION	10
lib/efi_loader/efi_image_loader.c +39 -12

81 lines not on this page · raw message

Signature · 1 line
2.7.4
#1 lore raw

PATCH v3 1/1 efi_loader: Check machine type in the image header

Quoted 5 lines · Ivan Gorinov

Check FileHeader.Machine to make sure the EFI executable image is built for the same architecture. For example, 32-bit U-Boot on x86 will print an error message instead of loading an x86_64 image and crashing.

Ah, sorry, I didn't see v3 until after I replied on the other thread. This is pretty much exactly what I wanted to see :).

Thanks!

Alex

#2 lore raw

PATCH v3 1/1 efi_loader: Check machine type in the image header

In reply to Ivan Gorinov
Quoted 5 lines

Check FileHeader.Machine to make sure the EFI executable image is built for the same architecture. For example, 32-bit U-Boot on x86 will print an error message instead of loading an x86_64 image and crashing.

Thanks, applied to efi-next

Alex