Skip to contentSkip to conversation

EDAC/fsl_ddr: use non devm for request_irq()

PATCH In review Rosen Penev 4 participants 12 messages Jul 29 – Jul 31

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

PATCH 1/1 EDAC/fsl_ddr: use non devm for request_irq()

We need to tear down the irq before edac_mc_free() to avoid a use after free on teardown as request_irq uses mci as dev_id.

---
 drivers/edac/fsl_ddr_edac.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/edac/fsl_ddr_edac.c +2 -1
index f4cc89b26954..f1ddd1f47f2a 100644
@@ -601,7 +601,7 @@ int fsl_mc_err_probe(struct platform_device *op)
 
 		/* register interrupts */
 		pdata->irq = platform_get_irq(op, 0);
-		res = devm_request_irq(&op->dev, pdata->irq,
+		res = request_irq(pdata->irq,
 				       fsl_mc_isr,
 				       IRQF_SHARED,
 				       "[EDAC] MC err", mci);
@@ -639,6 +639,7 @@ void fsl_mc_err_remove(struct platform_device *op)
 
 	if (edac_op_state == EDAC_OPSTATE_INT) {
 		ddr_out32(pdata, FSL_MC_ERR_INT_EN, 0);
+		free_irq(pdata->irq, mci);
 	}
 
 	ddr_out32(pdata, FSL_MC_ERR_DISABLE,
Signature · 1 line
2.55.0
#1 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] Hardware state leak on error path in fsl_mc_err_probe can lead to an interrupt storm. --

--- Patch [1]: [PATCH] EDAC/fsl_ddr: use non devm for request_irq() --- commit 8909bee5f3be8d2142784ef41571cbe3330c5c9a
Author: Rosen Penev <[email protected]>

EDAC/fsl_ddr: use non devm for request_irq()

This commit changes the driver to use request_irq() instead of devm_request_irq() so that the interrupt can be manually torn down before edac_mc_free(), avoiding a use-after-free on teardown.

Quoted 4 lines
drivers/edac/fsl_ddr_edac.c +0 -0
index e4eaec0aa81d5..878d4a86a3c9c 100644

[ ... ]

Quoted 9 lines
drivers/edac/fsl_ddr_edac.c +1 -1
@@ -623,7 +623,7 @@ int fsl_mc_err_probe(struct platform_device *op)
 
 		/* register interrupts */
 		pdata->irq = platform_get_irq(op, 0);
-		res = devm_request_irq(&op->dev, pdata->irq,
+		res = request_irq(pdata->irq,
 				       fsl_mc_isr,
 				       IRQF_SHARED,
 				       "[EDAC] MC err", mci);

drivers/edac/fsl_ddr_edac.c

Quoted 5 lines
drivers/edac/fsl_ddr_edac.c +0 -0
 		if (res < 0) {
 			pr_err("%s: Unable to request irq %d for FSL DDR DRAM ERR\n",
 			       __func__, pdata->irq);
 			res = -ENODEV;
 			goto err2;

[Severity: High]
This is a pre-existing issue, but is it possible for this error path to leave interrupts enabled in the hardware and cause an interrupt storm?

Earlier in fsl_mc_err_probe(), the hardware state is modified by clearing FSL_MC_ERR_DISABLE and enabling interrupts in FSL_MC_ERR_INT_EN. If request_irq() fails here, the goto err2 path cleans up the software state with edac_mc_del_mc() and edac_mc_free(), but it does not appear to revert these hardware registers.

Since the interrupt is requested with IRQF_SHARED, an unhandled interrupt storm from this device could cause the kernel IRQ core to permanently disable the shared IRQ line, potentially creating a denial of service for other devices sharing it.

This path could easily be hit if platform_get_irq() returns -EPROBE_DEFER, since its return value is not explicitly checked for errors before being passed directly to request_irq().

Should the err2 path restore FSL_MC_ERR_DISABLE and disable FSL_MC_ERR_INT_EN before returning?

[ ... ]

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#2 lore raw
In reply to Rosen Penev
Quoted 22 lines · Rosen Penev

We need to tear down the irq before edac_mc_free() to avoid a use after free on teardown as request_irq uses mci as dev_id.

---
 drivers/edac/fsl_ddr_edac.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/edac/fsl_ddr_edac.c +1 -1
index f4cc89b26954..f1ddd1f47f2a 100644
@@ -601,7 +601,7 @@ int fsl_mc_err_probe(struct platform_device *op)
 
 		/* register interrupts */
 		pdata->irq = platform_get_irq(op, 0);
-		res = devm_request_irq(&op->dev, pdata->irq,
+		res = request_irq(pdata->irq,
 				       fsl_mc_isr,
 				       IRQF_SHARED,
 				       "[EDAC] MC err", mci);

drivers/edac/fsl_ddr_edac.c void fsl_mc_err_remove(struct platform_device *op) · line 642

Quoted 4 lines
drivers/edac/fsl_ddr_edac.c +1 -0
@@ -639,6 +639,7 @@ void fsl_mc_err_remove(struct platform_device *op)
 
 	if (edac_op_state == EDAC_OPSTATE_INT) {
 		ddr_out32(pdata, FSL_MC_ERR_INT_EN, 0);
+		free_irq(pdata->irq, mci);

here already disable hardware irq. Just call synchronize_irq() to make sure pending irq handled.

Frank

Quoted 7 lines
drivers/edac/fsl_ddr_edac.c +0 -1
 	}
 
 	ddr_out32(pdata, FSL_MC_ERR_DISABLE,
--

2.55.0

#3 lore raw
Quoted 25 lines · Frank Li
Quoted 23 lines · Rosen Penev

We need to tear down the irq before edac_mc_free() to avoid a use after free on teardown as request_irq uses mci as dev_id.

---
 drivers/edac/fsl_ddr_edac.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/edac/fsl_ddr_edac.c +1 -1
index f4cc89b26954..f1ddd1f47f2a 100644
@@ -601,7 +601,7 @@ int fsl_mc_err_probe(struct platform_device *op)
 
              /* register interrupts */
              pdata->irq = platform_get_irq(op, 0);
-             res = devm_request_irq(&op->dev, pdata->irq,
+             res = request_irq(pdata->irq,
                                     fsl_mc_isr,
                                     IRQF_SHARED,
                                     "[EDAC] MC err", mci);
@@ -639,6 +639,7 @@ void fsl_mc_err_remove(struct platform_device *op)
 
Quoted 6 lines

drivers/edac/fsl_ddr_edac.c void fsl_mc_err_remove(struct platform_device *op) · line 642

Quoted 3 lines
drivers/edac/fsl_ddr_edac.c +1 -0
      if (edac_op_state == EDAC_OPSTATE_INT) {
              ddr_out32(pdata, FSL_MC_ERR_INT_EN, 0);
+             free_irq(pdata->irq, mci);

here already disable hardware irq. Just call synchronize_irq() to make sure pending irq handled.

AI disagrees with this suggestion:

The reviewer's suggestion to just call synchronize_irq() instead of free_irq() is problematic for two reasons:
1. Shared IRQ: The handler is registered with IRQF_SHARED. Disabling the DDR controller's local IRQ output (ddr_out32(..., 0)) prevents this device from asserting the IRQ line, but other devices sharing the same IRQ line can still trigger it. Without free_irq, the handler remains in the shared action list and can be called with a dangling mci pointer after edac_mc_free() — the very UAF this patch aims to fix.
2. free_irq already synchronizes: free_irq() internally calls synchronize_irq() after removing the action from the descriptor. An explicit synchronize_irq() before free_irq() would be redundant.

Quoted 10 lines

Frank

Quoted 7 lines
drivers/edac/fsl_ddr_edac.c +0 -1
      }
 
      ddr_out32(pdata, FSL_MC_ERR_DISABLE,
--

2.55.0

maintainer
#4 lore raw
Quoted 3 lines · Rosen Penev
Quoted 2 lines

here already disable hardware irq. Just call synchronize_irq() to make sure pending irq handled.

AI disagrees with this suggestion:

How about you try to parse what AI says and verify it yourself?

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
#5 lore raw
Quoted 7 lines · Borislav Petkov
Quoted 3 lines · Rosen Penev
Quoted 2 lines

here already disable hardware irq. Just call synchronize_irq() to make sure pending irq handled.

AI disagrees with this suggestion:

How about you try to parse what AI says and verify it yourself?

Makes sense to me.

The alternative is to use devm_add_action_or_reset for edac_mc_free. I'd rather not do that.

Quoted 6 lines

--
Regards/Gruss,
Boris.

https://people.kernel.org/tglx/notes-about-netiquette

#6 lore raw
Quoted 5 lines · Rosen Penev
Quoted 4 lines · Borislav Petkov
Quoted 2 lines · Rosen Penev
Quoted 2 lines

here already disable hardware irq. Just call synchronize_irq() to make sure pending irq handled.

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

AI disagrees with this suggestion:

How about you try to parse what AI says and verify it yourself?

Makes sense to me.

The alternative is to use devm_add_action_or_reset for edac_mc_free. I'd rather not do that.

This one should work, of add devm_edac_add*() version to simplufy probe and beanfit other EDAC driver.

Frank

Quoted 6 lines
Quoted 6 lines

--
Regards/Gruss,
Boris.

https://people.kernel.org/tglx/notes-about-netiquette

#7 lore raw
Quoted 9 lines · Frank Li
Quoted 7 lines · Rosen Penev
Quoted 6 lines · Borislav Petkov
Quoted 3 lines · Rosen Penev
Quoted 2 lines

here already disable hardware irq. Just call synchronize_irq() to make sure pending irq handled.

AI disagrees with this suggestion:

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

How about you try to parse what AI says and verify it yourself?

Makes sense to me.

The alternative is to use devm_add_action_or_reset for edac_mc_free. I'd rather not do that.

This one should work, of add devm_edac_add*() version to simplufy probe and beanfit other EDAC driver.

That's probably appropriate.

Quoted 9 lines

Frank

Quoted 6 lines
Quoted 6 lines

--
Regards/Gruss,
Boris.

https://people.kernel.org/tglx/notes-about-netiquette

#8 lore raw
In reply to Rosen Penev
Quoted 34 lines · Rosen Penev
Quoted 25 lines · Frank Li
Quoted 23 lines · Rosen Penev

We need to tear down the irq before edac_mc_free() to avoid a use after free on teardown as request_irq uses mci as dev_id.

---
 drivers/edac/fsl_ddr_edac.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/edac/fsl_ddr_edac.c +1 -1
index f4cc89b26954..f1ddd1f47f2a 100644
@@ -601,7 +601,7 @@ int fsl_mc_err_probe(struct platform_device *op)
 
              /* register interrupts */
              pdata->irq = platform_get_irq(op, 0);
-             res = devm_request_irq(&op->dev, pdata->irq,
+             res = request_irq(pdata->irq,
                                     fsl_mc_isr,
                                     IRQF_SHARED,
                                     "[EDAC] MC err", mci);
@@ -639,6 +639,7 @@ void fsl_mc_err_remove(struct platform_device *op)
 
Quoted 6 lines

drivers/edac/fsl_ddr_edac.c void fsl_mc_err_remove(struct platform_device *op) · line 642

Quoted 3 lines
drivers/edac/fsl_ddr_edac.c +1 -0
      if (edac_op_state == EDAC_OPSTATE_INT) {
              ddr_out32(pdata, FSL_MC_ERR_INT_EN, 0);
+             free_irq(pdata->irq, mci);

here already disable hardware irq. Just call synchronize_irq() to make sure pending irq handled.

AI disagrees with this suggestion:

Quoted 12 lines

The reviewer's suggestion to just call synchronize_irq() instead of free_irq() is problematic for two reasons:
1. Shared IRQ: The handler is registered with IRQF_SHARED. Disabling the DDR controller's local IRQ output (ddr_out32(..., 0)) prevents this device from asserting the IRQ line, but other devices sharing the same IRQ line can still trigger it. Without free_irq, the handler remains in the shared action list and can be called with a dangling mci pointer after edac_mc_free() — the very UAF this patch aims to fix.
2. free_irq already synchronizes: free_irq() internally calls synchronize_irq() after removing the action from the descriptor. An explicit synchronize_irq() before free_irq() would be redundant.

You post too quick, I have not seen this mail yet.

devm_free_irq() here. and add comment why need explicit call it.

Frank

Quoted 10 lines
Quoted 10 lines

Frank

Quoted 7 lines
drivers/edac/fsl_ddr_edac.c +0 -1
      }
 
      ddr_out32(pdata, FSL_MC_ERR_DISABLE,
--

2.55.0

#9 lore raw
Quoted 49 lines · Frank Li
Quoted 34 lines · Rosen Penev
Quoted 25 lines · Frank Li
Quoted 23 lines · Rosen Penev

We need to tear down the irq before edac_mc_free() to avoid a use after free on teardown as request_irq uses mci as dev_id.

---
 drivers/edac/fsl_ddr_edac.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/edac/fsl_ddr_edac.c +1 -1
index f4cc89b26954..f1ddd1f47f2a 100644
@@ -601,7 +601,7 @@ int fsl_mc_err_probe(struct platform_device *op)
 
              /* register interrupts */
              pdata->irq = platform_get_irq(op, 0);
-             res = devm_request_irq(&op->dev, pdata->irq,
+             res = request_irq(pdata->irq,
                                     fsl_mc_isr,
                                     IRQF_SHARED,
                                     "[EDAC] MC err", mci);
@@ -639,6 +639,7 @@ void fsl_mc_err_remove(struct platform_device *op)
 
Quoted 6 lines

drivers/edac/fsl_ddr_edac.c void fsl_mc_err_remove(struct platform_device *op) · line 642

Quoted 3 lines
drivers/edac/fsl_ddr_edac.c +1 -0
      if (edac_op_state == EDAC_OPSTATE_INT) {
              ddr_out32(pdata, FSL_MC_ERR_INT_EN, 0);
+             free_irq(pdata->irq, mci);

here already disable hardware irq. Just call synchronize_irq() to make sure pending irq handled.

AI disagrees with this suggestion:

Quoted 12 lines

The reviewer's suggestion to just call synchronize_irq() instead of free_irq() is problematic for two reasons:
1. Shared IRQ: The handler is registered with IRQF_SHARED. Disabling the DDR controller's local IRQ output (ddr_out32(..., 0)) prevents this device from asserting the IRQ line, but other devices sharing the same IRQ line can still trigger it. Without free_irq, the handler remains in the shared action list and can be called with a dangling mci pointer after edac_mc_free() — the very UAF this patch aims to fix.
2. free_irq already synchronizes: free_irq() internally calls synchronize_irq() after removing the action from the descriptor. An explicit synchronize_irq() before free_irq() would be redundant.

Quoted 3 lines

You post too quick, I have not seen this mail yet.

devm_free_irq() here. and add comment why need explicit call it.

Needing to explicitly call devm_free_irq kind of defeats the purpose of devm.

Explicit ordering in this case makes more sense to me, especially with the ddr_out32 calls.

There's actually a second benefit to the non devm version. The devm version prints an error message on failure. The normal one does not. The significance is that the driver prints its own message.

Quoted 13 lines

Frank

Quoted 10 lines
Quoted 10 lines

Frank

Quoted 7 lines
drivers/edac/fsl_ddr_edac.c +0 -1
      }
 
      ddr_out32(pdata, FSL_MC_ERR_DISABLE,
--

2.55.0

#10 lore raw
Quoted 53 lines · Rosen Penev
Quoted 49 lines · Frank Li
Quoted 34 lines · Rosen Penev
Quoted 25 lines · Frank Li
Quoted 23 lines · Rosen Penev

We need to tear down the irq before edac_mc_free() to avoid a use after free on teardown as request_irq uses mci as dev_id.

---
 drivers/edac/fsl_ddr_edac.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/edac/fsl_ddr_edac.c +1 -1
index f4cc89b26954..f1ddd1f47f2a 100644
@@ -601,7 +601,7 @@ int fsl_mc_err_probe(struct platform_device *op)
 
              /* register interrupts */
              pdata->irq = platform_get_irq(op, 0);
-             res = devm_request_irq(&op->dev, pdata->irq,
+             res = request_irq(pdata->irq,
                                     fsl_mc_isr,
                                     IRQF_SHARED,
                                     "[EDAC] MC err", mci);
@@ -639,6 +639,7 @@ void fsl_mc_err_remove(struct platform_device *op)
 
Quoted 6 lines

drivers/edac/fsl_ddr_edac.c void fsl_mc_err_remove(struct platform_device *op) · line 642

Quoted 3 lines
drivers/edac/fsl_ddr_edac.c +1 -0
      if (edac_op_state == EDAC_OPSTATE_INT) {
              ddr_out32(pdata, FSL_MC_ERR_INT_EN, 0);
+             free_irq(pdata->irq, mci);

here already disable hardware irq. Just call synchronize_irq() to make sure pending irq handled.

AI disagrees with this suggestion:

Quoted 12 lines

The reviewer's suggestion to just call synchronize_irq() instead of free_irq() is problematic for two reasons:
1. Shared IRQ: The handler is registered with IRQF_SHARED. Disabling the DDR controller's local IRQ output (ddr_out32(..., 0)) prevents this device from asserting the IRQ line, but other devices sharing the same IRQ line can still trigger it. Without free_irq, the handler remains in the shared action list and can be called with a dangling mci pointer after edac_mc_free() — the very UAF this patch aims to fix.
2. free_irq already synchronizes: free_irq() internally calls synchronize_irq() after removing the action from the descriptor. An explicit synchronize_irq() before free_irq() would be redundant.

Quoted 3 lines

You post too quick, I have not seen this mail yet.

devm_free_irq() here. and add comment why need explicit call it.

Quoted 8 lines

Needing to explicitly call devm_free_irq kind of defeats the purpose of devm.

Explicit ordering in this case makes more sense to me, especially with the ddr_out32 calls.

There's actually a second benefit to the non devm version. The devm version prints an error message on failure. The normal one does not. The significance is that the driver prints its own message.

It may need goto if add logic after request_irq(), I want to make probe code clean enough.

Error message doesn't mattter, we can remove it.

I suggest use other method, let use devm add action to make free irq before free mci.

Frank

Quoted 13 lines
Quoted 13 lines

Frank

Quoted 10 lines
Quoted 10 lines

Frank

Quoted 7 lines
drivers/edac/fsl_ddr_edac.c +0 -1
      }
 
      ddr_out32(pdata, FSL_MC_ERR_DISABLE,
--

2.55.0

#11 lore raw
Quoted 64 lines · Frank Li
Quoted 53 lines · Rosen Penev
Quoted 49 lines · Frank Li
Quoted 34 lines · Rosen Penev
Quoted 25 lines · Frank Li
Quoted 23 lines · Rosen Penev

We need to tear down the irq before edac_mc_free() to avoid a use after free on teardown as request_irq uses mci as dev_id.

---
 drivers/edac/fsl_ddr_edac.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/edac/fsl_ddr_edac.c +1 -1
index f4cc89b26954..f1ddd1f47f2a 100644
@@ -601,7 +601,7 @@ int fsl_mc_err_probe(struct platform_device *op)
 
              /* register interrupts */
              pdata->irq = platform_get_irq(op, 0);
-             res = devm_request_irq(&op->dev, pdata->irq,
+             res = request_irq(pdata->irq,
                                     fsl_mc_isr,
                                     IRQF_SHARED,
                                     "[EDAC] MC err", mci);
@@ -639,6 +639,7 @@ void fsl_mc_err_remove(struct platform_device *op)
 
Quoted 6 lines

drivers/edac/fsl_ddr_edac.c void fsl_mc_err_remove(struct platform_device *op) · line 642

Quoted 3 lines
drivers/edac/fsl_ddr_edac.c +1 -0
      if (edac_op_state == EDAC_OPSTATE_INT) {
              ddr_out32(pdata, FSL_MC_ERR_INT_EN, 0);
+             free_irq(pdata->irq, mci);

here already disable hardware irq. Just call synchronize_irq() to make sure pending irq handled.

AI disagrees with this suggestion:

Quoted 12 lines

The reviewer's suggestion to just call synchronize_irq() instead of free_irq() is problematic for two reasons:
1. Shared IRQ: The handler is registered with IRQF_SHARED. Disabling the DDR controller's local IRQ output (ddr_out32(..., 0)) prevents this device from asserting the IRQ line, but other devices sharing the same IRQ line can still trigger it. Without free_irq, the handler remains in the shared action list and can be called with a dangling mci pointer after edac_mc_free() — the very UAF this patch aims to fix.
2. free_irq already synchronizes: free_irq() internally calls synchronize_irq() after removing the action from the descriptor. An explicit synchronize_irq() before free_irq() would be redundant.

Quoted 3 lines

You post too quick, I have not seen this mail yet.

devm_free_irq() here. and add comment why need explicit call it.

Quoted 8 lines

Needing to explicitly call devm_free_irq kind of defeats the purpose of devm.

Explicit ordering in this case makes more sense to me, especially with the ddr_out32 calls.

There's actually a second benefit to the non devm version. The devm version prints an error message on failure. The normal one does not. The significance is that the driver prints its own message.

Quoted 7 lines

It may need goto if add logic after request_irq(), I want to make probe code clean enough.

Error message doesn't mattter, we can remove it.

I suggest use other method, let use devm add action to make free irq before free mci.

ACK. A couple of other drivers suffer from the same issue.

Quoted 16 lines

Frank

Quoted 13 lines
Quoted 13 lines

Frank

Quoted 10 lines
Quoted 10 lines

Frank

Quoted 7 lines
drivers/edac/fsl_ddr_edac.c +0 -1
      }
 
      ddr_out32(pdata, FSL_MC_ERR_DISABLE,
--

2.55.0