Skip to contentSkip to conversation

qdev: fix crash when device_add is called with abstract driver

PATCH In review Igor Mammedov 4 participants 4 messages Sep 17, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 qdev: fix crash when device_add is called with abstract driver

user is able to crash running QEMU when following monitor command is called:

device_add intel-hda-generic

crash is caused by assertion in object_initialize_with_type() when type is abstract.

Checking if type is abstract before instance is created in qdev_device_add() allows to prevent crash on incorrect user input.

---
 qdev-monitor.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
qdev-monitor.c +6 -0
index 410cdcb..bb2e1b6 100644
@@ -472,6 +472,12 @@ DeviceState *qdev_device_add(QemuOpts *opts)
         return NULL;
     }
 
+    if (object_class_is_abstract(obj)) {
+        qerror_report(QERR_INVALID_PARAMETER_VALUE, "driver",
+                      "non-abstract device type");
+        return NULL;
+    }
+
     k = DEVICE_CLASS(obj);
 
     /* find bus */
Signature · 1 line
1.7.1
#1 lore raw

Il 17/09/2013 15:32, Igor Mammedov ha scritto:

Quoted 24 lines

user is able to crash running QEMU when following monitor command is called:

device_add intel-hda-generic

crash is caused by assertion in object_initialize_with_type() when type is abstract.

Checking if type is abstract before instance is created in qdev_device_add() allows to prevent crash on incorrect user input.

---
 qdev-monitor.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
qdev-monitor.c +0 -0
index 410cdcb..bb2e1b6 100644
@@ -472,6 +472,12 @@ DeviceState *qdev_device_add(QemuOpts *opts)
         return NULL;
     }

qdev-monitor.c DeviceState *qdev_device_add(QemuOpts *opts) · line 483

Quoted 10 lines
qdev-monitor.c +6 -0
 
+    if (object_class_is_abstract(obj)) {
+        qerror_report(QERR_INVALID_PARAMETER_VALUE, "driver",
+                      "non-abstract device type");
+        return NULL;
+    }
+
     k = DEVICE_CLASS(obj);
 
     /* find bus */

Looks good,

Paolo

#2 lore raw
In reply to Igor Mammedov

Am 17.09.2013 15:32, schrieb Igor Mammedov:

Quoted 8 lines

user is able to crash running QEMU when following monitor command is called:

device_add intel-hda-generic

crash is caused by assertion in object_initialize_with_type() when type is abstract.

Quoted 7 lines

Checking if type is abstract before instance is created in qdev_device_add() allows to prevent crash on incorrect user input.

---
 qdev-monitor.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)

Thanks, rebased and applied to qom-next:
https://github.com/afaerber/qemu-cpu/commits/qom-next

One question though:

qdev-monitor.c DeviceState *qdev_device_add(QemuOpts *opts) · line 477

Quoted 12 lines
qdev-monitor.c +3 -0
index 410cdcb..bb2e1b6 100644
@@ -472,6 +472,12 @@ DeviceState *qdev_device_add(QemuOpts *opts)
         return NULL;
     }
 
+    if (object_class_is_abstract(obj)) {
+        qerror_report(QERR_INVALID_PARAMETER_VALUE, "driver",
+                      "non-abstract device type");

Is qerror_report() still okay despite the QERR_* considered obsolete for error_set()? I.e. because this is only printing the text and not passing on error classes? Or where do we draw the line? (CC Luiz)

Thanks,
Andreas

Quoted 6 lines
qdev-monitor.c +3 -0
+        return NULL;
+    }
+
     k = DEVICE_CLASS(obj);
 
     /* find bus */
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#3 lore raw
Quoted 8 lines · On Tue, 17 Sep 2013 19:42:08 +0200 Andreas Färber <[email protected]> wrote:
Quoted 8 lines
qdev-monitor.c +0 -0
index 410cdcb..bb2e1b6 100644
@@ -472,6 +472,12 @@ DeviceState *qdev_device_add(QemuOpts *opts)
         return NULL;
     }
 
Quoted 7 lines

qdev-monitor.c DeviceState *qdev_device_add(QemuOpts *opts) · line 477

Quoted 3 lines
qdev-monitor.c +3 -0
+    if (object_class_is_abstract(obj)) {
+        qerror_report(QERR_INVALID_PARAMETER_VALUE, "driver",
+                      "non-abstract device type");

Is qerror_report() still okay despite the QERR_* considered obsolete for error_set()? I.e. because this is only printing the text and not passing on error classes?

This is OK because qdev_device_add() still uses qerror_report(). This is so because do_device_add() (the QMP/HMP command in question) hasn't been converted yet.

Quoted 1 line

Or where do we draw the line? (CC Luiz)

We should convert old qerror_report() users to error_set() whenever doing error-related changes. But sometimes it may not be practical to do it right away (this case).