spapr_rtas: Prevent QEMU crash during hotplug without a prior device_add
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. As per PAPR+, an error value of -9003 seems appropriate for this failure.
---
Changes in v1:
- Use error value of -9003 instead of RTAS_OUT_HW_ERROR.
v0: http://lists.nongnu.org/archive/html/qemu-devel/2015-08/msg03026.html
hw/ppc/spapr_rtas.c | 6 ++++++ include/hw/ppc/spapr_drc.h | 15 ++++++++------- 2 files changed, 14 insertions(+), 7 deletions(-)
hw/ppc/spapr_rtas.c +6 -0
@@ -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 =SPAPR_DR_CC_RESPONSE_NOT_CONFIGURABLE ; + goto out; + } ccs =spapr_ccs_find (spapr, drc_index);if (!ccs) {
include/hw/ppc/spapr_drc.h +8 -7
@@ -119,13 +119,14 @@ typedef enum { } sPAPRDREntitySense;typedef enum { -SPAPR_DR_CC_RESPONSE_NEXT_SIB =1 ,/* currently unused */ -SPAPR_DR_CC_RESPONSE_NEXT_CHILD =2 , -SPAPR_DR_CC_RESPONSE_NEXT_PROPERTY =3 , -SPAPR_DR_CC_RESPONSE_PREV_PARENT =4 , -SPAPR_DR_CC_RESPONSE_SUCCESS =0 , -SPAPR_DR_CC_RESPONSE_ERROR =-1 , -SPAPR_DR_CC_RESPONSE_CONTINUE =-2 , +SPAPR_DR_CC_RESPONSE_NEXT_SIB =1 ,/* currently unused */ +SPAPR_DR_CC_RESPONSE_NEXT_CHILD =2 , +SPAPR_DR_CC_RESPONSE_NEXT_PROPERTY =3 , +SPAPR_DR_CC_RESPONSE_PREV_PARENT =4 , +SPAPR_DR_CC_RESPONSE_SUCCESS =0 , +SPAPR_DR_CC_RESPONSE_ERROR =-1 , +SPAPR_DR_CC_RESPONSE_CONTINUE =-2 , +SPAPR_DR_CC_RESPONSE_NOT_CONFIGURABLE =-9003 , }sPAPRDRCCResponse ;typedef void (spapr_drc_detach_cb )(DeviceState *d,void *opaque);
Signature · 1 line
2.1.0
David Gibson
AppliedQuoted 10 lines · Bharata B Rao
If drmgr is used in the guest to hotplug a device before a
device_addhas been issued via the QEMU monitor, QEMU segfaults inconfigure_connectorcall. This occurs due to accessing of NULL FDT which otherwise would have been created and associated with the DRC duringdevice_addcommand.Check for NULL FDT and return failure from
configure_connectorcall. As per PAPR+, an error value of -9003 seems appropriate for this failure.Signed-off-by Bharata B Rao <[email protected]>Cc Michael Roth <[email protected]>
Applied to spapr-next, thanks.
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson