Skip to contentSkip to conversation

hw/i386/vmmouse: Fix crash when using the vmmouse on a machine without vmport

PATCH Applied Thomas Huth 3 participants 3 messages Jan 29, 2020 – Feb 6, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hw/i386/vmmouse: Fix crash when using the vmmouse on a machine without vmport

QEMU currently crashes when the user tries to use the "vmmouse" on a machine without vmport, e.g.:

 $ x86_64-softmmu/qemu-system-x86_64 -machine microvm -device vmmouse
 Segmentation fault (core dumped)

or:

 $ x86_64-softmmu/qemu-system-x86_64 -device vmmouse -M pc,vmport=off
 Segmentation fault (core dumped)

Let's avoid the crash by checking for the vmport device first.

---
 hw/i386/vmmouse.c | 6 ++++++
 1 file changed, 6 insertions(+)
hw/i386/vmmouse.c +6 -0
index 7c2a375527..e8e62bd96b 100644
@@ -23,6 +23,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qapi/error.h"
 #include "ui/console.h"
 #include "hw/i386/pc.h"
 #include "hw/input/i8042.h"
@@ -269,6 +270,11 @@ static void vmmouse_realizefn(DeviceState *dev, Error **errp)
 
     DPRINTF("vmmouse_init\n");
 
+    if (!object_resolve_path_type("", TYPE_VMPORT, NULL)) {
+        error_setg(errp, "vmmouse needs a machine with vmport");
+        return;
+    }
+
     vmport_register(VMMOUSE_STATUS, vmmouse_ioport_read, s);
     vmport_register(VMMOUSE_COMMAND, vmmouse_ioport_read, s);
     vmport_register(VMMOUSE_DATA, vmmouse_ioport_read, s);
Signature · 1 line
2.18.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Thomas Huth

QEMU currently crashes when the user tries to use the "vmmouse" on a machine without vmport, e.g.:

$ x86_64-softmmu/qemu-system-x86_64 -machine microvm -device vmmouse
Segmentation fault (core dumped)
Quoted 8 lines

or:

$ x86_64-softmmu/qemu-system-x86_64 -device vmmouse -M pc,vmport=off
Segmentation fault (core dumped)

Let's avoid the crash by checking for the vmport device first.

Makes sense.

Thanks,

Darren

Quoted 32 lines

---
hw/i386/vmmouse.c | 6 ++++++

1 file changed, 6 insertions(+)
hw/i386/vmmouse.c +6 -0
index 7c2a375527..e8e62bd96b 100644
@@ -23,6 +23,7 @@
 */
 
 #include "qemu/osdep.h"
+#include "qapi/error.h"
 #include "ui/console.h"
 #include "hw/i386/pc.h"
 #include "hw/input/i8042.h"
@@ -269,6 +270,11 @@ static void vmmouse_realizefn(DeviceState *dev, Error **errp)
 
    DPRINTF("vmmouse_init\n");
 
+    if (!object_resolve_path_type("", TYPE_VMPORT, NULL)) {
+        error_setg(errp, "vmmouse needs a machine with vmport");
+        return;
+    }
+
    vmport_register(VMMOUSE_STATUS, vmmouse_ioport_read, s);
    vmport_register(VMMOUSE_COMMAND, vmmouse_ioport_read, s);
    vmport_register(VMMOUSE_DATA, vmmouse_ioport_read, s);
Signature · 1 line
2.18.1
#2 lore raw
In reply to Thomas Huth

Le 29/01/2020 à 12:29, Thomas Huth a écrit :

Quoted 33 lines

QEMU currently crashes when the user tries to use the "vmmouse" on a machine without vmport, e.g.:

 $ x86_64-softmmu/qemu-system-x86_64 -machine microvm -device vmmouse
 Segmentation fault (core dumped)

or:

 $ x86_64-softmmu/qemu-system-x86_64 -device vmmouse -M pc,vmport=off
 Segmentation fault (core dumped)

Let's avoid the crash by checking for the vmport device first.

---
 hw/i386/vmmouse.c | 6 ++++++
 1 file changed, 6 insertions(+)
hw/i386/vmmouse.c +1 -0
index 7c2a375527..e8e62bd96b 100644
@@ -23,6 +23,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qapi/error.h"
 #include "ui/console.h"
 #include "hw/i386/pc.h"
 #include "hw/input/i8042.h"
@@ -269,6 +270,11 @@ static void vmmouse_realizefn(DeviceState *dev, Error **errp)
 

hw/i386/vmmouse.c static void vmmouse_realizefn(DeviceState *dev, Error **errp) · line 280

Quoted 10 lines
hw/i386/vmmouse.c +5 -0
     DPRINTF("vmmouse_init\n");
 
+    if (!object_resolve_path_type("", TYPE_VMPORT, NULL)) {
+        error_setg(errp, "vmmouse needs a machine with vmport");
+        return;
+    }
+
     vmport_register(VMMOUSE_STATUS, vmmouse_ioport_read, s);
     vmport_register(VMMOUSE_COMMAND, vmmouse_ioport_read, s);
     vmport_register(VMMOUSE_DATA, vmmouse_ioport_read, s);

Applied to my trivial-patches branch.

Thanks,
Laurent