mirror of https://github.com/xemu-project/xemu.git
hw/core/machine: diagnose wrapping of maxmem
The 'maxmem' parameter parsed on the command line is held in uint64_t and then assigned to the MachineState field that is 'ram_addr_t'. This assignment will wrap on 32-bit hosts, silently changing the user's config request if it were over-sized. Improve the existing diagnositics for validating 'size', and add the same diagnostics for 'maxmem' Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> Tested-by: Ani Sinha <anisinha@redhat.com> Reviewed-by: Ani Sinha <anisinha@redhat.com> Message-ID: <20241127114057.255995-1-berrange@redhat.com> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
This commit is contained in:
parent
2dfe93699c
commit
235560b3a7
|
@ -598,11 +598,19 @@ static void machine_set_mem(Object *obj, Visitor *v, const char *name,
|
|||
mem->size = mc->fixup_ram_size(mem->size);
|
||||
}
|
||||
if ((ram_addr_t)mem->size != mem->size) {
|
||||
error_setg(errp, "ram size too large");
|
||||
error_setg(errp, "ram size %llu exceeds permitted maximum %llu",
|
||||
(unsigned long long)mem->size,
|
||||
(unsigned long long)RAM_ADDR_MAX);
|
||||
goto out_free;
|
||||
}
|
||||
|
||||
if (mem->has_max_size) {
|
||||
if ((ram_addr_t)mem->max_size != mem->max_size) {
|
||||
error_setg(errp, "ram size %llu exceeds permitted maximum %llu",
|
||||
(unsigned long long)mem->max_size,
|
||||
(unsigned long long)RAM_ADDR_MAX);
|
||||
goto out_free;
|
||||
}
|
||||
if (mem->max_size < mem->size) {
|
||||
error_setg(errp, "invalid value of maxmem: "
|
||||
"maximum memory size (0x%" PRIx64 ") must be at least "
|
||||
|
|
Loading…
Reference in New Issue