Skip to contentSkip to conversation

hw/i386/pc: reject to boot a wrong header magic kernel

PATCH In review liguang 2 participants 3 messages Apr 1, 2013 – Apr 8, 2013

lore
Share & tools
lore

liguang

author
#0 lore raw

PATCH v2 1/1 hw/i386/pc: reject to boot a wrong header magic kernel

if head magic is missing or wrong unexpectedly, we'd better to reject booting.
e.g.
I make a mistake to boot a vmlinuz for MIPS(which I think it's for x86) like this:
qemu-system-x86_64 -kernel vmlinuz -initrd demord then qemu report:
"qemu: linux kernel too old to load a ram disk" that's misleading.

---
 hw/i386/pc.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
hw/i386/pc.c +3 -0
index b1e06fa..bfbb5fe 100644
@@ -683,6 +683,9 @@ static void load_linux(void *fw_cfg,
         if (load_multiboot(fw_cfg, f, kernel_filename, initrd_filename,
                            kernel_cmdline, kernel_size, header)) {
             return;
+        } else {
+            fprintf(stderr, "not a valid multiboot image!\n");
+            exit(1);
         }
         protocol = 0;
     }
Signature · 1 line
1.7.2.5
#1 lore raw
Quoted 20 lines · liguang

if head magic is missing or wrong unexpectedly, we'd better to reject booting.
e.g.
I make a mistake to boot a vmlinuz for MIPS(which I think it's for x86) like this:
qemu-system-x86_64 -kernel vmlinuz -initrd demord then qemu report:
"qemu: linux kernel too old to load a ram disk" that's misleading.

---
 hw/i386/pc.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
hw/i386/pc.c +0 -0
index b1e06fa..bfbb5fe 100644

hw/i386/pc.c static void load_linux(void *fw_cfg, · line 690

Quoted 8 lines
hw/i386/pc.c +3 -0
@@ -683,6 +683,9 @@ static void load_linux(void *fw_cfg,
         if (load_multiboot(fw_cfg, f, kernel_filename, initrd_filename,
                            kernel_cmdline, kernel_size, header)) {
             return;
+        } else {
+            fprintf(stderr, "not a valid multiboot image!\n");
+            exit(1);
         }
         protocol = 0;

The point of protocol = 0 is to support old Linux kernels. If we exit when probing load_multiboot() fails then QEMU will no longer load old Linux kernels!

I suggest just:
fprintf(stderr, "warning: not a valid multiboot or modern kernel image\n");

Stefan

author
#2 lore raw
Quoted 34 lines · 在 2013-04-05五的 14:59 +0200,Stefan Hajnoczi写道:
Quoted 20 lines · liguang

if head magic is missing or wrong unexpectedly, we'd better to reject booting.
e.g.
I make a mistake to boot a vmlinuz for MIPS(which I think it's for x86) like this:
qemu-system-x86_64 -kernel vmlinuz -initrd demord then qemu report:
"qemu: linux kernel too old to load a ram disk" that's misleading.

---
 hw/i386/pc.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
hw/i386/pc.c +0 -0
index b1e06fa..bfbb5fe 100644

hw/i386/pc.c static void load_linux(void *fw_cfg, · line 690

Quoted 8 lines
hw/i386/pc.c +3 -0
@@ -683,6 +683,9 @@ static void load_linux(void *fw_cfg,
         if (load_multiboot(fw_cfg, f, kernel_filename, initrd_filename,
                            kernel_cmdline, kernel_size, header)) {
             return;
+        } else {
+            fprintf(stderr, "not a valid multiboot image!\n");
+            exit(1);
         }
         protocol = 0;

The point of protocol = 0 is to support old Linux kernels. If we exit when probing load_multiboot() fails then QEMU will no longer load old Linux kernels!

Quoted 4 lines

I suggest just:
fprintf(stderr, "warning: not a valid multiboot or modern kernel image\n");

Stefan

OK, Thanks!