Skip to contentSkip to conversation

powerpc: Fix integer underflow & leak

PATCH Applied Nam Cao 3 participants 6 messages Aug 4, 2025 – Sep 6, 2025

Subsystems (2)
lore
Share & tools
lore

Nam Cao

author
#0 lore raw

cover powerpc: Fix integer underflow & leak

Hi,

This series fixes integer overflow & leak problem. I noticed this problem when Gautam reported a kernel bug with another patch series of mine:
https://lore.kernel.org/linuxppc-dev/[email protected]/

The root cause of that report is a bug in that series. However, that bug triggered another existing bug, causing the reported end results.

Nam Cao (2):
powerpc/pseries/msi: Fix potential underflow and leak issue powerpc/powernv/pci: Fix underflow and leak issue

 arch/powerpc/platforms/powernv/pci-ioda.c | 2 +-
 arch/powerpc/platforms/pseries/msi.c      | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
Signature · 1 line
2.39.5
author
#1 lore raw

PATCH 1/2 powerpc/pseries/msi: Fix potential underflow and leak issue

pseries_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 a5f3d2c17b07 ("powerpc/pseries/pci: Add MSI domains")
---
 arch/powerpc/platforms/pseries/msi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/platforms/pseries/msi.c +1 -1
index ee1c8c6898a3..9dc294de631f 100644
@@ -593,7 +593,7 @@ static int pseries_irq_domain_alloc(struct irq_domain *domain, unsigned int virq
 
 out:
 	/* TODO: handle RTAS cleanup in ->msi_finish() ? */
-	irq_domain_free_irqs_parent(domain, virq, i - 1);
+	irq_domain_free_irqs_parent(domain, virq, i);
 	return ret;
 }
 
Signature · 1 line
2.39.5
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] powerpc/pseries/msi: Fix potential underflow and leak issue

Quoted 11 lines · Nam Cao

pseries_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

Quoted 8 lines

Correct the number of freed interrupts to 'i'.

Fixes a5f3d2c17b07 ("powerpc/pseries/pci: Add MSI domains")
---
  arch/powerpc/platforms/pseries/msi.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

Thanks,

C.

author
#3 lore raw

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

In reply to Nam Cao

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")
---
 arch/powerpc/platforms/powernv/pci-ioda.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/platforms/powernv/pci-ioda.c +1 -1
index d8ccf2c9b98a..0166bf39ce1e 100644
@@ -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;
 }
Signature · 1 line
2.39.5
Reviewed-by on v1 2/2
#4 lore raw

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

Quoted 11 lines · Nam Cao

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

Quoted 8 lines

Correct the number of freed interrupts to "i".

Fixes 0fcfe2247e75 ("powerpc/powernv/pci: Add MSI domains")
---
  arch/powerpc/platforms/powernv/pci-ioda.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

Thanks,

C.

maintainer Applied
#5 lore raw
In reply to Nam Cao
Quoted 8 lines · Nam Cao

This series fixes integer overflow & leak problem. I noticed this problem when Gautam reported a kernel bug with another patch series of mine:
https://lore.kernel.org/linuxppc-dev/[email protected]/

The root cause of that report is a bug in that series. However, that bug triggered another existing bug, causing the reported end results.

[...]

Applied to powerpc/next.

[1/2] powerpc/pseries/msi: Fix potential underflow and leak issue

      https://git.kernel.org/powerpc/c/3443ff3be6e59b80d74036bb39f5b6409eb23cc9
[2/2] powerpc/powernv/pci: Fix underflow and leak issue
      https://git.kernel.org/powerpc/c/a39087905af9ffecaa237a918a2c03a04e479934

Thanks