Commit 955f5c7b authored by Igor Mammedov's avatar Igor Mammedov Committed by John Snow

ide: ahci: unparent children buses before freeing their memory

Fixes read after freeing error reported
  Message-Id: <>

ich9-ahci device creates ide buses and attaches them as QOM children
at realize time, however it forgets to properly clean them up
at unrealize time and frees memory containing these children,
with following call-chain:

     object_property_set_bool('realized', true)
          pci_qdev_realize() -> pci_ich9_ahci_realize() -> ahci_realize()
               s->dev = g_new0(AHCIDevice, ports);
                  AHCIDevice *ad = &s->dev[i];
                  ide_bus_new(&ad->port, sizeof(ad->port), qdev, i, 1);
                  ^^^ creates bus in memory allocated by above gnew()
                      and adds it as child propety to ahci device
          hotplug_handler_plug(); -> goto post_realize_fail;
          pci_qdev_unrealize() -> pci_ich9_uninit() -> ahci_uninit()
               ^^^ free memory that holds children busses

          return with error from device_set_realized()

As result later when qdev_device_add() tries to unparent ich9-ahci
after failed device_set_realized(),
    object_unparent() -> object_property_del_child()
iterates over existing QOM children including buses added by
ide_bus_new() and tries to unparent them, which causes access to
freed memory where they where located.
Reported-by: 's avatarThomas Huth <>
Signed-off-by: 's avatarIgor Mammedov <>
Reviewed-by: 's avatarPhilippe Mathieu-Daudé <>
Reviewed-by: 's avatarMichael S. Tsirkin <>
Tested-by: 's avatarThomas Huth <>
Reviewed-by: 's avatarJohn Snow <>
Signed-off-by: 's avatarJohn Snow <>
parent a9158a5c
......@@ -1495,6 +1495,7 @@ void ahci_uninit(AHCIState *s)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment