hw/core: fix segmentation fault
PATCH 1/1 hw/core: fix segmentation fault
Reproducer:
$i386-softmmu/qemu-system-i386 -S -machine isapc,accel=tcg -device amd-iommu
Segmentation fault (core dumped)
Partial bt:
#0 bus_add_child (child=0x555556d4e520, bus=0x0) at hw/core/qdev.c:88 #1 qdev_set_parent_bus (dev=0x555556d4e520, bus=bus@entry=0x0) at hw/core/qdev.c:119
--- hw/core/qdev.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
hw/core/qdev.c +5 -1
@@ -84,7 +84,11 @@ static void bus_add_child(BusState *bus, DeviceState *child) {char name[32 ];BusChild *kid =g_malloc0 (sizeof (*kid)); - + +if (!bus) { +error_report ("bus not found " ); +exit (0 ); + } kid->index = bus->max_index++; kid->child = child;object_ref (OBJECT (kid->child));
Signature · 1 line
2.9.3
Quoted 21 lines · Suramya Shah
Reproducer:
$i386-softmmu/qemu-system-i386 -S -machine isapc,accel=tcg -device amd-iommu
Segmentation fault (core dumped)Partial bt:
#0bus_add_child(child=0x555556d4e520, bus=0x0) athw/core/qdev.c:88#1qdev_set_parent_bus(dev=0x555556d4e520, bus=bus@entry=0x0) athw/core/qdev.c:119Signed-off-by Suramya Shah <[email protected]>--- hw/core/qdev.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)hw/core/qdev.c +0
-0@@ -84,7 +84,11 @@ static void bus_add_child(BusState *bus, DeviceState *child) {char name[32 ];
hw/core/qdev.c static void bus_add_child(BusState *bus, DeviceState *child) · line 94
Quoted 10 lines
hw/core/qdev.c +5
-1BusChild *kid =g_malloc0 (sizeof (*kid)); - + +if (!bus) { +error_report ("bus not found " ); +exit (0 ); + } kid->index = bus->max_index++; kid->child = child;object_ref (OBJECT (kid->child));
Thanks for the patch, but this doesn't look like the right way to fix this. Exiting with an error in a low-level function like this is not really any better than crashing. This function is not supposed to be called with a NULL bus pointer, so the question is: why is that happening? Something in one of the calling functions, probably several layers up the stack, has a bug. To fix this bug we need to look at that code and identify why it is trying to add the child device to a NULL bus and what bus it ought to be putting it on instead.
thanks
-- PMM