qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Igor Mammedov <imammedo@redhat.com>
To: qemu-devel@nongnu.org
Cc: david@gibson.dropbear.id.au, mst@redhat.com
Subject: [Qemu-devel] [PATCH] pc-dimm: fix crash when invalid slot number is used
Date: Tue, 23 Jul 2019 12:08:59 -0400	[thread overview]
Message-ID: <20190723160859.27250-1-imammedo@redhat.com> (raw)

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 <imammedo@redhat.com>
---
 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 b1239fd0d3..29c785799c 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) {
-- 
2.18.1



WARNING: multiple messages have this Message-ID (diff)
From: "Michael S. Tsirkin" <mst@redhat.com>
To: qemu-devel@nongnu.org
Cc: Peter Maydell <peter.maydell@linaro.org>,
	Pankaj Gupta <pagupta@redhat.com>, Li Qiang <liq3ea@gmail.com>,
	&lt@redhat.com, Mammedov@redhat.com,
	Igor Mammedov <imammedo@redhat.com>,
	David Gibson <david@gibson.dropbear.id.au>
Subject: [Qemu-devel] [PULL 3/3] pc-dimm: fix crash when invalid slot number is used
Date: Mon, 29 Jul 2019 17:16:14 -0400	[thread overview]
Message-ID: <20190723160859.27250-1-imammedo@redhat.com> (raw)
Message-ID: <20190729211614.e_nKAiNoJDhFUCrBz2F3QmB-D-U_dpE2MFddBp6-Tng@z> (raw)
In-Reply-To: <20190729211404.1533-1-mst@redhat.com>

From: Igor Mammedov <imammedo@redhat.com>

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 <imammedo@redhat.com>
Message-Id: <20190723160859.27250-1-imammedo@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Reviewed-by: Li Qiang <liq3ea@gmail.com>
Signed-off-by: Igor Mammedov &lt;<a href="mailto:imammedo@redhat.com" target="_blank">imammedo@redhat.com</a>&gt;<br></blockquote><div><br></div><div>Reviewed-by: Li Qiang &lt;<a href="mailto:liq3ea@gmail.com">liq3ea@gmail.com</a>&gt;<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
Reviewed-by: Pankaj Gupta <pagupta@redhat.com>
---
 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 b1239fd0d3..29c785799c 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) {
-- 
MST



         reply	other threads:[~2019-07-23 16:09 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-29 21:15 [Qemu-devel] [PULL 0/3] virtio, pc: fixes Michael S. Tsirkin
2019-07-23 16:08 ` Igor Mammedov [this message]
2019-07-24  3:18   ` [Qemu-devel] [PATCH] pc-dimm: fix crash when invalid slot number is used David Gibson
2019-07-24  6:13   ` Li Qiang
2019-07-24  6:39   ` Pankaj Gupta
2019-07-29 21:16   ` [Qemu-devel] [PULL 3/3] " Michael S. Tsirkin
2019-07-30 12:36   ` Igor Mammedov
2019-07-30 15:50     ` Michael S. Tsirkin
2019-07-30  9:44 ` [Qemu-devel] [PULL 0/3] virtio, pc: fixes Peter Maydell
  -- strict thread matches above, loose matches on Subject: below --
2019-07-29 16:29 [Qemu-devel] [For 4.1 PATCH v2 0/2] Reversions to fix PCIe in virtio Dr. David Alan Gilbert (git)
2019-07-29 16:29 ` [Qemu-devel] [PATCH v2 1/2] Revert "Revert "globals: Allow global properties to be optional"" Dr. David Alan Gilbert (git)
2019-07-29 16:30   ` Daniel P. Berrangé
2019-07-29 16:46   ` Cornelia Huck
2019-07-29 21:16   ` [Qemu-devel] [PULL 1/3] " Michael S. Tsirkin
2019-07-29 16:29 ` [Qemu-devel] [PATCH v2 2/2] Revert "hw: report invalid disable-legacy|modern usage for virtio-1-only devs" Dr. David Alan Gilbert (git)
2019-07-29 16:31   ` Daniel P. Berrangé
2019-07-29 16:46   ` Cornelia Huck
2019-07-29 21:16   ` [Qemu-devel] [PULL 2/3] " Michael S. Tsirkin
2019-07-29 16:32 ` [Qemu-devel] [For 4.1 PATCH v2 0/2] Reversions to fix PCIe in virtio Cornelia Huck
2019-07-29 16:35   ` Dr. David Alan Gilbert
2019-07-29 16:43     ` Peter Maydell
2019-07-29 16:45       ` Daniel P. Berrangé

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190723160859.27250-1-imammedo@redhat.com \
    --to=imammedo@redhat.com \
    --cc=david@gibson.dropbear.id.au \
    --cc=mst@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).