Skip to content

Commit

Permalink
load_elf: fix iterator's type for elf file processing
Browse files Browse the repository at this point in the history
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: 7ef295e ("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>
  • Loading branch information
Anastasia Belova authored and pm215 committed Jan 15, 2024
1 parent 8869bdb commit 7ec3973
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion include/hw/elf_ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 7ec3973

Please sign in to comment.