Skip to contentSkip to conversation

iommu/amd: Fix PCI device reference leak in PPR handling

PATCH In review Ruoyu Wang 3 participants 4 messages Aug 14 – Aug 23

Subsystems (3)
lore
Share & tools
lore

Ruoyu Wang

author
#0 lore raw

PATCH 1/1 iommu/amd: Fix PCI device reference leak in PPR handling

pci_get_domain_bus_and_slot() takes a reference on the returned PCI device. iommu_call_iopf_notifier() fails to release it after either reporting a valid PPR fault or completing a rejected request. Each handled request therefore leaks a reference and can prevent the PCI device from being released.

Call pci_dev_put() after the final use of the lookup reference on both paths.

This issue was found by a static analysis checker and confirmed by manual source review.

Fixes 978d626b8f1a ("iommu/amd: Add IO page fault notifier handler")
---
 drivers/iommu/amd/ppr.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/iommu/amd/ppr.c +2 -0
index 1f8d2823bea42..1e4392b17bd8f 100644
@@ -151,6 +151,7 @@ static void iommu_call_iopf_notifier(struct amd_iommu *iommu, u64 *raw)
 
 	/* Submit event */
 	iommu_report_device_fault(&pdev->dev, &event);
+	pci_dev_put(pdev);
 
 	return;
 
@@ -159,6 +160,7 @@ static void iommu_call_iopf_notifier(struct amd_iommu *iommu, u64 *raw)
 	amd_iommu_complete_ppr(&pdev->dev, PPR_PASID(raw[0]),
 			       IOMMU_PAGE_RESP_FAILURE,
 			       PPR_TAG(raw[0]) & 0x1FF);
+	pci_dev_put(pdev);
 }
 
 void amd_iommu_poll_ppr_log(struct amd_iommu *iommu)
Signature · 1 line
2.51.0
maintainer
#2 lore raw
In reply to Ruoyu Wang
Quoted 10 lines · Ruoyu Wang

[You don't often get email from [email protected]. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]

pci_get_domain_bus_and_slot() takes a reference on the returned PCI device. iommu_call_iopf_notifier() fails to release it after either reporting a valid PPR fault or completing a rejected request. Each handled request therefore leaks a reference and can prevent the PCI device from being released.

Call pci_dev_put() after the final use of the lookup reference on both paths.

This was recently fixed by commit af3b69b16383.

-Vasant