multiboot: copy the cmdline verbatim
Quoted 2 lines · Vlad Lungu
get_opt_value()truncates the value at the first comma. Usememcpy()instead.
Looks good since get_opt_value is already used by the caller. Have you tested this with multiple initrd modules too?
Paolo
Quoted 19 lines
Signed-off-by Vlad Lungu <[email protected]>--- hw/i386/multiboot.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/i386/multiboot.c +1
-1@@ -109,7 +109,7 @@ static uint32_t mb_add_cmdline(MultibootState *s, const char *cmdline)hwaddr p = s->offset_cmdlines;char *b = (char *)s->mb_buf + p; -get_opt_value (b,strlen (cmdline) +1 , cmdline); +memcpy (b, cmdline,strlen (cmdline) +1 ); s->offset_cmdlines +=strlen (b) +1 ;return s->mb_buf_phys + p; }
Quoted 8 lines · Paolo Bonzini
Quoted 2 lines · Vlad Lungu
get_opt_value()truncates the value at the first comma. Usememcpy()instead.Looks good since
get_opt_valueis already used by the caller. Have you tested this with multiple initrd modules too?
get_opt_value() is used by the caller, but with NULL buf argument. This means the caller doesn't handle ",," escaping. (See my reply to the previous submission of this patch)
However this only means the caller is buggy, not mb_add_cmdline(). So the change still looks good to me.
Quoted 22 lines
Paolo
Quoted 19 lines
Signed-off-by Vlad Lungu <[email protected]>--- hw/i386/multiboot.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/i386/multiboot.c +1
-1@@ -109,7 +109,7 @@ static uint32_t mb_add_cmdline(MultibootState *s, const char *cmdline)hwaddr p = s->offset_cmdlines;char *b = (char *)s->mb_buf + p; -get_opt_value (b,strlen (cmdline) +1 , cmdline); +memcpy (b, cmdline,strlen (cmdline) +1 ); s->offset_cmdlines +=strlen (b) +1 ;return s->mb_buf_phys + p; }
Signature · 1 line
Eduardo
Quoted 7 lines · Eduardo Habkost
Quoted 6 lines · Paolo Bonzini
Quoted 2 lines · Vlad Lungu
get_opt_value()truncates the value at the first comma. Usememcpy()instead.
Quoted 6 lines
Quoted 2 lines
Looks good since
get_opt_valueis already used by the caller. Have you tested this with multiple initrd modules too?
get_opt_value()is used by the caller, but with NULL buf argument. This means the caller doesn't handle ",," escaping. (See my reply to the previous submission of this patch)
Hmm, wait. When NULL is passed, ",," escaping is handled correctly in that next_initrd points to the next lone comma. The lone comma is replaced with a '\0' by the caller.
So you need to use get_opt_value again in mb_add_cmdline to do the unescaping, because mb_add_cmdline only receives double commas.
This was actually my first reaction to the patch, and it was correct. Then I overthought it. :)
So the patch is wrong.
Paolo
Quoted 26 lines
However this only means the caller is buggy, not
mb_add_cmdline(). So the change still looks good to me.Quoted 22 lines
Paolo
Quoted 19 lines
Signed-off-by Vlad Lungu <[email protected]>--- hw/i386/multiboot.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/i386/multiboot.c +1
-1@@ -109,7 +109,7 @@ static uint32_t mb_add_cmdline(MultibootState *s, const char *cmdline)hwaddr p = s->offset_cmdlines;char *b = (char *)s->mb_buf + p; -get_opt_value (b,strlen (cmdline) +1 , cmdline); +memcpy (b, cmdline,strlen (cmdline) +1 ); s->offset_cmdlines +=strlen (b) +1 ;return s->mb_buf_phys + p; }
Quoted 11 lines · Paolo Bonzini
Quoted 10 lines · Eduardo Habkost
Quoted 8 lines · Paolo Bonzini
Quoted 2 lines · Vlad Lungu
get_opt_value()truncates the value at the first comma. Usememcpy()instead.Looks good since
get_opt_valueis already used by the caller. Have you tested this with multiple initrd modules too?
Quoted 7 lines
Quoted 3 lines
get_opt_value()is used by the caller, but with NULL buf argument. This means the caller doesn't handle ",," escaping. (See my reply to the previous submission of this patch)Hmm, wait. When NULL is passed, ",," escaping is handled correctly in that
next_initrdpoints to the next lone comma. The lone comma is replaced with a '\0' by the caller.
It is handled correctly when splitting the string, but not when opening the file.
Quoted 8 lines
So you need to use
get_opt_valueagain inmb_add_cmdlineto do the unescaping, becausemb_add_cmdlineonly receives double commas.This was actually my first reaction to the patch, and it was correct. Then I overthought it. :)
So the patch is wrong.
Except that the caller is already broken when using ",," for a different reason: it calls get_image_size(initrd_filename) and load_image(initrd_filename, ...) directly. So comma-escaping never worked anyway:
$ qemu-system-x86_64 -kernel ~/Downloads/gnumach -initrd /tmp/one,,file,/tmp/another,,file Failed to open file '/tmp/one,,file'
The right fix for comma-escaping would require calling get_opt_value() with non-NULL buf outside mb_add_cmdline(), because the mb_add_cmdline(&mbs, kcmdline) call do NOT need get_opt_value() to be called.
In other words: this fixes the mb_add_cmdline(kcmdline) case, and doesn't break comma escaping on the initrd case (because it was already broken). I don't see a problem with this patch.
Quoted 29 lines
Paolo
Quoted 26 lines
However this only means the caller is buggy, not
mb_add_cmdline(). So the change still looks good to me.Quoted 22 lines
Paolo
Quoted 19 lines
Signed-off-by Vlad Lungu <[email protected]>--- hw/i386/multiboot.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/i386/multiboot.c +1
-1@@ -109,7 +109,7 @@ static uint32_t mb_add_cmdline(MultibootState *s, const char *cmdline)hwaddr p = s->offset_cmdlines;char *b = (char *)s->mb_buf + p; -get_opt_value (b,strlen (cmdline) +1 , cmdline); +memcpy (b, cmdline,strlen (cmdline) +1 ); s->offset_cmdlines +=strlen (b) +1 ;return s->mb_buf_phys + p; }
Signature · 1 line
Eduardo
PATCH 1/1 multiboot: copy the cmdline verbatim
get_opt_value() truncates the value at the first comma. Use memcpy() instead.
--- hw/i386/multiboot.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/i386/multiboot.c +1 -1
@@ -109,7 +109,7 @@ static uint32_t mb_add_cmdline(MultibootState *s, const char *cmdline)hwaddr p = s->offset_cmdlines;char *b = (char *)s->mb_buf + p; -get_opt_value (b,strlen (cmdline) +1 , cmdline); +memcpy (b, cmdline,strlen (cmdline) +1 ); s->offset_cmdlines +=strlen (b) +1 ;return s->mb_buf_phys + p; }
Signature · 1 line
1.9.1
----- Original Message -----
Quoted 43 lines
From: "Eduardo Habkost" <[email protected]>
To: "Paolo Bonzini" <[email protected]>
Cc: "Vlad Lungu" <[email protected]>, [email protected], [email protected]
Sent: Wednesday, December 14, 2016 6:51:44 PM
Subject: Re: [PATCH] multiboot: copy the cmdline verbatimQuoted 11 lines · Paolo Bonzini
Quoted 10 lines · Eduardo Habkost
Quoted 8 lines · Paolo Bonzini
Quoted 2 lines · Vlad Lungu
get_opt_value()truncates the value at the first comma. Usememcpy()instead.Looks good since
get_opt_valueis already used by the caller. Have you tested this with multiple initrd modules too?Quoted 7 lines
Quoted 3 lines
get_opt_value()is used by the caller, but with NULL buf argument. This means the caller doesn't handle ",," escaping. (See my reply to the previous submission of this patch)Hmm, wait. When NULL is passed, ",," escaping is handled correctly in that
next_initrdpoints to the next lone comma. The lone comma is replaced with a '\0' by the caller.It is handled correctly when splitting the string, but not when opening the file.
Quoted 8 lines
So you need to use
get_opt_valueagain inmb_add_cmdlineto do the unescaping, becausemb_add_cmdlineonly receives double commas.This was actually my first reaction to the patch, and it was correct. Then I overthought it. :)
So the patch is wrong.
Except that the caller is already broken when using ",," for a different reason: it calls
get_image_size(initrd_filename)andload_image(initrd_filename, ...)directly. So comma-escaping never worked anyway:
Quoted 8 lines
$ qemu-system-x86_64 -kernel ~/Downloads/gnumach -initrd /tmp/one,,file,/tmp/another,,file Failed to open file '/tmp/one,,file'The right fix for comma-escaping would require calling
get_opt_value()with non-NULL buf outsidemb_add_cmdline(), because themb_add_cmdline(&mbs, kcmdline)call do NOT needget_opt_value()to be called.
For filenames containing commas you're right, but...
Quoted 3 lines
In other words: this fixes the
mb_add_cmdline(kcmdline)case, and doesn't break comma escaping on the initrd case (because it was already broken). I don't see a problem with this patch.
... there is one case of comma escaping that wasn't broken:
$ qemu-system-x86_64 -kernel foo -initrd '/tmp/one arg,,with,,commas,/tmp/another arg,,with,,commas'
And presumably this is what Vlad was trying to do.
Paolo
Quoted 57 lines · Paolo Bonzini
----- Original Message -----
Quoted 43 lines
From: "Eduardo Habkost" <[email protected]>
To: "Paolo Bonzini" <[email protected]>
Cc: "Vlad Lungu" <[email protected]>, [email protected], [email protected]
Sent: Wednesday, December 14, 2016 6:51:44 PM
Subject: Re: [PATCH] multiboot: copy the cmdline verbatimQuoted 11 lines · Paolo Bonzini
Quoted 10 lines · Eduardo Habkost
Quoted 8 lines · Paolo Bonzini
Quoted 2 lines · Vlad Lungu
get_opt_value()truncates the value at the first comma. Usememcpy()instead.Looks good since
get_opt_valueis already used by the caller. Have you tested this with multiple initrd modules too?Quoted 7 lines
Quoted 3 lines
get_opt_value()is used by the caller, but with NULL buf argument. This means the caller doesn't handle ",," escaping. (See my reply to the previous submission of this patch)Hmm, wait. When NULL is passed, ",," escaping is handled correctly in that
next_initrdpoints to the next lone comma. The lone comma is replaced with a '\0' by the caller.It is handled correctly when splitting the string, but not when opening the file.
Quoted 8 lines
So you need to use
get_opt_valueagain inmb_add_cmdlineto do the unescaping, becausemb_add_cmdlineonly receives double commas.This was actually my first reaction to the patch, and it was correct. Then I overthought it. :)
So the patch is wrong.
Except that the caller is already broken when using ",," for a different reason: it calls
get_image_size(initrd_filename)andload_image(initrd_filename, ...)directly. So comma-escaping never worked anyway:Quoted 8 lines
$ qemu-system-x86_64 -kernel ~/Downloads/gnumach -initrd /tmp/one,,file,/tmp/another,,file Failed to open file '/tmp/one,,file'The right fix for comma-escaping would require calling
get_opt_value()with non-NULL buf outsidemb_add_cmdline(), because themb_add_cmdline(&mbs, kcmdline)call do NOT needget_opt_value()to be called.For filenames containing commas you're right, but...
Quoted 8 lines
Quoted 3 lines
In other words: this fixes the
mb_add_cmdline(kcmdline)case, and doesn't break comma escaping on the initrd case (because it was already broken). I don't see a problem with this patch.... there is one case of comma escaping that wasn't broken:
$ qemu-system-x86_64 -kernel foo -initrd '/tmp/one arg,,with,,commas,/tmp/another arg,,with,,commas'
Oh, I didn't notice the whitespace-based split for initrd arguments.
This is messier than I thought. Maybe the simplest solution is to inline mb_add_cmdline() at both callers, and change the kcmdline one to use memcpy().
Quoted 1 line
And presumably this is what Vlad was trying to do.
I believe he was trying to fix -append, not -initrd. The patch fixes -append, but breaks comma-escaping on -initrd.
Signature · 1 line
Eduardo
Quoted 10 lines
Quoted 9 lines
Quoted 3 lines
In other words: this fixes the
mb_add_cmdline(kcmdline)case, and doesn't break comma escaping on the initrd case (because it was already broken). I don't see a problem with this patch.... there is one case of comma escaping that wasn't broken:
$ qemu-system-x86_64 -kernel foo -initrd '/tmp/one arg,,with,,commas,/tmp/another arg,,with,,commas'
Quoted 6 lines
Oh, I didn't notice the whitespace-based split for initrd arguments.
This is messier than I thought. Maybe the simplest solution is to inline
mb_add_cmdline()at both callers, and change the kcmdline one to usememcpy().
Yes, I agree.
Paolo
Quoted 10 lines · Paolo Bonzini
Quoted 10 lines
Quoted 8 lines
Quoted 3 lines
In other words: this fixes the
mb_add_cmdline(kcmdline)case, and doesn't break comma escaping on the initrd case (because it was already broken). I don't see a problem with this patch.... there is one case of comma escaping that wasn't broken:
$ qemu-system-x86_64 -kernel foo -initrd '/tmp/one arg,,with,,commas,/tmp/another arg,,with,,commas'Oh, I didn't notice the whitespace-based split for initrd arguments.
So that's how it works :-)
Quoted 4 lines
Quoted 3 lines
This is messier than I thought. Maybe the simplest solution is to inline
mb_add_cmdline()at both callers, and change the kcmdline one to usememcpy().
OK, I have a new version that does with memcpy for the cmdline, with get_opt_value() for the modules and also unescapes the filename for get_image_size()/load_image() . You still can't have spaces in filenames, so maybe a new scheme should be devised for this.
Regards,
Vlad