Skip to contentSkip to conversation

roms: assert if max rom size is less than the used size

PATCH Applied Igor Mammedov 3 participants 3 messages Apr 11, 2019 – Apr 12, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 roms: assert if max rom size is less than the used size

It would ensure that we would notice attempt to write beyond the allocated buffer. In case of MemoryRegion backed ROM it's the host buffer and the guest RAM otherwise.

assert can be triggered with:
dd if=/dev/zero of=/tmp/blob bs=63k count=1
qemu-system-x86_64 for i in {1..33}; do echo -n " -acpitable /tmp/blob"; done

Fixes (a1666142db acpi-build: make ROMs RAM blocks resizeable)
---
 hw/core/loader.c | 1 +
 1 file changed, 1 insertion(+)
hw/core/loader.c +1 -0
index fe5cb24..a097bbe 100644
@@ -1025,6 +1025,7 @@ MemoryRegion *rom_add_blob(const char *name, const void *blob, size_t len,
     rom->addr     = addr;
     rom->romsize  = max_len ? max_len : len;
     rom->datasize = len;
+    g_assert(rom->romsize >= rom->datasize);
     rom->data     = g_malloc0(rom->datasize);
     memcpy(rom->data, blob, len);
     rom_insert(rom);
Signature · 1 line
2.7.4
Reviewed-by Tested-by on v1 1/1
#1 lore raw
Quoted 8 lines · Igor Mammedov

It would ensure that we would notice attempt to write beyond the allocated buffer. In case of MemoryRegion backed ROM it's the host buffer and the guest RAM otherwise.

assert can be triggered with:
dd if=/dev/zero of=/tmp/blob bs=63k count=1
qemu-system-x86_64 for i in {1..33}; do echo -n " -acpitable /tmp/blob"; done

Quoted 8 lines
Fixes (a1666142db acpi-build: make ROMs RAM blocks resizeable)
---
 hw/core/loader.c | 1 +
 1 file changed, 1 insertion(+)

Thanks,
Stefano

#2 lore raw
Quoted 18 lines · Stefano Garzarella
Quoted 8 lines · Igor Mammedov

It would ensure that we would notice attempt to write beyond the allocated buffer. In case of MemoryRegion backed ROM it's the host buffer and the guest RAM otherwise.

assert can be triggered with:
dd if=/dev/zero of=/tmp/blob bs=63k count=1
qemu-system-x86_64 for i in {1..33}; do echo -n " -acpitable /tmp/blob"; done

Quoted 8 lines
Fixes (a1666142db acpi-build: make ROMs RAM blocks resizeable)
---
 hw/core/loader.c | 1 +
 1 file changed, 1 insertion(+)
Quoted 6 lines

Thanks,
Stefano

Queued, thanks.

Paolo