Skip to contentSkip to conversation

pc-dimm: fix crash when invalid slot number is used

PATCH In review Igor Mammedov 6 participants 8 messages Jul 23, 2019 – Jul 30, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pc-dimm: fix crash when invalid slot number is used

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.

---
 hw/mem/pc-dimm.c | 7 +++++++
 1 file changed, 7 insertions(+)
hw/mem/pc-dimm.c +7 -0
index b1239fd0d3..29c785799c 100644
@@ -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) {
Signature · 1 line
2.18.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Igor Mammedov

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.

Quoted 22 lines
---
 hw/mem/pc-dimm.c | 7 +++++++
 1 file changed, 7 insertions(+)
hw/mem/pc-dimm.c +7 -0
index b1239fd0d3..29c785799c 100644
@@ -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) {
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
Reviewed-by on v1 1/1
#2 lore raw
In reply to Igor Mammedov
Quoted 11 lines · Igor Mammedov <[email protected]> 于2019年7月24日周三 上午12:09写道:

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.

Quoted 29 lines
---
 hw/mem/pc-dimm.c | 7 +++++++
 1 file changed, 7 insertions(+)
hw/mem/pc-dimm.c +7 -0
index b1239fd0d3..29c785799c 100644
@@ -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) {

--
2.18.1

Reviewed-by on v1 1/1
#3 lore raw
In reply to Igor Mammedov
Quoted 35 lines

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.

---
 hw/mem/pc-dimm.c | 7 +++++++
 1 file changed, 7 insertions(+)
hw/mem/pc-dimm.c +7 -0
index b1239fd0d3..29c785799c 100644
@@ -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) {
Quoted 1 line

--

Quoted 4 lines

2.18.1

#5 lore raw
Quoted 7 lines · Igor Mammedov

On Mon, 29 Jul 2019 17:16:14 -0400
"Michael S. Tsirkin" <[email protected]> wrote:

Hi Michael,

it seems tooling used for pull req is a bit broken
* minor issue is CC list contains bogus addresses like: &[email protected], [email protected],

Ouch. Looks like the html version ended up there in git somehow. I'll look into fixing that.

Quoted 2 lines

* a bigger issie is that Message-Id is taken from original patch even though [PULL 3/3] is not 100% the same as original which confuses mail clients quite a bit.

That's somehow the fault of the mail sending script. I checked and I don't see any logs of how it run though. I think I somehow triggered an old version by mistake. Sorry :(

Signature · 1 line
MST
#6 lore raw

[Qemu-devel] [PULL 0/3] virtio, pc: fixes

I'm sending this out now as these patches are ready, but it seems likely we'll need another patch for pci, and as it deals with migration compat it might be a blocker. Will know more tomorrow :(

The following changes since commit fff3159900d2b95613a9cb75fc3703e67a674729:

Merge remote-tracking branch 'remotes/pmaydell/tags/pull-target-arm-20190726' into staging (2019-07-26 16:23:07 +0100)

are available in the Git repository at:

git://git.kernel.org/pub/scm/virt/kvm/mst/qemu.git tags/for_upstream

for you to fetch changes up to 22235bb609c18547cf6b215bad1f9d2ec56ad371:

pc-dimm: fix crash when invalid slot number is used (2019-07-29 16:57:27 -0400)

----------------------------------------------------------------
virtio, pc: fixes

A couple of last minute bugfixes.

----------------------------------------------------------------
Dr. David Alan Gilbert (2):
Revert "Revert "globals: Allow global properties to be optional"" Revert "hw: report invalid disable-legacy|modern usage for virtio-1-only devs"

Igor Mammedov (1):
pc-dimm: fix crash when invalid slot number is used

 hw/virtio/virtio-pci.h        | 31 ++++++-------------------------
 include/hw/qdev-core.h        |  3 +++
 hw/core/machine.c             | 23 +++--------------------
 hw/display/virtio-gpu-pci.c   |  4 +---
 hw/display/virtio-vga.c       |  4 +---
 hw/mem/pc-dimm.c              |  7 +++++++
 hw/virtio/virtio-crypto-pci.c |  4 +---
 hw/virtio/virtio-input-pci.c  |  4 +---
 hw/virtio/virtio-pci.c        | 26 ++++++++++----------------
 qom/object.c                  |  3 +++
 10 files changed, 36 insertions(+), 73 deletions(-)
#7 lore raw

Re: [Qemu-devel] [PULL 0/3] virtio, pc: fixes

Quoted 26 lines · Michael S. Tsirkin

I'm sending this out now as these patches are ready, but it seems likely we'll need another patch for pci, and as it deals with migration compat it might be a blocker. Will know more tomorrow :(

The following changes since commit fff3159900d2b95613a9cb75fc3703e67a674729:

Merge remote-tracking branch 'remotes/pmaydell/tags/pull-target-arm-20190726' into staging (2019-07-26 16:23:07 +0100)

are available in the Git repository at:

git://git.kernel.org/pub/scm/virt/kvm/mst/qemu.git tags/for_upstream

for you to fetch changes up to 22235bb609c18547cf6b215bad1f9d2ec56ad371:

pc-dimm: fix crash when invalid slot number is used (2019-07-29 16:57:27 -0400)

----------------------------------------------------------------
virtio, pc: fixes

A couple of last minute bugfixes.

Quoted 8 lines

----------------------------------------------------------------
Dr. David Alan Gilbert (2):
Revert "Revert "globals: Allow global properties to be optional"" Revert "hw: report invalid disable-legacy|modern usage for virtio-1-only devs"

Igor Mammedov (1):
pc-dimm: fix crash when invalid slot number is used

Applied, thanks.

Please update the changelog at https://wiki.qemu.org/ChangeLog/4.1
for any user-visible changes.

-- PMM