Skip to contentSkip to conversation

qapi: output visitor crashes qemu if it encounters a NULL value

PATCH In review Marcel Apfelbaum 3 participants 6 messages Feb 17, 2014 – Mar 3, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 qapi: output visitor crashes qemu if it encounters a NULL value

A NULL value is not added to visitor's stack, but there is no check for that when the visitor tries to return that value, leading to Qemu crash.

---
 qapi/qmp-output-visitor.c | 5 +++++
 1 file changed, 5 insertions(+)
qapi/qmp-output-visitor.c +5 -0
index 74a5684..0562f49 100644
@@ -66,6 +66,11 @@ static QObject *qmp_output_pop(QmpOutputVisitor *qov)
 static QObject *qmp_output_first(QmpOutputVisitor *qov)
 {
     QStackEntry *e = QTAILQ_LAST(&qov->stack, QStack);
+
+    if (!e) {
+        return NULL;
+    }
+
     return e->value;
 }
 
Signature · 1 line
1.8.3.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 3 lines · Marcel Apfelbaum

A NULL value is not added to visitor's stack, but there is no check for that when the visitor tries to return that value, leading to Qemu crash.

Do you have an easy formula for reproducing the crash?

Quoted 11 lines
---
 qapi/qmp-output-visitor.c | 5 +++++
 1 file changed, 5 insertions(+)
qapi/qmp-output-visitor.c +0 -0
index 74a5684..0562f49 100644

qapi/qmp-output-visitor.c static QObject *qmp_output_pop(QmpOutputVisitor *qov) · line 73

