Skip to contentSkip to conversation

iommu/amd: Fix leak of data->entry in irq_remapping_alloc() error path

PATCH Applied lirongqing 2 participants 2 messages Sep 22 – Sep 24

Subsystems (2)
lore
Share & tools
lore

lirongqing

author
#0 lore raw

PATCH 1/1 iommu/amd: Fix leak of data->entry in irq_remapping_alloc() error path

From: Li RongQing <[email protected]>

In irq_remapping_alloc() each per-IRQ iteration allocates two objects:
the amd_ir_data (chip_data) and its data->entry (union irte / struct irte_ga). The out_free_data error path only freed chip_data via kfree(irq_data->chip_data), leaking data->entry for every already initialized IRQ.

Free data->entry alongside data on the error path.

---
 drivers/iommu/amd/iommu.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/iommu/amd/iommu.c +5 -2
index fd27373..92e93d2 100644
@@ -3906,8 +3906,11 @@ static int irq_remapping_alloc(struct irq_domain *domain, unsigned int virq,
 out_free_data:
 	for (i--; i >= 0; i--) {
 		irq_data = irq_domain_get_irq_data(domain, virq + i);
-		if (irq_data)
-			kfree(irq_data->chip_data);
+		if (irq_data && irq_data->chip_data) {
+			data = irq_data->chip_data;
+			kfree(data->entry);
+			kfree(data);
+		}
 	}
 	for (i = 0; i < nr_irqs; i++)
 		free_irte(iommu, devid, index + i);
Signature · 1 line
2.9.4
maintainer Applied
#1 lore raw
Quoted 2 lines · lirongqing
 drivers/iommu/amd/iommu.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

Applied, thanks.