* [PATCH v2] q800: fix segfault with invalid MacROM
@ 2022-01-07 10:50 Laurent Vivier
2022-01-07 11:03 ` Thomas Huth
2022-01-07 23:08 ` Mark Cave-Ayland
0 siblings, 2 replies; 3+ messages in thread
From: Laurent Vivier @ 2022-01-07 10:50 UTC (permalink / raw)
To: qemu-devel
Cc: Peter Maydell, Thomas Huth, Mark Cave-Ayland, Laurent Vivier,
Philippe Mathieu-Daudé
"qemu-system-m68k -M q800 -bios /dev/null" crashes with a segfault
in q800_init().
This happens because the code doesn't check that rom_ptr() returned
a non-NULL pointer .
To avoid NULL pointer, don't allow 0 sized file and use bios_size with
rom_ptr().
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/756
Reported-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
hw/m68k/q800.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/hw/m68k/q800.c b/hw/m68k/q800.c
index e4c7c9b88ad0..55dfe5036f40 100644
--- a/hw/m68k/q800.c
+++ b/hw/m68k/q800.c
@@ -672,12 +672,13 @@ static void q800_init(MachineState *machine)
/* Remove qtest_enabled() check once firmware files are in the tree */
if (!qtest_enabled()) {
- if (bios_size < 0 || bios_size > MACROM_SIZE) {
+ if (bios_size <= 0 || bios_size > MACROM_SIZE) {
error_report("could not load MacROM '%s'", bios_name);
exit(1);
}
- ptr = rom_ptr(MACROM_ADDR, MACROM_SIZE);
+ ptr = rom_ptr(MACROM_ADDR, bios_size);
+ assert(ptr != NULL);
stl_phys(cs->as, 0, ldl_p(ptr)); /* reset initial SP */
stl_phys(cs->as, 4,
MACROM_ADDR + ldl_p(ptr + 4)); /* reset initial PC */
--
2.33.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] q800: fix segfault with invalid MacROM
2022-01-07 10:50 [PATCH v2] q800: fix segfault with invalid MacROM Laurent Vivier
@ 2022-01-07 11:03 ` Thomas Huth
2022-01-07 23:08 ` Mark Cave-Ayland
1 sibling, 0 replies; 3+ messages in thread
From: Thomas Huth @ 2022-01-07 11:03 UTC (permalink / raw)
To: Laurent Vivier, qemu-devel
Cc: Peter Maydell, Mark Cave-Ayland, Philippe Mathieu-Daudé
On 07/01/2022 11.50, Laurent Vivier wrote:
> "qemu-system-m68k -M q800 -bios /dev/null" crashes with a segfault
> in q800_init().
> This happens because the code doesn't check that rom_ptr() returned
> a non-NULL pointer .
>
> To avoid NULL pointer, don't allow 0 sized file and use bios_size with
> rom_ptr().
>
> Resolves: https://gitlab.com/qemu-project/qemu/-/issues/756
> Reported-by: Peter Maydell <peter.maydell@linaro.org>
> Signed-off-by: Laurent Vivier <laurent@vivier.eu>
> ---
> hw/m68k/q800.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/hw/m68k/q800.c b/hw/m68k/q800.c
> index e4c7c9b88ad0..55dfe5036f40 100644
> --- a/hw/m68k/q800.c
> +++ b/hw/m68k/q800.c
> @@ -672,12 +672,13 @@ static void q800_init(MachineState *machine)
>
> /* Remove qtest_enabled() check once firmware files are in the tree */
> if (!qtest_enabled()) {
> - if (bios_size < 0 || bios_size > MACROM_SIZE) {
> + if (bios_size <= 0 || bios_size > MACROM_SIZE) {
> error_report("could not load MacROM '%s'", bios_name);
> exit(1);
> }
>
> - ptr = rom_ptr(MACROM_ADDR, MACROM_SIZE);
> + ptr = rom_ptr(MACROM_ADDR, bios_size);
> + assert(ptr != NULL);
> stl_phys(cs->as, 0, ldl_p(ptr)); /* reset initial SP */
> stl_phys(cs->as, 4,
> MACROM_ADDR + ldl_p(ptr + 4)); /* reset initial PC */
Looks nicer than v1, indeed.
Reviewed-by: Thomas Huth <thuth@redhat.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] q800: fix segfault with invalid MacROM
2022-01-07 10:50 [PATCH v2] q800: fix segfault with invalid MacROM Laurent Vivier
2022-01-07 11:03 ` Thomas Huth
@ 2022-01-07 23:08 ` Mark Cave-Ayland
1 sibling, 0 replies; 3+ messages in thread
From: Mark Cave-Ayland @ 2022-01-07 23:08 UTC (permalink / raw)
To: Laurent Vivier, qemu-devel
Cc: Peter Maydell, Thomas Huth, Philippe Mathieu-Daudé
On 07/01/2022 10:50, Laurent Vivier wrote:
> "qemu-system-m68k -M q800 -bios /dev/null" crashes with a segfault
> in q800_init().
> This happens because the code doesn't check that rom_ptr() returned
> a non-NULL pointer .
>
> To avoid NULL pointer, don't allow 0 sized file and use bios_size with
> rom_ptr().
>
> Resolves: https://gitlab.com/qemu-project/qemu/-/issues/756
> Reported-by: Peter Maydell <peter.maydell@linaro.org>
> Signed-off-by: Laurent Vivier <laurent@vivier.eu>
> ---
> hw/m68k/q800.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/hw/m68k/q800.c b/hw/m68k/q800.c
> index e4c7c9b88ad0..55dfe5036f40 100644
> --- a/hw/m68k/q800.c
> +++ b/hw/m68k/q800.c
> @@ -672,12 +672,13 @@ static void q800_init(MachineState *machine)
>
> /* Remove qtest_enabled() check once firmware files are in the tree */
> if (!qtest_enabled()) {
> - if (bios_size < 0 || bios_size > MACROM_SIZE) {
> + if (bios_size <= 0 || bios_size > MACROM_SIZE) {
> error_report("could not load MacROM '%s'", bios_name);
> exit(1);
> }
>
> - ptr = rom_ptr(MACROM_ADDR, MACROM_SIZE);
> + ptr = rom_ptr(MACROM_ADDR, bios_size);
> + assert(ptr != NULL);
> stl_phys(cs->as, 0, ldl_p(ptr)); /* reset initial SP */
> stl_phys(cs->as, 4,
> MACROM_ADDR + ldl_p(ptr + 4)); /* reset initial PC */
I think technically the second parameter of rom_ptr() is supposed to be the absolute
upper bound of the accessible region so the existing MACROM_SIZE feels better being a
constant rather than a variable such as bios_size. But then again bios_size should
never be greater than MACROM_SIZE because of the check beforehand so it shouldn't
matter in practice. Anyhow regardless of what you decide:
Reviewed-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
ATB,
Mark.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-01-07 23:09 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-01-07 10:50 [PATCH v2] q800: fix segfault with invalid MacROM Laurent Vivier
2022-01-07 11:03 ` Thomas Huth
2022-01-07 23:08 ` Mark Cave-Ayland
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).