Quoted 8 lines
qapi/qmp-output-visitor.c +5 -0
@@ -66,6 +66,11 @@ static QObject *qmp_output_pop(QmpOutputVisitor *qov)
 static QObject *qmp_output_first(QmpOutputVisitor *qov)
 {
     QStackEntry *e = QTAILQ_LAST(&qov->stack, QStack);
+
+    if (!e) {
+        return NULL;
+    }
+

The code looks okay to me, but without a formula, my review is fairly weak:

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#2 lore raw
Quoted 6 lines · Eric Blake
Quoted 3 lines · Marcel Apfelbaum

A NULL value is not added to visitor's stack, but there is no check for that when the visitor tries to return that value, leading to Qemu crash.

Do you have an easy formula for reproducing the crash?

Hi Eric, thank you for your review!

In order to reproduce this you need to use object_property_get_str on an object with a string property with a null value.

I don't know if in the current code base we have this scenario, but I am trying to QOMify the QemuMachine and properties as "kernel" may be NULL.

Either way (if NULL properties are not wanted), IMHO it is recommended to cover such cases in order to avoid QEMU crash.

Quoted 7 lines
Quoted 7 lines
---
 qapi/qmp-output-visitor.c | 5 +++++
 1 file changed, 5 insertions(+)
Quoted 15 lines

qapi/qmp-output-visitor.c static QObject *qmp_output_pop(QmpOutputVisitor *qov) · line 73

Quoted 13 lines
qapi/qmp-output-visitor.c +5 -0
index 74a5684..0562f49 100644
@@ -66,6 +66,11 @@ static QObject *qmp_output_pop(QmpOutputVisitor *qov)
 static QObject *qmp_output_first(QmpOutputVisitor *qov)
 {
     QStackEntry *e = QTAILQ_LAST(&qov->stack, QStack);
+
+    if (!e) {
+        return NULL;
+    }
+

The code looks okay to me, but without a formula, my review is fairly weak:

Appreciated,
Marcel

Quoted 3 lines
#3 lore raw
Quoted 6 lines · On Mon, 17 Feb 2014 20:01:42 +0200 Marcel Apfelbaum <[email protected]> wrote:
Quoted 5 lines · Eric Blake
Quoted 3 lines · Marcel Apfelbaum

A NULL value is not added to visitor's stack, but there is no check for that when the visitor tries to return that value, leading to Qemu crash.

Quoted 6 lines
Quoted 1 line

Do you have an easy formula for reproducing the crash?

Hi Eric, thank you for your review!

In order to reproduce this you need to use object_property_get_str on an object with a string property with a null value.

I tried looking into this but got a bit lost in the abstraction maze. Can you point me to your series and how to reproduce it?

Quoted 4 lines

I don't know if in the current code base we have this scenario, but I am trying to QOMify the QemuMachine and properties as "kernel" may be NULL.

Either way (if NULL properties are not wanted), IMHO it is recommended to cover such cases in order to avoid QEMU crash.

I agree, but I want to be sure we're fixing the right thing and not only papering over a bug. Also, Why is the check not needed in qmp_output_last()?

Btw, sorry for the long delay.

Quoted 32 lines
Quoted 8 lines
Quoted 8 lines
---
 qapi/qmp-output-visitor.c | 5 +++++
 1 file changed, 5 insertions(+)
Quoted 15 lines

qapi/qmp-output-visitor.c static QObject *qmp_output_pop(QmpOutputVisitor *qov) · line 73

Quoted 13 lines
qapi/qmp-output-visitor.c +5 -0
index 74a5684..0562f49 100644
@@ -66,6 +66,11 @@ static QObject *qmp_output_pop(QmpOutputVisitor *qov)
 static QObject *qmp_output_first(QmpOutputVisitor *qov)
 {
     QStackEntry *e = QTAILQ_LAST(&qov->stack, QStack);
+
+    if (!e) {
+        return NULL;
+    }
+

The code looks okay to me, but without a formula, my review is fairly weak:

Appreciated,
Marcel

Quoted 3 lines
#4 lore raw
Quoted 11 lines · Luiz Capitulino
Quoted 8 lines · On Mon, 17 Feb 2014 20:01:42 +0200 Marcel Apfelbaum <[email protected]> wrote:
Quoted 6 lines · Eric Blake
Quoted 3 lines · Marcel Apfelbaum

A NULL value is not added to visitor's stack, but there is no check for that when the visitor tries to return that value, leading to Qemu crash.

Do you have an easy formula for reproducing the crash?

Quoted 7 lines
Quoted 4 lines

Hi Eric, thank you for your review!

In order to reproduce this you need to use object_property_get_str on an object with a string property with a null value.

I tried looking into this but got a bit lost in the abstraction maze. Can you point me to your series and how to reproduce it?

Hi Luiz, thanks for the review!

I will send an RFC V2 soon and CC you to it. Basically if you have a string property with a NULL value and you access it with obj_property_get_str, QEMU will crush. You can see this in the series.

Quoted 8 lines
Quoted 5 lines

I don't know if in the current code base we have this scenario, but I am trying to QOMify the QemuMachine and properties as "kernel" may be NULL.

Either way (if NULL properties are not wanted), IMHO it is recommended to cover such cases in order to avoid QEMU crash.

I agree, but I want to be sure we're fixing the right thing and not only papering over a bug. Also, Why is the check not needed in qmp_output_last()?

You lost me here, I debugged the above crush and this was the exact place the check should be in order to avoid it. It is a "get" path.

Quoted 2 lines

Btw, sorry for the long delay.

No problem, I am going to send this as part of machine QOMify series.

Thanks,
Marcel

Quoted 33 lines
Quoted 32 lines
Quoted 8 lines
Quoted 8 lines
---
 qapi/qmp-output-visitor.c | 5 +++++
 1 file changed, 5 insertions(+)
Quoted 15 lines

qapi/qmp-output-visitor.c static QObject *qmp_output_pop(QmpOutputVisitor *qov) · line 73

Quoted 13 lines
qapi/qmp-output-visitor.c +5 -0
index 74a5684..0562f49 100644
@@ -66,6 +66,11 @@ static QObject *qmp_output_pop(QmpOutputVisitor *qov)
 static QObject *qmp_output_first(QmpOutputVisitor *qov)
 {
     QStackEntry *e = QTAILQ_LAST(&qov->stack, QStack);
+
+    if (!e) {
+        return NULL;
+    }
+

The code looks okay to me, but without a formula, my review is fairly weak:

Appreciated,
Marcel

Quoted 3 lines
#5 lore raw
Quoted 17 lines · On Sun, 02 Mar 2014 12:15:45 +0200 Marcel Apfelbaum <[email protected]> wrote:
Quoted 16 lines · Luiz Capitulino
Quoted 12 lines · On Mon, 17 Feb 2014 20:01:42 +0200 Marcel Apfelbaum <[email protected]> wrote:
Quoted 6 lines · Eric Blake
Quoted 3 lines · Marcel Apfelbaum

A NULL value is not added to visitor's stack, but there is no check for that when the visitor tries to return that value, leading to Qemu crash.

Do you have an easy formula for reproducing the crash?

Hi Eric, thank you for your review!

In order to reproduce this you need to use object_property_get_str on an object with a string property with a null value.

Quoted 7 lines
Quoted 2 lines

I tried looking into this but got a bit lost in the abstraction maze. Can you point me to your series and how to reproduce it?

Hi Luiz, thanks for the review!

I will send an RFC V2 soon and CC you to it. Basically if you have a string property with a NULL value and you access it with obj_property_get_str, QEMU will crush. You can see this in the series.

Yes, saw it. Fix looks OK.

Quoted 9 lines
Quoted 7 lines
Quoted 4 lines

I don't know if in the current code base we have this scenario, but I am trying to QOMify the QemuMachine and properties as "kernel" may be NULL.

Either way (if NULL properties are not wanted), IMHO it is recommended to cover such cases in order to avoid QEMU crash.

I agree, but I want to be sure we're fixing the right thing and not only papering over a bug. Also, Why is the check not needed in qmp_output_last()?

You lost me here, I debugged the above crush and this was the exact place the check should be in order to avoid it. It is a "get" path.

If we allow stack elements to be NULL, then I'd guess that the same problem might as well happen with qmp_output_last().

Quoted 43 lines
Quoted 2 lines

Btw, sorry for the long delay.

No problem, I am going to send this as part of machine QOMify series.

Thanks,
Marcel

Quoted 33 lines
Quoted 32 lines
Quoted 8 lines
Quoted 8 lines
---
 qapi/qmp-output-visitor.c | 5 +++++
 1 file changed, 5 insertions(+)
Quoted 15 lines

qapi/qmp-output-visitor.c static QObject *qmp_output_pop(QmpOutputVisitor *qov) · line 73

Quoted 13 lines
qapi/qmp-output-visitor.c +5 -0
index 74a5684..0562f49 100644
@@ -66,6 +66,11 @@ static QObject *qmp_output_pop(QmpOutputVisitor *qov)
 static QObject *qmp_output_first(QmpOutputVisitor *qov)
 {
     QStackEntry *e = QTAILQ_LAST(&qov->stack, QStack);
+
+    if (!e) {
+        return NULL;
+    }
+

The code looks okay to me, but without a formula, my review is fairly weak:

Appreciated,
Marcel

Quoted 3 lines