From b4c4c1f1129a5d9dcbcbff46b58998f6fb1410bb Mon Sep 17 00:00:00 2001 From: Laurent Vivier Date: Sat, 15 Jan 2022 21:37:24 +0100 Subject: hw/elf_ops: clear uninitialized segment space MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When the mem_size of the segment is bigger than the file_size, and if this space doesn't overlap another segment, it needs to be cleared. This bug is very similar to the one we had for linux-user, 22d113b52f41 ("linux-user: Fix loading of BSS segments"), where .bss section is encoded as an extension of the the data one by setting the segment p_memsz > p_filesz. Signed-off-by: Laurent Vivier [PMD: Use recently added address_space_set()] Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Stefano Garzarella Reviewed-by: Richard Henderson Message-Id: <20220115203725.3834712-3-laurent@vivier.eu> --- hw/core/loader.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'hw') diff --git a/hw/core/loader.c b/hw/core/loader.c index 052a0fd719..19edb928e9 100644 --- a/hw/core/loader.c +++ b/hw/core/loader.c @@ -1164,9 +1164,13 @@ static void rom_reset(void *unused) if (rom->mr) { void *host = memory_region_get_ram_ptr(rom->mr); memcpy(host, rom->data, rom->datasize); + memset(host + rom->datasize, 0, rom->romsize - rom->datasize); } else { address_space_write_rom(rom->as, rom->addr, MEMTXATTRS_UNSPECIFIED, rom->data, rom->datasize); + address_space_set(rom->as, rom->addr + rom->datasize, 0, + rom->romsize - rom->datasize, + MEMTXATTRS_UNSPECIFIED); } if (rom->isrom) { /* rom needs to be written only once */ -- cgit v1.2.3