Skip to contentSkip to conversation

hw/hyperv: fix NULL dereference with pure-kvm SynIC

PATCH Applied Roman Kagan 4 participants 5 messages Nov 26, 2018 – Nov 27, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hw/hyperv: fix NULL dereference with pure-kvm SynIC

When started in compat configuration of SynIC, e.g.

qemu-system-x86_64 -machine pc-i440fx-2.10,accel=kvm \
-cpu host,-vmx,hv-relaxed,hv_spinlocks=0x1fff,hv-vpindex,hv-synic

or explicitly

qemu-system-x86_64 -enable-kvm -cpu host,hv-synic,x-hv-synic-kvm-only=on

QEMU crashes in hyperv_synic_reset() trying to access the non-present qobject for SynIC.

Add the missing check for NULL.

Fixes 9b4cf107b09d18ac30f46fd1c4de8585ccba030c
Fixes 4a93722f9c279184e95b1e1ad775c01deec05065
---
 hw/hyperv/hyperv.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
hw/hyperv/hyperv.c +5 -1
index a28e7249d8..8758635227 100644
@@ -136,7 +136,11 @@ void hyperv_synic_add(CPUState *cs)
 
 void hyperv_synic_reset(CPUState *cs)
 {
-    device_reset(DEVICE(get_synic(cs)));
+    SynICState *synic = get_synic(cs);
+
+    if (synic) {
+        device_reset(DEVICE(synic));
+    }
 }
 
 static const TypeInfo synic_type_info = {
Signature · 1 line
2.19.1
Reviewed-by Tested-by on v1 1/1
#1 lore raw
Quoted 12 lines · Roman Kagan

When started in compat configuration of SynIC, e.g.

qemu-system-x86_64 -machine pc-i440fx-2.10,accel=kvm \
-cpu host,-vmx,hv-relaxed,hv_spinlocks=0x1fff,hv-vpindex,hv-synic

or explicitly

qemu-system-x86_64 -enable-kvm -cpu host,hv-synic,x-hv-synic-kvm-only=on

QEMU crashes in hyperv_synic_reset() trying to access the non-present qobject for SynIC.

Quoted 7 lines

Add the missing check for NULL.

Fixes 9b4cf107b09d18ac30f46fd1c4de8585ccba030c
Fixes 4a93722f9c279184e95b1e1ad775c01deec05065
Quoted 22 lines
---
 hw/hyperv/hyperv.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
hw/hyperv/hyperv.c +5 -1
index a28e7249d8..8758635227 100644
@@ -136,7 +136,11 @@ void hyperv_synic_add(CPUState *cs)
 
 void hyperv_synic_reset(CPUState *cs)
 {
-    device_reset(DEVICE(get_synic(cs)));
+    SynICState *synic = get_synic(cs);
+
+    if (synic) {
+        device_reset(DEVICE(synic));
+    }
 }
 
 static const TypeInfo synic_type_info = {
#2 lore raw
In reply to Roman Kagan
Quoted 31 lines · Roman Kagan

When started in compat configuration of SynIC, e.g.

qemu-system-x86_64 -machine pc-i440fx-2.10,accel=kvm \
-cpu host,-vmx,hv-relaxed,hv_spinlocks=0x1fff,hv-vpindex,hv-synic

or explicitly

qemu-system-x86_64 -enable-kvm -cpu host,hv-synic,x-hv-synic-kvm-only=on

QEMU crashes in hyperv_synic_reset() trying to access the non-present qobject for SynIC.

Add the missing check for NULL.

Fixes 9b4cf107b09d18ac30f46fd1c4de8585ccba030c
Fixes 4a93722f9c279184e95b1e1ad775c01deec05065
---
 hw/hyperv/hyperv.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
hw/hyperv/hyperv.c +0 -0
index a28e7249d8..8758635227 100644
@@ -136,7 +136,11 @@ void hyperv_synic_add(CPUState *cs)
 
 void hyperv_synic_reset(CPUState *cs)

hw/hyperv/hyperv.c void hyperv_synic_add(CPUState *cs) · line 146

Quoted 10 lines
hw/hyperv/hyperv.c +5 -1
 {
-    device_reset(DEVICE(get_synic(cs)));
+    SynICState *synic = get_synic(cs);
+
+    if (synic) {
+        device_reset(DEVICE(synic));
+    }
 }
 
 static const TypeInfo synic_type_info = {

Queued, thanks.

Paolo

#3 lore raw
Quoted 40 lines · Paolo Bonzini
Quoted 39 lines · Roman Kagan

When started in compat configuration of SynIC, e.g.

qemu-system-x86_64 -machine pc-i440fx-2.10,accel=kvm \
-cpu host,-vmx,hv-relaxed,hv_spinlocks=0x1fff,hv-vpindex,hv-synic

or explicitly

qemu-system-x86_64 -enable-kvm -cpu host,hv-synic,x-hv-synic-kvm-only=on

QEMU crashes in hyperv_synic_reset() trying to access the non-present qobject for SynIC.

Add the missing check for NULL.

Fixes 9b4cf107b09d18ac30f46fd1c4de8585ccba030c
Fixes 4a93722f9c279184e95b1e1ad775c01deec05065
---
 hw/hyperv/hyperv.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
hw/hyperv/hyperv.c +5 -1
index a28e7249d8..8758635227 100644
@@ -136,7 +136,11 @@ void hyperv_synic_add(CPUState *cs)
 
 void hyperv_synic_reset(CPUState *cs)
 {
-    device_reset(DEVICE(get_synic(cs)));
+    SynICState *synic = get_synic(cs);
+
+    if (synic) {
+        device_reset(DEVICE(synic));
+    }
 }
 
Quoted 4 lines

hw/hyperv/hyperv.c void hyperv_synic_add(CPUState *cs) · line 146

Quoted 2 lines
hw/hyperv/hyperv.c +0 -0
 static const TypeInfo synic_type_info = {

Queued, thanks.

Oops, I had queued it earlier today and just submitted a pull request.

Signature · 1 line
Eduardo
#4 lore raw
Quoted 41 lines · Eduardo Habkost
Quoted 40 lines · Paolo Bonzini
Quoted 39 lines · Roman Kagan

When started in compat configuration of SynIC, e.g.

qemu-system-x86_64 -machine pc-i440fx-2.10,accel=kvm \
-cpu host,-vmx,hv-relaxed,hv_spinlocks=0x1fff,hv-vpindex,hv-synic

or explicitly

qemu-system-x86_64 -enable-kvm -cpu host,hv-synic,x-hv-synic-kvm-only=on

QEMU crashes in hyperv_synic_reset() trying to access the non-present qobject for SynIC.

Add the missing check for NULL.

Fixes 9b4cf107b09d18ac30f46fd1c4de8585ccba030c
Fixes 4a93722f9c279184e95b1e1ad775c01deec05065
---
 hw/hyperv/hyperv.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
hw/hyperv/hyperv.c +5 -1
index a28e7249d8..8758635227 100644
@@ -136,7 +136,11 @@ void hyperv_synic_add(CPUState *cs)
 
 void hyperv_synic_reset(CPUState *cs)
 {
-    device_reset(DEVICE(get_synic(cs)));
+    SynICState *synic = get_synic(cs);
+
+    if (synic) {
+        device_reset(DEVICE(synic));
+    }
 }
 
Quoted 7 lines
Quoted 4 lines

hw/hyperv/hyperv.c void hyperv_synic_add(CPUState *cs) · line 146

Quoted 2 lines
hw/hyperv/hyperv.c +0 -0
 static const TypeInfo synic_type_info = {

Queued, thanks.

Oops, I had queued it earlier today and just submitted a pull request.

No big deal, it will be included twice. :)

Paolo