PCI: hv: Avoid use of hv_pci_dev->pci_slot after freeing it
authorDexuan Cui <decui@microsoft.com>
Fri, 2 Aug 2019 22:50:20 +0000 (22:50 +0000)
committerLorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Mon, 12 Aug 2019 13:14:00 +0000 (14:14 +0100)
The slot must be removed before the pci_dev is removed, otherwise a panic
can happen due to use-after-free.

Fixes: 15becc2b56c6 ("PCI: hv: Add hv_pci_remove_slots() when we unload the driver")
Signed-off-by: Dexuan Cui <decui@microsoft.com>
Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Cc: stable@vger.kernel.org
drivers/pci/controller/pci-hyperv.c

index 40b625458afa5edbbb98adadf4a6a8b317aea7ce..2b53976cd9f93736c1d9d2eeb37ae233eddc2386 100644 (file)
@@ -2701,8 +2701,8 @@ static int hv_pci_remove(struct hv_device *hdev)
                /* Remove the bus from PCI's point of view. */
                pci_lock_rescan_remove();
                pci_stop_root_bus(hbus->pci_bus);
-               pci_remove_root_bus(hbus->pci_bus);
                hv_pci_remove_slots(hbus);
+               pci_remove_root_bus(hbus->pci_bus);
                pci_unlock_rescan_remove();
                hbus->state = hv_pcibus_removed;
        }