QEMU-Devel Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH for-5.0] hw/ppc/e500.c: Handle qemu_find_file() failure
@ 2020-03-24 12:12 Peter Maydell
  2020-03-24 12:58 ` Philippe Mathieu-Daudé
  2020-03-26  0:12 ` David Gibson
  0 siblings, 2 replies; 3+ messages in thread
From: Peter Maydell @ 2020-03-24 12:12 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-ppc, David Gibson

If qemu_find_file() doesn't find the BIOS it returns NULL; we were
passing that unchecked through to load_elf(), which assumes a non-NULL
pointer and may misbehave. In practice it fails with a weird message:

  $ qemu-system-ppc -M ppce500 -display none -kernel nonesuch
  Bad address
  qemu-system-ppc: could not load firmware '(null)'

Handle the failure case better:

  $ qemu-system-ppc -M ppce500 -display none -kernel nonesuch
  qemu-system-ppc: could not find firmware/kernel file 'nonesuch'

Spotted by Coverity (CID 1238954).

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
 hw/ppc/e500.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/hw/ppc/e500.c b/hw/ppc/e500.c
index 854cd3ac465..0d1f41197cf 100644
--- a/hw/ppc/e500.c
+++ b/hw/ppc/e500.c
@@ -1047,6 +1047,10 @@ void ppce500_init(MachineState *machine)
     }
 
     filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, payload_name);
+    if (!filename) {
+        error_report("could not find firmware/kernel file '%s'", payload_name);
+        exit(1);
+    }
 
     payload_size = load_elf(filename, NULL, NULL, NULL,
                             &bios_entry, &loadaddr, NULL, NULL,
-- 
2.20.1



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH for-5.0] hw/ppc/e500.c: Handle qemu_find_file() failure
  2020-03-24 12:12 [PATCH for-5.0] hw/ppc/e500.c: Handle qemu_find_file() failure Peter Maydell
@ 2020-03-24 12:58 ` Philippe Mathieu-Daudé
  2020-03-26  0:12 ` David Gibson
  1 sibling, 0 replies; 3+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-03-24 12:58 UTC (permalink / raw)
  To: Peter Maydell, qemu-devel; +Cc: qemu-ppc, David Gibson

On 3/24/20 1:12 PM, Peter Maydell wrote:
> If qemu_find_file() doesn't find the BIOS it returns NULL; we were
> passing that unchecked through to load_elf(), which assumes a non-NULL
> pointer and may misbehave. In practice it fails with a weird message:
> 
>    $ qemu-system-ppc -M ppce500 -display none -kernel nonesuch
>    Bad address
>    qemu-system-ppc: could not load firmware '(null)'
> 
> Handle the failure case better:
> 
>    $ qemu-system-ppc -M ppce500 -display none -kernel nonesuch
>    qemu-system-ppc: could not find firmware/kernel file 'nonesuch'
> 
> Spotted by Coverity (CID 1238954).
> 
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
>   hw/ppc/e500.c | 4 ++++
>   1 file changed, 4 insertions(+)
> 
> diff --git a/hw/ppc/e500.c b/hw/ppc/e500.c
> index 854cd3ac465..0d1f41197cf 100644
> --- a/hw/ppc/e500.c
> +++ b/hw/ppc/e500.c
> @@ -1047,6 +1047,10 @@ void ppce500_init(MachineState *machine)
>       }
>   
>       filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, payload_name);
> +    if (!filename) {
> +        error_report("could not find firmware/kernel file '%s'", payload_name);
> +        exit(1);
> +    }
>   
>       payload_size = load_elf(filename, NULL, NULL, NULL,
>                               &bios_entry, &loadaddr, NULL, NULL,
> 

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH for-5.0] hw/ppc/e500.c: Handle qemu_find_file() failure
  2020-03-24 12:12 [PATCH for-5.0] hw/ppc/e500.c: Handle qemu_find_file() failure Peter Maydell
  2020-03-24 12:58 ` Philippe Mathieu-Daudé
@ 2020-03-26  0:12 ` David Gibson
  1 sibling, 0 replies; 3+ messages in thread
From: David Gibson @ 2020-03-26  0:12 UTC (permalink / raw)
  To: Peter Maydell; +Cc: qemu-ppc, qemu-devel


[-- Attachment #1: Type: text/plain, Size: 1569 bytes --]

On Tue, Mar 24, 2020 at 12:12:16PM +0000, Peter Maydell wrote:
> If qemu_find_file() doesn't find the BIOS it returns NULL; we were
> passing that unchecked through to load_elf(), which assumes a non-NULL
> pointer and may misbehave. In practice it fails with a weird message:
> 
>   $ qemu-system-ppc -M ppce500 -display none -kernel nonesuch
>   Bad address
>   qemu-system-ppc: could not load firmware '(null)'
> 
> Handle the failure case better:
> 
>   $ qemu-system-ppc -M ppce500 -display none -kernel nonesuch
>   qemu-system-ppc: could not find firmware/kernel file 'nonesuch'
> 
> Spotted by Coverity (CID 1238954).
> 
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>

Applied to ppc-for-5.0, thanks.

> ---
>  hw/ppc/e500.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/hw/ppc/e500.c b/hw/ppc/e500.c
> index 854cd3ac465..0d1f41197cf 100644
> --- a/hw/ppc/e500.c
> +++ b/hw/ppc/e500.c
> @@ -1047,6 +1047,10 @@ void ppce500_init(MachineState *machine)
>      }
>  
>      filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, payload_name);
> +    if (!filename) {
> +        error_report("could not find firmware/kernel file '%s'", payload_name);
> +        exit(1);
> +    }
>  
>      payload_size = load_elf(filename, NULL, NULL, NULL,
>                              &bios_entry, &loadaddr, NULL, NULL,

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-24 12:12 [PATCH for-5.0] hw/ppc/e500.c: Handle qemu_find_file() failure Peter Maydell
2020-03-24 12:58 ` Philippe Mathieu-Daudé
2020-03-26  0:12 ` David Gibson

QEMU-Devel Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/qemu-devel/0 qemu-devel/git/0.git
	git clone --mirror https://lore.kernel.org/qemu-devel/1 qemu-devel/git/1.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 qemu-devel qemu-devel/ https://lore.kernel.org/qemu-devel \
		qemu-devel@nongnu.org
	public-inbox-index qemu-devel

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.nongnu.qemu-devel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git