]> git.proxmox.com Git - mirror_qemu.git/commitdiff
load_elf: fix iterator's type for elf file processing
authorAnastasia Belova <abelova@astralinux.ru>
Mon, 15 Jan 2024 09:22:16 +0000 (12:22 +0300)
committerPeter Maydell <peter.maydell@linaro.org>
Thu, 18 Jan 2024 12:20:33 +0000 (12:20 +0000)
j is used while loading an ELF file to byteswap segments'
data. If data is larger than 2GB an overflow may happen.
So j should be elf_word.

This commit fixes a minor bug: it's unlikely anybody is trying to
load ELF files with 2GB+ segments for wrong-endianness targets,
but if they did, it wouldn't work correctly.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Cc: qemu-stable@nongnu.org
Fixes: 7ef295ea5b ("loader: Add data swap option to load-elf")
Signed-off-by: Anastasia Belova <abelova@astralinux.ru>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
include/hw/elf_ops.h

index 0a5c258fe6898c58b5b7aa03dee4286e70c20541..9c35d1b9da6c36198b6f49e99db6eb49cdfae058 100644 (file)
@@ -500,7 +500,7 @@ static ssize_t glue(load_elf, SZ)(const char *name, int fd,
             }
 
             if (data_swab) {
-                int j;
+                elf_word j;
                 for (j = 0; j < file_size; j += (1 << data_swab)) {
                     uint8_t *dp = data + j;
                     switch (data_swab) {