From 22235bb609c18547cf6b215bad1f9d2ec56ad371 Mon Sep 17 00:00:00 2001 From: Igor Mammedov Date: Tue, 23 Jul 2019 12:08:59 -0400 Subject: pc-dimm: fix crash when invalid slot number is used MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit QEMU will crash with: Segmentation fault (core dumped) when negative slot number is used, ex: qemu-system-x86_64 -m 1G,maxmem=20G,slots=256 \ -object memory-backend-ram,id=mem1,size=1G \ -device pc-dimm,id=dimm1,memdev=mem1,slot=-2 fix it by checking that slot number is within valid range. Signed-off-by: Igor Mammedov Message-Id: <20190723160859.27250-1-imammedo@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin Reviewed-by: David Gibson Reviewed-by: Li Qiang Signed-off-by: Igor Mammedov <imammedo@redhat.com>

Reviewed-by: Li Qiang <liq3ea@gmail.com>
 
Reviewed-by: Pankaj Gupta --- hw/mem/pc-dimm.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c index b1239fd..29c7857 100644 --- a/hw/mem/pc-dimm.c +++ b/hw/mem/pc-dimm.c @@ -38,6 +38,13 @@ void pc_dimm_pre_plug(PCDIMMDevice *dimm, MachineState *machine, slot = object_property_get_int(OBJECT(dimm), PC_DIMM_SLOT_PROP, &error_abort); + if ((slot < 0 || slot >= machine->ram_slots) && + slot != PC_DIMM_UNASSIGNED_SLOT) { + error_setg(&local_err, "invalid slot number, valid range is [0-%" + PRIu64 "]", machine->ram_slots - 1); + goto out; + } + slot = pc_dimm_get_free_slot(slot == PC_DIMM_UNASSIGNED_SLOT ? NULL : &slot, machine->ram_slots, &local_err); if (local_err) { -- cgit v1.1