Skip to contentSkip to conversation

ivshmem: fix crash with ivshmem-plain

PATCH In review [email protected] 2 participants 2 messages Apr 12, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ivshmem: fix crash with ivshmem-plain

From: Marc-André Lureau <[email protected]>

"qemu -device ivshmem-plain" will crash, because it doesn't check that 'memdev' was provided.

---
 hw/misc/ivshmem.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)
hw/misc/ivshmem.c +18 -1
index 08bf5c6..fae4d08 100644
@@ -868,7 +868,7 @@ static void ivshmem_common_realize(PCIDevice *dev, Error **errp)
 
         s->ivshmem_bar2 = host_memory_backend_get_memory(s->hostmem,
                                                          &error_abort);
-    } else {
+    } else if (s->server_chr) {
         IVSHMEM_DPRINTF("using shared memory server (socket = %s)\n",
                         s->server_chr->filename);
 
@@ -899,6 +899,8 @@ static void ivshmem_common_realize(PCIDevice *dev, Error **errp)
             error_setg(errp, "failed to initialize interrupts");
             return;
         }
+    } else {
+        g_assert_not_reached();
     }
 
     vmstate_register_ram(s->ivshmem_bar2, DEVICE(s));
@@ -1048,10 +1050,25 @@ static void ivshmem_plain_init(Object *obj)
                              &error_abort);
 }
 
+static void ivshmem_plain_realize(PCIDevice *dev, Error **errp)
+{
+    IVShmemState *s = IVSHMEM_COMMON(dev);
+
+    if (!s->hostmem) {
+        error_setg(errp, "You must specify a 'memdev'");
+        return;
+    }
+
+    ivshmem_common_realize(dev, errp);
+}
+
+
 static void ivshmem_plain_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
+    PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
 
+    k->realize = ivshmem_plain_realize;
     dc->props = ivshmem_plain_properties;
     dc->vmsd = &ivshmem_plain_vmsd;
 }
Signature · 1 line
2.5.5
#1 lore raw
Quoted 6 lines · [email protected] writes:

From: Marc-André Lureau <[email protected]>

"qemu -device ivshmem-plain" will crash, because it doesn't check that 'memdev' was provided.

Oww!

Quoted 9 lines
---
 hw/misc/ivshmem.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)
hw/misc/ivshmem.c +0 -0
index 08bf5c6..fae4d08 100644

hw/misc/ivshmem.c static void ivshmem_common_realize(PCIDevice *dev, Error **errp) · line 871

Quoted 5 lines
hw/misc/ivshmem.c +1 -1
@@ -868,7 +868,7 @@ static void ivshmem_common_realize(PCIDevice *dev, Error **errp)
 
         s->ivshmem_bar2 = host_memory_backend_get_memory(s->hostmem,
                                                          &error_abort);
-    } else {
+    } else if (s->server_chr) {

I'd simply stick

           assert(s->server_chr)

here.

Quoted 28 lines
hw/misc/ivshmem.c +14 -0
         IVSHMEM_DPRINTF("using shared memory server (socket = %s)\n",
                         s->server_chr->filename);
 
@@ -899,6 +899,8 @@ static void ivshmem_common_realize(PCIDevice *dev, Error **errp)
             error_setg(errp, "failed to initialize interrupts");
             return;
         }
+    } else {
+        g_assert_not_reached();
     }
 
     vmstate_register_ram(s->ivshmem_bar2, DEVICE(s));
@@ -1048,10 +1050,25 @@ static void ivshmem_plain_init(Object *obj)
                              &error_abort);
 }
 
+static void ivshmem_plain_realize(PCIDevice *dev, Error **errp)
+{
+    IVShmemState *s = IVSHMEM_COMMON(dev);
+
+    if (!s->hostmem) {
+        error_setg(errp, "You must specify a 'memdev'");
+        return;
+    }
+
+    ivshmem_common_realize(dev, errp);
+}
+

hw/misc/ivshmem.c static void ivshmem_plain_init(Object *obj) · line 1074

Quoted 10 lines
hw/misc/ivshmem.c +3 -0
+
 static void ivshmem_plain_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
+    PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
 
+    k->realize = ivshmem_plain_realize;
     dc->props = ivshmem_plain_properties;
     dc->vmsd = &ivshmem_plain_vmsd;
 }

Same bug in ivshmem-doorbell. Care to fix that, too?