From: David Hildenbrand Date: Tue, 23 Oct 2018 15:23:05 +0000 (+0200) Subject: memory-device: avoid overflows on very huge devices X-Git-Tag: v4.0.0-rc0~222^2~16 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=5e6aa26723f3eb67016282709fda7835a975f1ab;p=users%2Fdwmw2%2Fqemu.git memory-device: avoid overflows on very huge devices Should not be a problem right now, but it could theoretically happen in the future. Signed-off-by: David Hildenbrand Message-Id: <20181023152306.3123-7-david@redhat.com> Reviewed-by: David Gibson Reviewed-by: Igor Mammedov Signed-off-by: Eduardo Habkost --- diff --git a/hw/mem/memory-device.c b/hw/mem/memory-device.c index 996ad1490f..8be63c8032 100644 --- a/hw/mem/memory-device.c +++ b/hw/mem/memory-device.c @@ -85,7 +85,8 @@ static void memory_device_check_addable(MachineState *ms, uint64_t size, /* will we exceed the total amount of memory specified */ memory_device_used_region_size(OBJECT(ms), &used_region_size); - if (used_region_size + size > ms->maxram_size - ms->ram_size) { + if (used_region_size + size < used_region_size || + used_region_size + size > ms->maxram_size - ms->ram_size) { error_setg(errp, "not enough space, currently 0x%" PRIx64 " in use of total space for memory devices 0x" RAM_ADDR_FMT, used_region_size, ms->maxram_size - ms->ram_size);