Skip to contentSkip to conversation

spapr_rtas: Prevent QEMU crash during hotplug without a prior device_add

PATCH In review Bharata B Rao 2 participants 4 messages Aug 26, 2015 – Aug 28, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 spapr_rtas: Prevent QEMU crash during hotplug without a prior device_add

If drmgr is used in the guest to hotplug a device before a device_add has been issued via the QEMU monitor, QEMU segfaults in configure_connector call. This occurs due to accessing of NULL FDT which otherwise would have been created and associated with the DRC during device_add command.

Check for NULL FDT and return failure from configure_connector call.

---
Not fully sure if RTAS_OUT_HW_ERROR is the right error code here. Should we be using RTAS_OUT_NOT_SUPPORTED instead ?

 hw/ppc/spapr_rtas.c | 6 ++++++
 1 file changed, 6 insertions(+)
hw/ppc/spapr_rtas.c +6 -0
index e99e25f..3be8eec 100644
@@ -522,6 +522,12 @@ static void rtas_ibm_configure_connector(PowerPCCPU *cpu,
 
     drck = SPAPR_DR_CONNECTOR_GET_CLASS(drc);
     fdt = drck->get_fdt(drc, NULL);
+    if (!fdt) {
+        DPRINTF("rtas_ibm_configure_connector: Missing FDT for DRC index: %xh\n",
+                drc_index);
+        rc = RTAS_OUT_HW_ERROR;
+        goto out;
+    }
 
     ccs = spapr_ccs_find(spapr, drc_index);
     if (!ccs) {
Signature · 1 line
2.1.0
Reviewed-by on v1 1/1
#1 lore raw

Quoting Bharata B Rao (2015-08-25 23:04:11)

Quoted 9 lines

If drmgr is used in the guest to hotplug a device before a device_add has been issued via the QEMU monitor, QEMU segfaults in configure_connector call. This occurs due to accessing of NULL FDT which otherwise would have been created and associated with the DRC during device_add command.

Check for NULL FDT and return failure from configure_connector call.

Quoted 27 lines

---
Not fully sure if RTAS_OUT_HW_ERROR is the right error code here. Should we be using RTAS_OUT_NOT_SUPPORTED instead ?

 hw/ppc/spapr_rtas.c | 6 ++++++
 1 file changed, 6 insertions(+)
hw/ppc/spapr_rtas.c +6 -0
index e99e25f..3be8eec 100644
@@ -522,6 +522,12 @@ static void rtas_ibm_configure_connector(PowerPCCPU *cpu,
 
     drck = SPAPR_DR_CONNECTOR_GET_CLASS(drc);
     fdt = drck->get_fdt(drc, NULL);
+    if (!fdt) {
+        DPRINTF("rtas_ibm_configure_connector: Missing FDT for DRC index: %xh\n",
+                drc_index);
+        rc = RTAS_OUT_HW_ERROR;
+        goto out;
+    }
 
     ccs = spapr_ccs_find(spapr, drc_index);
     if (!ccs) {
Signature · 1 line
2.1.0
#2 lore raw
Quoted 6 lines · Michael Roth

Quoting Bharata B Rao (2015-08-25 23:04:11)

Quoted 5 lines

If drmgr is used in the guest to hotplug a device before a device_add has been issued via the QEMU monitor, QEMU segfaults in configure_connector call. This occurs due to accessing of NULL FDT which otherwise would have been created and associated with the DRC during device_add command.

Quoted 10 lines
Quoted 4 lines

Check for NULL FDT and return failure from configure_connector call.

Quoted 3 lines

---
Not fully sure if RTAS_OUT_HW_ERROR is the right error code here. Should we be using RTAS_OUT_NOT_SUPPORTED instead ?

Based on my reading of PAPR+ 2.7, it appears that we should return -9003 error code here.

I am planning to add

#define SPAPR_DR_CC_RESPONSE_NOT_CONFIGURABLE -9003

and use it when fdt is NULL in ibm,configure-connector call. Is that fine ?

Regards,
Bharata.

#3 lore raw

Quoting Bharata B Rao (2015-08-27 00:28:57)

Quoted 18 lines · Michael Roth
Quoted 6 lines

Quoting Bharata B Rao (2015-08-25 23:04:11)

Quoted 5 lines

If drmgr is used in the guest to hotplug a device before a device_add has been issued via the QEMU monitor, QEMU segfaults in configure_connector call. This occurs due to accessing of NULL FDT which otherwise would have been created and associated with the DRC during device_add command.

Quoted 10 lines
Quoted 4 lines

Check for NULL FDT and return failure from configure_connector call.

Quoted 3 lines

---
Not fully sure if RTAS_OUT_HW_ERROR is the right error code here. Should we be using RTAS_OUT_NOT_SUPPORTED instead ?

Quoted 8 lines

Based on my reading of PAPR+ 2.7, it appears that we should return -9003 error code here.

I am planning to add

#define SPAPR_DR_CC_RESPONSE_NOT_CONFIGURABLE -9003

and use it when fdt is NULL in ibm,configure-connector call. Is that fine ?

Yes, that error seems in line with this situation, and proposed constant seems fine to me (assuming you add to the existing sPAPRDRCCResponse enum)

Quoted 4 lines

Regards,
Bharata.