Skip to content

Commit 6a9484e

Browse files
author
Myron Stowe
committed
PCI: endpoint: Fix PCI domain ID release in pci_epc_destroy()
JIRA: https://issues.redhat.com/browse/RHEL-67693 Upstream Status: 4acc902 commit 4acc902 Author: Zijun Hu <[email protected]> Date: Thu Nov 7 08:53:08 2024 +0800 PCI: endpoint: Fix PCI domain ID release in pci_epc_destroy() pci_epc_destroy() invokes pci_bus_release_domain_nr() to release the PCI domain ID, but there are two issues: - 'epc->dev' is passed to pci_bus_release_domain_nr() which was already freed by device_unregister(), leading to a use-after-free issue. - Domain ID corresponds to the EPC device parent, so passing 'epc->dev' is also wrong. Fix these issues by passing 'epc->dev.parent' to pci_bus_release_domain_nr() and also do it before device_unregister(). Fixes: 0328947 ("PCI: endpoint: Assign PCI domain number for endpoint controllers") Signed-off-by: Zijun Hu <[email protected]> Reviewed-by: Manivannan Sadhasivam <[email protected]> Link: https://lore.kernel.org/r/[email protected] [mani: reworded subject and description] Signed-off-by: Manivannan Sadhasivam <[email protected]> Signed-off-by: Bjorn Helgaas <[email protected]> Signed-off-by: Krzysztof Wilczyński <[email protected]> Cc: [email protected] Signed-off-by: Myron Stowe <[email protected]>
1 parent 13cab74 commit 6a9484e

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

drivers/pci/endpoint/pci-epc-core.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -837,11 +837,10 @@ EXPORT_SYMBOL_GPL(pci_epc_bus_master_enable_notify);
837837
void pci_epc_destroy(struct pci_epc *epc)
838838
{
839839
pci_ep_cfs_remove_epc_group(epc->group);
840-
device_unregister(&epc->dev);
841-
842840
#ifdef CONFIG_PCI_DOMAINS_GENERIC
843-
pci_bus_release_domain_nr(&epc->dev, epc->domain_nr);
841+
pci_bus_release_domain_nr(epc->dev.parent, epc->domain_nr);
844842
#endif
843+
device_unregister(&epc->dev);
845844
}
846845
EXPORT_SYMBOL_GPL(pci_epc_destroy);
847846

0 commit comments

Comments
 (0)