Skip to contentSkip to conversation

multiboot: Prevent loading of x86_64 images

PATCH New Adam Lackorzynski 1 participant 1 message Sep 2, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 multiboot: Prevent loading of x86_64 images

A via -kernel supplied x86_64 ELF image is being started in 32bit mode. Detect and exit if a 64bit image has been supplied.

---
 hw/multiboot.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
hw/multiboot.c +6 -0
index dc980e6..e9dcbc9 100644
@@ -171,6 +171,12 @@ int load_multiboot(void *fw_cfg,
         uint64_t elf_low, elf_high;
         int kernel_size;
         fclose(f);
+
+        if (((struct elf64_hdr*)header)->e_machine == EM_X86_64) {
+            fprintf(stderr, "Cannot load x86-64 image, give a 32bit one.\n");
+            exit(1);
+        }
+
         kernel_size = load_elf(kernel_filename, NULL, NULL, &elf_entry,
                                &elf_low, &elf_high, 0, ELF_MACHINE, 0);
         if (kernel_size < 0) {
Signature · 1 line
1.7.1