]> xenbits.xensource.com Git - qemu-xen.git/commitdiff
elf-ops.h: fix int overflow in load_elf()
authorStefano Garzarella <sgarzare@redhat.com>
Tue, 10 Sep 2019 14:22:23 +0000 (16:22 +0200)
committerPaolo Bonzini <pbonzini@redhat.com>
Mon, 16 Sep 2019 10:32:21 +0000 (12:32 +0200)
This patch fixes a possible integer overflow when we calculate
the total size of ELF segments loaded.

Reported-by: Coverity (CID 1405299)
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
Message-Id: <20190910124828.39794-1-sgarzare@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
hw/core/loader.c
include/hw/elf_ops.h
include/hw/loader.h

index 32f7cc7c33c89edd9b77b14dcf9589278b82c834..75eb56ddbb8c423a9454b97c85ea0fe8910c9c94 100644 (file)
@@ -338,6 +338,8 @@ const char *load_elf_strerror(int error)
         return "The image is from incompatible architecture";
     case ELF_LOAD_WRONG_ENDIAN:
         return "The image has incorrect endianness";
+    case ELF_LOAD_TOO_BIG:
+        return "The image segments are too big to load";
     default:
         return "Unknown error";
     }
index 1496d7e7536773663e21779aa9cc63d7d61c1c09..e07d276df78b18b8d7ee56ea1a7bda79ec9ae3ee 100644 (file)
@@ -485,6 +485,11 @@ static int glue(load_elf, SZ)(const char *name, int fd,
                 }
             }
 
+            if (mem_size > INT_MAX - total_size) {
+                ret = ELF_LOAD_TOO_BIG;
+                goto fail;
+            }
+
             /* address_offset is hack for kernel images that are
                linked at the wrong physical address.  */
             if (translate_fn) {
index 07fd9286e7543336e5fcf380c41854ae14f2afb9..48a96cd55904bdb2349ba56a9856094e7edfecad 100644 (file)
@@ -89,6 +89,7 @@ int load_image_gzipped(const char *filename, hwaddr addr, uint64_t max_sz);
 #define ELF_LOAD_NOT_ELF      -2
 #define ELF_LOAD_WRONG_ARCH   -3
 #define ELF_LOAD_WRONG_ENDIAN -4
+#define ELF_LOAD_TOO_BIG      -5
 const char *load_elf_strerror(int error);
 
 /** load_elf_ram_sym: