Skip to contentSkip to conversation

net: ibm: emac: Fix NULL pointer dereference in emac_probe

PATCH Superseded Rosen Penev 2 participants 5 messages May 31

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: ibm: emac: Fix NULL pointer dereference in emac_probe

Move devm_request_irq() after devm_platform_ioremap_resource() so that dev->emacp is mapped before the interrupt handler can fire. An early interrupt hitting emac_irq() would dereference the NULL dev->emacp and crash.

Fixes dcc34ef7c834 ("net: ibm: emac: manage emac_irq with devm")
Assisted-by Opencode:Big-Pickle
---
 drivers/net/ethernet/ibm/emac/core.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/net/ethernet/ibm/emac/core.c +7 -7
index b060795dace7..3e8ea0b05619 100644
@@ -3044,6 +3044,13 @@ static int emac_probe(struct platform_device *ofdev)
 	if (err)
 		goto err_gone;
 
+	dev->emacp = devm_platform_ioremap_resource(ofdev, 0);
+	if (IS_ERR(dev->emacp)) {
+		dev_err(&ofdev->dev, "can't map device registers");
+		err = PTR_ERR(dev->emacp);
+		goto err_gone;
+	}
+
 	/* Setup error IRQ handler */
 	dev->emac_irq = platform_get_irq(ofdev, 0);
 	err = devm_request_irq(&ofdev->dev, dev->emac_irq, emac_irq, 0, "EMAC",
@@ -3056,13 +3063,6 @@ static int emac_probe(struct platform_device *ofdev)
 
 	ndev->irq = dev->emac_irq;
 
-	dev->emacp = devm_platform_ioremap_resource(ofdev, 0);
-	if (IS_ERR(dev->emacp)) {
-		dev_err(&ofdev->dev, "can't map device registers");
-		err = PTR_ERR(dev->emacp);
-		goto err_gone;
-	}
-
 	/* Wait for dependent devices */
 	err = emac_wait_deps(dev);
 	if (err)

--
2.54.0

#1 lore raw
Quoted 4 lines · Rosen Penev

Move devm_request_irq() after devm_platform_ioremap_resource() so that dev->emacp is mapped before the interrupt handler can fire. An early interrupt hitting emac_irq() would dereference the NULL dev->emacp and crash.

Please add an explanation how this can happen, given that iser is written in open() not probe().

Quoted 1 line
Fixes dcc34ef7c834 ("net: ibm: emac: manage emac_irq with devm")

Is this actually bothering people?

Andrew

#2 lore raw
Quoted 9 lines · Andrew Lunn
Quoted 4 lines · Rosen Penev

Move devm_request_irq() after devm_platform_ioremap_resource() so that dev->emacp is mapped before the interrupt handler can fire. An early interrupt hitting emac_irq() would dereference the NULL dev->emacp and crash.

Please add an explanation how this can happen, given that iser is written in open() not probe().

https://sashiko.dev/#/patchset/20260517033621.1839397-1-rosenp%40gmail.com

Also, does requesting the hardware interrupt before mapping the device I/O registers create a NULL pointer dereference regression in emac_probe()? The hardware interrupt is requested and enabled via devm_request_irq() before the device I/O registers are mapped via devm_platform_ioremap_resource().
If an interrupt is asserted early, emac_irq() will execute immediately and attempt to read the ISR register by dereferencing dev->emacp. Since dev->emacp is still NULL at this point, this would cause a kernel panic.

Quoted 2 lines
Quoted 2 lines
Fixes dcc34ef7c834 ("net: ibm: emac: manage emac_irq with devm")

This is mine btw.

Quoted 2 lines

Is this actually bothering people?

It's bothering the bot. The problem here is any other commit will also trigger this nonsense. Having devm_platform_ioremap_resource earlier like this is more consistent with other drivers as well.

Quoted 2 lines

Andrew

#3 lore raw
Quoted 12 lines · Rosen Penev
Quoted 9 lines · Andrew Lunn
Quoted 4 lines · Rosen Penev

Move devm_request_irq() after devm_platform_ioremap_resource() so that dev->emacp is mapped before the interrupt handler can fire. An early interrupt hitting emac_irq() would dereference the NULL dev->emacp and crash.

Please add an explanation how this can happen, given that iser is written in open() not probe().

https://sashiko.dev/#/patchset/20260517033621.1839397-1-rosenp%40gmail.com

Quoted 8 lines

Also, does requesting the hardware interrupt before mapping the device I/O registers create a NULL pointer dereference regression in emac_probe()? The hardware interrupt is requested and enabled via devm_request_irq() before the device I/O registers are mapped via devm_platform_ioremap_resource().
If an interrupt is asserted early, emac_irq() will execute immediately and attempt to read the ISR register by dereferencing dev->emacp. Since dev->emacp is still NULL at this point, this would cause a kernel panic.

You have still not explained how an interrupt could happen before the interrupts are enabled by writing to the iser in open(). I don't care too much what the AI says, i want a human to explain how this can happen. You have put your Signed-off-by: here, so it is down to you to explain your patch, even is AI told you to do this, and you blindly did it.

Quoted 2 lines

Having devm_platform_ioremap_resource earlier like this is more consistent with other drivers as well.

So maybe this is a better thing to put in the commit message, rather than something you cannot actually explain?

Andrew

#4 lore raw
Quoted 23 lines · Andrew Lunn
Quoted 12 lines · Rosen Penev
Quoted 9 lines · Andrew Lunn
Quoted 4 lines · Rosen Penev

Move devm_request_irq() after devm_platform_ioremap_resource() so that dev->emacp is mapped before the interrupt handler can fire. An early interrupt hitting emac_irq() would dereference the NULL dev->emacp and crash.

Please add an explanation how this can happen, given that iser is written in open() not probe().

https://sashiko.dev/#/patchset/20260517033621.1839397-1-rosenp%40gmail.com

Quoted 8 lines

Also, does requesting the hardware interrupt before mapping the device I/O registers create a NULL pointer dereference regression in emac_probe()? The hardware interrupt is requested and enabled via devm_request_irq() before the device I/O registers are mapped via devm_platform_ioremap_resource().
If an interrupt is asserted early, emac_irq() will execute immediately and attempt to read the ISR register by dereferencing dev->emacp. Since dev->emacp is still NULL at this point, this would cause a kernel panic.

Quoted 6 lines

You have still not explained how an interrupt could happen before the interrupts are enabled by writing to the iser in open(). I don't care too much what the AI says, i want a human to explain how this can happen. You have put your Signed-off-by: here, so it is down to you to explain your patch, even is AI told you to do this, and you blindly did it.

Beats me. When I did the devm conversions, I tested the hardware to make sure it comes up and is usable. Various probe ordering tests were not done.

FWIW, the AI is probably correct. How correct it is is beyond my pay grade.

Quoted 6 lines
Quoted 3 lines

Having devm_platform_ioremap_resource earlier like this is more consistent with other drivers as well.

So maybe this is a better thing to put in the commit message, rather than something you cannot actually explain?

Sure. Although this patch is targeted towards net, not net-next. Just saying it's more consistent will get a flat out rejection.

Quoted 2 lines

Andrew