* [Qemu-devel] [PATCH] hw/i386/pc: reject to boot a wrong header magic kernel
@ 2013-03-27 6:10 liguang
2013-03-28 9:42 ` [Qemu-devel] [Qemu-trivial] " Stefan Hajnoczi
0 siblings, 1 reply; 5+ messages in thread
From: liguang @ 2013-03-27 6:10 UTC (permalink / raw)
To: qemu-devel, qemu-trivial; +Cc: 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.
Signed-off-by: liguang <lig.fnst@cn.fujitsu.com>
---
hw/i386/pc.c | 4 +++-
1 files changed, 3 insertions(+), 1 deletions(-)
diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index b1e06fa..2b78dfc 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -683,8 +683,10 @@ 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, "please assure specicified kernel is for x86!\n");
+ exit(1);
}
- protocol = 0;
}
if (protocol < 0x200 || !(header[0x211] & 0x01)) {
--
1.7.2.5
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [Qemu-trivial] [PATCH] hw/i386/pc: reject to boot a wrong header magic kernel
2013-03-27 6:10 [Qemu-devel] [PATCH] hw/i386/pc: reject to boot a wrong header magic kernel liguang
@ 2013-03-28 9:42 ` Stefan Hajnoczi
2013-03-29 0:38 ` li guang
0 siblings, 1 reply; 5+ messages in thread
From: Stefan Hajnoczi @ 2013-03-28 9:42 UTC (permalink / raw)
To: liguang; +Cc: qemu-trivial, qemu-devel
On Wed, Mar 27, 2013 at 02:10:31PM +0800, liguang wrote:
> 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.
>
> Signed-off-by: liguang <lig.fnst@cn.fujitsu.com>
> ---
> hw/i386/pc.c | 4 +++-
> 1 files changed, 3 insertions(+), 1 deletions(-)
>
> diff --git a/hw/i386/pc.c b/hw/i386/pc.c
> index b1e06fa..2b78dfc 100644
> --- a/hw/i386/pc.c
> +++ b/hw/i386/pc.c
> @@ -683,8 +683,10 @@ 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, "please assure specicified kernel is for x86!\n");
> + exit(1);
load_multiboot() can fail for other reasons so this error messing is
misleading. Giving QEMU a non-x86 kernel is just one scenario where
this may fail.
> }
> - protocol = 0;
> }
Why did you drop protocol = 0?
Stefan
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [Qemu-trivial] [PATCH] hw/i386/pc: reject to boot a wrong header magic kernel
2013-03-28 9:42 ` [Qemu-devel] [Qemu-trivial] " Stefan Hajnoczi
@ 2013-03-29 0:38 ` li guang
2013-03-29 14:46 ` Stefan Hajnoczi
0 siblings, 1 reply; 5+ messages in thread
From: li guang @ 2013-03-29 0:38 UTC (permalink / raw)
To: Stefan Hajnoczi; +Cc: qemu-trivial, qemu-devel
在 2013-03-28四的 10:42 +0100,Stefan Hajnoczi写道:
> On Wed, Mar 27, 2013 at 02:10:31PM +0800, liguang wrote:
> > 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.
> >
> > Signed-off-by: liguang <lig.fnst@cn.fujitsu.com>
> > ---
> > hw/i386/pc.c | 4 +++-
> > 1 files changed, 3 insertions(+), 1 deletions(-)
> >
> > diff --git a/hw/i386/pc.c b/hw/i386/pc.c
> > index b1e06fa..2b78dfc 100644
> > --- a/hw/i386/pc.c
> > +++ b/hw/i386/pc.c
> > @@ -683,8 +683,10 @@ 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, "please assure specicified kernel is for x86!\n");
> > + exit(1);
>
> load_multiboot() can fail for other reasons so this error messing is
> misleading. Giving QEMU a non-x86 kernel is just one scenario where
> this may fail.
according to my check of load_mutiboot function,
mostly it will return 0 if it's not multboot,
or 1 it's a multiboot, so print this message,
or can I just print "wrong kernel image!" ?
>
> > }
> > - protocol = 0;
> > }
>
> Why did you drop protocol = 0?
I think we only want either normal or multi boot linux kernel,
I can't see meaning let other case go on.
so, here, if a normal kernel, OK, go on,
if multiboot, OK, go on,
others, NO, end up.
so, "protocol = 0" is meaningless here.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [Qemu-trivial] [PATCH] hw/i386/pc: reject to boot a wrong header magic kernel
2013-03-29 0:38 ` li guang
@ 2013-03-29 14:46 ` Stefan Hajnoczi
2013-04-01 1:16 ` li guang
0 siblings, 1 reply; 5+ messages in thread
From: Stefan Hajnoczi @ 2013-03-29 14:46 UTC (permalink / raw)
To: li guang; +Cc: qemu-trivial, qemu-devel
On Fri, Mar 29, 2013 at 1:38 AM, li guang <lig.fnst@cn.fujitsu.com> wrote:
> 在 2013-03-28四的 10:42 +0100,Stefan Hajnoczi写道:
>> On Wed, Mar 27, 2013 at 02:10:31PM +0800, liguang wrote:
>> > 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.
>> >
>> > Signed-off-by: liguang <lig.fnst@cn.fujitsu.com>
>> > ---
>> > hw/i386/pc.c | 4 +++-
>> > 1 files changed, 3 insertions(+), 1 deletions(-)
>> >
>> > diff --git a/hw/i386/pc.c b/hw/i386/pc.c
>> > index b1e06fa..2b78dfc 100644
>> > --- a/hw/i386/pc.c
>> > +++ b/hw/i386/pc.c
>> > @@ -683,8 +683,10 @@ 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, "please assure specicified kernel is for x86!\n");
>> > + exit(1);
>>
>> load_multiboot() can fail for other reasons so this error messing is
>> misleading. Giving QEMU a non-x86 kernel is just one scenario where
>> this may fail.
>
> according to my check of load_mutiboot function,
> mostly it will return 0 if it's not multboot,
> or 1 it's a multiboot, so print this message,
> or can I just print "wrong kernel image!" ?
Yes, load_multiboot() fails if the image is not a valid multiboot
image. An error message like "not a valid multiboot image" is good.
>>
>> > }
>> > - protocol = 0;
>> > }
>>
>> Why did you drop protocol = 0?
>
> I think we only want either normal or multi boot linux kernel,
> I can't see meaning let other case go on.
> so, here, if a normal kernel, OK, go on,
> if multiboot, OK, go on,
> others, NO, end up.
> so, "protocol = 0" is meaningless here.
I looked in more detail now and here is why we cannot drop this line of code:
uint16_t protocol;
Note that the variable is not initialized.
[...]
if (ldl_p(header+0x202) == 0x53726448)
protocol = lduw_p(header+0x206);
else {
/* This looks like a multiboot kernel. If it is, let's stop
treating it like a Linux kernel. */
if (load_multiboot(fw_cfg, f, kernel_filename, initrd_filename,
kernel_cmdline, kernel_size, header))
return;
protocol = 0;
Set it to 0 here so it's initialized
}
if (protocol < 0x200 || !(header[0x211] & 0x01)) {
Use variable here - so we *must* initialize it before use.
Stefan
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [Qemu-trivial] [PATCH] hw/i386/pc: reject to boot a wrong header magic kernel
2013-03-29 14:46 ` Stefan Hajnoczi
@ 2013-04-01 1:16 ` li guang
0 siblings, 0 replies; 5+ messages in thread
From: li guang @ 2013-04-01 1:16 UTC (permalink / raw)
To: Stefan Hajnoczi; +Cc: qemu-trivial, qemu-devel
OK, Thanks!
I will update this patch as your comment.
在 2013-03-29五的 15:46 +0100,Stefan Hajnoczi写道:
> On Fri, Mar 29, 2013 at 1:38 AM, li guang <lig.fnst@cn.fujitsu.com> wrote:
> > 在 2013-03-28四的 10:42 +0100,Stefan Hajnoczi写道:
> >> On Wed, Mar 27, 2013 at 02:10:31PM +0800, liguang wrote:
> >> > 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.
> >> >
> >> > Signed-off-by: liguang <lig.fnst@cn.fujitsu.com>
> >> > ---
> >> > hw/i386/pc.c | 4 +++-
> >> > 1 files changed, 3 insertions(+), 1 deletions(-)
> >> >
> >> > diff --git a/hw/i386/pc.c b/hw/i386/pc.c
> >> > index b1e06fa..2b78dfc 100644
> >> > --- a/hw/i386/pc.c
> >> > +++ b/hw/i386/pc.c
> >> > @@ -683,8 +683,10 @@ 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, "please assure specicified kernel is for x86!\n");
> >> > + exit(1);
> >>
> >> load_multiboot() can fail for other reasons so this error messing is
> >> misleading. Giving QEMU a non-x86 kernel is just one scenario where
> >> this may fail.
> >
> > according to my check of load_mutiboot function,
> > mostly it will return 0 if it's not multboot,
> > or 1 it's a multiboot, so print this message,
> > or can I just print "wrong kernel image!" ?
>
> Yes, load_multiboot() fails if the image is not a valid multiboot
> image. An error message like "not a valid multiboot image" is good.
>
> >>
> >> > }
> >> > - protocol = 0;
> >> > }
> >>
> >> Why did you drop protocol = 0?
> >
> > I think we only want either normal or multi boot linux kernel,
> > I can't see meaning let other case go on.
> > so, here, if a normal kernel, OK, go on,
> > if multiboot, OK, go on,
> > others, NO, end up.
> > so, "protocol = 0" is meaningless here.
>
> I looked in more detail now and here is why we cannot drop this line of code:
>
> uint16_t protocol;
>
> Note that the variable is not initialized.
>
> [...]
> if (ldl_p(header+0x202) == 0x53726448)
> protocol = lduw_p(header+0x206);
> else {
> /* This looks like a multiboot kernel. If it is, let's stop
> treating it like a Linux kernel. */
> if (load_multiboot(fw_cfg, f, kernel_filename, initrd_filename,
> kernel_cmdline, kernel_size, header))
> return;
> protocol = 0;
>
> Set it to 0 here so it's initialized
>
> }
> if (protocol < 0x200 || !(header[0x211] & 0x01)) {
>
> Use variable here - so we *must* initialize it before use.
>
> Stefan
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2013-04-01 1:19 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-03-27 6:10 [Qemu-devel] [PATCH] hw/i386/pc: reject to boot a wrong header magic kernel liguang
2013-03-28 9:42 ` [Qemu-devel] [Qemu-trivial] " Stefan Hajnoczi
2013-03-29 0:38 ` li guang
2013-03-29 14:46 ` Stefan Hajnoczi
2013-04-01 1:16 ` li guang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).