[PATCH 2/2] powerpc/powernv/pci: Fix underflow and leak issue

Nam Cao posted 2 patches 2 months ago
[PATCH 2/2] powerpc/powernv/pci: Fix underflow and leak issue
Posted by Nam Cao 2 months ago
pnv_irq_domain_alloc() allocates interrupts at parent's interrupt
domain. If it fails in the progress, all allocated interrupts are
freed.

The number of successfully allocated interrupts so far is stored
"i". However, "i - 1" interrupts are freed. This is broken:

    - One interrupt is not be freed

    - If "i" is zero, "i - 1" wraps around

Correct the number of freed interrupts to "i".

Fixes: 0fcfe2247e75 ("powerpc/powernv/pci: Add MSI domains")
Signed-off-by: Nam Cao <namcao@linutronix.de>
Cc: stable@vger.kernel.org
---
 arch/powerpc/platforms/powernv/pci-ioda.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/powerpc/platforms/powernv/pci-ioda.c b/arch/powerpc/platforms/powernv/pci-ioda.c
index d8ccf2c9b98a..0166bf39ce1e 100644
--- a/arch/powerpc/platforms/powernv/pci-ioda.c
+++ b/arch/powerpc/platforms/powernv/pci-ioda.c
@@ -1854,7 +1854,7 @@ static int pnv_irq_domain_alloc(struct irq_domain *domain, unsigned int virq,
 	return 0;
 
 out:
-	irq_domain_free_irqs_parent(domain, virq, i - 1);
+	irq_domain_free_irqs_parent(domain, virq, i);
 	msi_bitmap_free_hwirqs(&phb->msi_bmp, hwirq, nr_irqs);
 	return ret;
 }
-- 
2.39.5
Re: [PATCH 2/2] powerpc/powernv/pci: Fix underflow and leak issue
Posted by Cédric Le Goater 2 months ago
On 8/4/25 12:07, Nam Cao wrote:
> pnv_irq_domain_alloc() allocates interrupts at parent's interrupt
> domain. If it fails in the progress, all allocated interrupts are
> freed.
> 
> The number of successfully allocated interrupts so far is stored
> "i". However, "i - 1" interrupts are freed. This is broken:
> 
>      - One interrupt is not be freed
> 
>      - If "i" is zero, "i - 1" wraps around
> 
> Correct the number of freed interrupts to "i".
> 
> Fixes: 0fcfe2247e75 ("powerpc/powernv/pci: Add MSI domains")
> Signed-off-by: Nam Cao <namcao@linutronix.de>
> Cc: stable@vger.kernel.org
> ---
>   arch/powerpc/platforms/powernv/pci-ioda.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: Cédric Le Goater <clg@redhat.com>

Thanks,

C.