Skip to contentSkip to conversation

net: ipa: Fix double free of the interrupt structure on config error

PATCH Applied Thomas Fourier 4 participants 4 messages Oct 29 – Oct 31

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 net: ipa: Fix double free of the interrupt structure on config error

Since ipa_interrupt_init() allocates struct ipa_interrupt in ipa_probe(), the structure is owned by ipa_probe() and released with ipa_interrupt_exit() on its error paths and in ipa_remove(). The error path of ipa_interrupt_config() still frees it with kfree(). If ipa_interrupt_config() fails (called from ipa_config() via ipa_setup()), ipa_probe() unwinds through err_interrupt_exit, which frees the same structure again.

Drop the kfree() from ipa_interrupt_config(); it should only undo what it set up itself. Drop the leftover initialization and cleanup of ipa->interrupt now managed in ipa_proble() and ipa_remove() of ipa_main.c.

Fixes ad1be80d7582 ("net: ipa: introduce ipa_interrupt_init()")

---
v1->v2:
- Drop ipa->interrupt initialization and cleanup.

 drivers/net/ipa/ipa_interrupt.c | 12 ++----------
 1 file changed, 2 insertions(+), 10 deletions(-)
drivers/net/ipa/ipa_interrupt.c +2 -10
index 131b9cc94201..766b094eb069 100644
@@ -260,10 +260,8 @@ int ipa_interrupt_config(struct ipa *ipa)
 	interrupt->enabled = 0;
 	interrupt->suspend_enabled = bitmap_zalloc(ipa->endpoint_count,
 						   GFP_KERNEL);
-	if (!interrupt->suspend_enabled) {
-		ret = -ENOMEM;
-		goto err_kfree;
-	}
+	if (!interrupt->suspend_enabled)
+		return -ENOMEM;
 
 	/* Disable IPA interrupt types */
 	reg = ipa_reg(ipa, IPA_IRQ_EN);
@@ -289,8 +287,6 @@ int ipa_interrupt_config(struct ipa *ipa)
 		goto err_disable_wakeup;
 	}
 
-	ipa->interrupt = interrupt;
-
 	return 0;
 
 err_disable_wakeup:
@@ -299,8 +295,6 @@ int ipa_interrupt_config(struct ipa *ipa)
 	free_irq(interrupt->irq, interrupt);
 err_free_bitmap:
 	bitmap_free(interrupt->suspend_enabled);
-err_kfree:
-	kfree(interrupt);
 
 	return ret;
 }
@@ -311,8 +305,6 @@ void ipa_interrupt_deconfig(struct ipa *ipa)
 	struct ipa_interrupt *interrupt = ipa->interrupt;
 	struct device *dev = ipa->dev;
 
-	ipa->interrupt = NULL;
-
 	dev_pm_clear_wake_irq(dev);
 	(void)device_init_wakeup(dev, false);
 	free_irq(interrupt->irq, interrupt);
Signature · 1 line
2.53.0
#1 lore raw
This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:

Hi!

This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:

- How the issue was discovered, e.g. hit in production, hit during development, syzbot report, manual code inspection, LLM or static analysis tool scan.

- Whether the issue was actually triggered, or is only theoretical (e.g. found by code inspection). If it was triggered please include the symptoms, like the stack trace or error messages.

Please do not repost the series just to address the above. Instead, reply to this email with the missing information, so that reviewers can take it into account. If the series needs another revision for other reasons, please include the information in the commit messages then.

The evaluation is done by an LLM so it may be wrong, if you think that is the case please reply and explain.

Reviewed-by on v2 1/1
#2 lore raw
In reply to Thomas Fourier
Quoted 8 lines · Thomas Fourier

Since ipa_interrupt_init() allocates struct ipa_interrupt in ipa_probe(), the structure is owned by ipa_probe() and released with ipa_interrupt_exit() on its error paths and in ipa_remove(). The error path of ipa_interrupt_config() still frees it with kfree(). If ipa_interrupt_config() fails (called from ipa_config() via ipa_setup()), ipa_probe() unwinds through err_interrupt_exit, which frees the same structure again.

Quoted 6 lines

Drop the kfree() from ipa_interrupt_config(); it should only undo what it set up itself. Drop the leftover initialization and cleanup of ipa->interrupt now managed in ipa_proble() and ipa_remove() of ipa_main.c.

Fixes ad1be80d7582 ("net: ipa: introduce ipa_interrupt_init()")

You should respond to the netdev-bot message asking for a better explanation of how this was found and whether it was observed or just found by inspection.

However I think this version does look good.

Quoted 51 lines

---
v1->v2:
- Drop ipa->interrupt initialization and cleanup.

  drivers/net/ipa/ipa_interrupt.c | 12 ++----------
  1 file changed, 2 insertions(+), 10 deletions(-)
drivers/net/ipa/ipa_interrupt.c +2 -10
index 131b9cc94201..766b094eb069 100644
@@ -260,10 +260,8 @@ int ipa_interrupt_config(struct ipa *ipa)
  	interrupt->enabled = 0;
  	interrupt->suspend_enabled = bitmap_zalloc(ipa->endpoint_count,
  						   GFP_KERNEL);
-	if (!interrupt->suspend_enabled) {
-		ret = -ENOMEM;
-		goto err_kfree;
-	}
+	if (!interrupt->suspend_enabled)
+		return -ENOMEM;
 
  	/* Disable IPA interrupt types */
  	reg = ipa_reg(ipa, IPA_IRQ_EN);
@@ -289,8 +287,6 @@ int ipa_interrupt_config(struct ipa *ipa)
  		goto err_disable_wakeup;
  	}
 
-	ipa->interrupt = interrupt;
-
  	return 0;
 
  err_disable_wakeup:
@@ -299,8 +295,6 @@ int ipa_interrupt_config(struct ipa *ipa)
  	free_irq(interrupt->irq, interrupt);
  err_free_bitmap:
  	bitmap_free(interrupt->suspend_enabled);
-err_kfree:
-	kfree(interrupt);
 
  	return ret;
  }
@@ -311,8 +305,6 @@ void ipa_interrupt_deconfig(struct ipa *ipa)
  	struct ipa_interrupt *interrupt = ipa->interrupt;
  	struct device *dev = ipa->dev;
 
-	ipa->interrupt = NULL;
-
  	dev_pm_clear_wake_irq(dev);
  	(void)device_init_wakeup(dev, false);
  	free_irq(interrupt->irq, interrupt);
#3 lore raw
In reply to Thomas Fourier
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:

Quoted 9 lines · On Thu, 29 Oct 2026 09:20:55 +0100 you wrote:

Since ipa_interrupt_init() allocates struct ipa_interrupt in ipa_probe(), the structure is owned by ipa_probe() and released with ipa_interrupt_exit() on its error paths and in ipa_remove(). The error path of ipa_interrupt_config() still frees it with kfree(). If ipa_interrupt_config() fails (called from ipa_config() via ipa_setup()), ipa_probe() unwinds through err_interrupt_exit, which frees the same structure again.

[...]

Here is the summary with links:
- [net,v2] net: ipa: Fix double free of the interrupt structure on config error

    https://git.kernel.org/netdev/net/c/cb284914e749

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html