diff mbox series

[v2,4/7] hw/elf_ops: Do not ignore write failures when loading ELF

Message ID 20200518155308.15851-5-f4bug@amsat.org (mailing list archive)
State New, archived
Headers show
Series exec/memory: Enforce checking MemTxResult values | expand

Commit Message

Philippe Mathieu-Daudé May 18, 2020, 3:53 p.m. UTC
Do not ignore the MemTxResult error type returned by
address_space_write().

Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
 include/hw/elf_ops.h | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

Comments

Stefano Garzarella May 19, 2020, 7:58 a.m. UTC | #1
On Mon, May 18, 2020 at 05:53:05PM +0200, Philippe Mathieu-Daudé wrote:
> Do not ignore the MemTxResult error type returned by
> address_space_write().
> 
> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> ---
>  include/hw/elf_ops.h | 11 ++++++++---
>  1 file changed, 8 insertions(+), 3 deletions(-)

Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>

> 
> diff --git a/include/hw/elf_ops.h b/include/hw/elf_ops.h
> index 398a4a2c85..6fdff3dced 100644
> --- a/include/hw/elf_ops.h
> +++ b/include/hw/elf_ops.h
> @@ -553,9 +553,14 @@ static int glue(load_elf, SZ)(const char *name, int fd,
>                      rom_add_elf_program(label, mapped_file, data, file_size,
>                                          mem_size, addr, as);
>                  } else {
> -                    address_space_write(as ? as : &address_space_memory,
> -                                        addr, MEMTXATTRS_UNSPECIFIED,
> -                                        data, file_size);
> +                    MemTxResult res;
> +
> +                    res = address_space_write(as ? as : &address_space_memory,
> +                                              addr, MEMTXATTRS_UNSPECIFIED,
> +                                              data, file_size);
> +                    if (res != MEMTX_OK) {
> +                        goto fail;
> +                    }
>                  }
>              }
>  
> -- 
> 2.21.3
>
diff mbox series

Patch

diff --git a/include/hw/elf_ops.h b/include/hw/elf_ops.h
index 398a4a2c85..6fdff3dced 100644
--- a/include/hw/elf_ops.h
+++ b/include/hw/elf_ops.h
@@ -553,9 +553,14 @@  static int glue(load_elf, SZ)(const char *name, int fd,
                     rom_add_elf_program(label, mapped_file, data, file_size,
                                         mem_size, addr, as);
                 } else {
-                    address_space_write(as ? as : &address_space_memory,
-                                        addr, MEMTXATTRS_UNSPECIFIED,
-                                        data, file_size);
+                    MemTxResult res;
+
+                    res = address_space_write(as ? as : &address_space_memory,
+                                              addr, MEMTXATTRS_UNSPECIFIED,
+                                              data, file_size);
+                    if (res != MEMTX_OK) {
+                        goto fail;
+                    }
                 }
             }