Skip to contentSkip to conversation

drm: mxsfb: Fix NULL pointer dereference crash on unload

PATCH Applied Marek Vasut 3 participants 6 messages Sep 7, 2021 – Oct 19, 2021

Subsystems (4)
lore
Share & tools
lore

Marek Vasut

author maintainer
#0 lore raw

PATCH 1/1 drm: mxsfb: Fix NULL pointer dereference crash on unload

The mxsfb->crtc.funcs may already be NULL when unloading the driver, in which case calling mxsfb_irq_disable() via drm_irq_uninstall() from mxsfb_unload() leads to NULL pointer dereference.

Since all we care about is masking the IRQ and mxsfb->base is still valid, just use that to clear and mask the IRQ.

Fixes ae1ed00932819 ("drm: mxsfb: Stop using DRM simple display pipeline helper")
Cc Daniel Abrecht <[email protected]>
Cc Emil Velikov <[email protected]>
Cc Laurent Pinchart <[email protected]>
Cc Sam Ravnborg <[email protected]>
Cc Stefan Agner <[email protected]>
---
 drivers/gpu/drm/mxsfb/mxsfb_drv.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/gpu/drm/mxsfb/mxsfb_drv.c +5 -1
index ec0432fe1bdf8..86d78634a9799 100644
@@ -173,7 +173,11 @@ static void mxsfb_irq_disable(struct drm_device *drm)
 	struct mxsfb_drm_private *mxsfb = drm->dev_private;
 
 	mxsfb_enable_axi_clk(mxsfb);
-	mxsfb->crtc.funcs->disable_vblank(&mxsfb->crtc);
+
+	/* Disable and clear VBLANK IRQ */
+	writel(CTRL1_CUR_FRAME_DONE_IRQ_EN, mxsfb->base + LCDC_CTRL1 + REG_CLR);
+	writel(CTRL1_CUR_FRAME_DONE_IRQ, mxsfb->base + LCDC_CTRL1 + REG_CLR);
+
 	mxsfb_disable_axi_clk(mxsfb);
 }
 
Signature · 1 line
2.33.0
#1 lore raw
Quoted 7 lines · Marek Vasut

The mxsfb->crtc.funcs may already be NULL when unloading the driver, in which case calling mxsfb_irq_disable() via drm_irq_uninstall() from mxsfb_unload() leads to NULL pointer dereference.

Since all we care about is masking the IRQ and mxsfb->base is still valid, just use that to clear and mask the IRQ.

Quoted 7 lines
Fixes ae1ed00932819 ("drm: mxsfb: Stop using DRM simple display pipeline helper")
Cc Daniel Abrecht <[email protected]>
Cc Emil Velikov <[email protected]>
Cc Laurent Pinchart <[email protected]>
Cc Sam Ravnborg <[email protected]>
Cc Stefan Agner <[email protected]>

You probably want a drm_atomic_helper_shutdown instead of trying to do all that manually. We've also added a bunch more devm and drmm_ functions to automate the cleanup a lot more here, e.g. your drm_mode_config_cleanup is in the wrong place.

Also I'm confused because I'm not even seeing this function anywhere in upstream.
-Daniel

Quoted 24 lines
---
 drivers/gpu/drm/mxsfb/mxsfb_drv.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/gpu/drm/mxsfb/mxsfb_drv.c +5 -1
index ec0432fe1bdf8..86d78634a9799 100644
@@ -173,7 +173,11 @@ static void mxsfb_irq_disable(struct drm_device *drm)
 	struct mxsfb_drm_private *mxsfb = drm->dev_private;
 
 	mxsfb_enable_axi_clk(mxsfb);
-	mxsfb->crtc.funcs->disable_vblank(&mxsfb->crtc);
+
+	/* Disable and clear VBLANK IRQ */
+	writel(CTRL1_CUR_FRAME_DONE_IRQ_EN, mxsfb->base + LCDC_CTRL1 + REG_CLR);
+	writel(CTRL1_CUR_FRAME_DONE_IRQ, mxsfb->base + LCDC_CTRL1 + REG_CLR);
+
 	mxsfb_disable_axi_clk(mxsfb);
 }
 
Signature · 1 line
2.33.0
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
author maintainer
#2 lore raw
Quoted 16 lines · Daniel Vetter
Quoted 7 lines · Marek Vasut

The mxsfb->crtc.funcs may already be NULL when unloading the driver, in which case calling mxsfb_irq_disable() via drm_irq_uninstall() from mxsfb_unload() leads to NULL pointer dereference.

Since all we care about is masking the IRQ and mxsfb->base is still valid, just use that to clear and mask the IRQ.

Quoted 7 lines
Fixes ae1ed00932819 ("drm: mxsfb: Stop using DRM simple display pipeline helper")
Cc Daniel Abrecht <[email protected]>
Cc Emil Velikov <[email protected]>
Cc Laurent Pinchart <[email protected]>
Cc Sam Ravnborg <[email protected]>
Cc Stefan Agner <[email protected]>
Quoted 7 lines

You probably want a drm_atomic_helper_shutdown instead of trying to do all that manually. We've also added a bunch more devm and drmm_ functions to automate the cleanup a lot more here, e.g. your drm_mode_config_cleanup is in the wrong place.

Also I'm confused because I'm not even seeing this function anywhere in upstream.

It is still here:
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/tree/drivers/gpu/drm/mxsfb/mxsfb_drv.c#n171
as of:
999569d59a0aa ("Add linux-next specific files for 20210908")

Is there some other tree I should be looking at ?

Applied
#3 lore raw
In reply to Daniel Vetter

Hi Marek,

Quoted 16 lines · Daniel Vetter
Quoted 7 lines · Marek Vasut

The mxsfb->crtc.funcs may already be NULL when unloading the driver, in which case calling mxsfb_irq_disable() via drm_irq_uninstall() from mxsfb_unload() leads to NULL pointer dereference.

Since all we care about is masking the IRQ and mxsfb->base is still valid, just use that to clear and mask the IRQ.

Quoted 7 lines
Fixes ae1ed00932819 ("drm: mxsfb: Stop using DRM simple display pipeline helper")
Cc Daniel Abrecht <[email protected]>
Cc Emil Velikov <[email protected]>
Cc Laurent Pinchart <[email protected]>
Cc Sam Ravnborg <[email protected]>
Cc Stefan Agner <[email protected]>
Quoted 4 lines

You probably want a drm_atomic_helper_shutdown instead of trying to do all that manually. We've also added a bunch more devm and drmm_ functions to automate the cleanup a lot more here, e.g. your drm_mode_config_cleanup is in the wrong place.

I have applied v2 of this patch today - but failed to see any response in v2 to this comment from Daniel. Was it lost somehow?

Sam

author maintainer
#4 lore raw
Quoted 19 lines · Sam Ravnborg

Hi Marek,

Quoted 16 lines · Daniel Vetter
Quoted 14 lines · Marek Vasut

The mxsfb->crtc.funcs may already be NULL when unloading the driver, in which case calling mxsfb_irq_disable() via drm_irq_uninstall() from mxsfb_unload() leads to NULL pointer dereference.

Since all we care about is masking the IRQ and mxsfb->base is still valid, just use that to clear and mask the IRQ.

Fixes ae1ed00932819 ("drm: mxsfb: Stop using DRM simple display pipeline helper")
Cc Daniel Abrecht <[email protected]>
Cc Emil Velikov <[email protected]>
Cc Laurent Pinchart <[email protected]>
Cc Sam Ravnborg <[email protected]>
Cc Stefan Agner <[email protected]>
Quoted 7 lines
Quoted 4 lines

You probably want a drm_atomic_helper_shutdown instead of trying to do all that manually. We've also added a bunch more devm and drmm_ functions to automate the cleanup a lot more here, e.g. your drm_mode_config_cleanup is in the wrong place.

I have applied v2 of this patch today - but failed to see any response in v2 to this comment from Daniel. Was it lost somehow?

Hmmm, I'll investigate that ^ in the next round of mxsfb clean ups.

#5 lore raw
Quoted 26 lines · Marek Vasut
Quoted 24 lines · Sam Ravnborg

Hi Marek,

Quoted 20 lines · Daniel Vetter
Quoted 7 lines · Marek Vasut

The mxsfb->crtc.funcs may already be NULL when unloading the driver, in which case calling mxsfb_irq_disable() via drm_irq_uninstall() from mxsfb_unload() leads to NULL pointer dereference.

Since all we care about is masking the IRQ and mxsfb->base is still valid, just use that to clear and mask the IRQ.

Quoted 7 lines
Fixes ae1ed00932819 ("drm: mxsfb: Stop using DRM simple display pipeline helper")
Cc Daniel Abrecht <[email protected]>
Cc Emil Velikov <[email protected]>
Cc Laurent Pinchart <[email protected]>
Cc Sam Ravnborg <[email protected]>
Cc Stefan Agner <[email protected]>

You probably want a drm_atomic_helper_shutdown instead of trying to do all that manually. We've also added a bunch more devm and drmm_ functions to automate the cleanup a lot more here, e.g. your drm_mode_config_cleanup is in the wrong place.

Quoted 4 lines
Quoted 2 lines

I have applied v2 of this patch today - but failed to see any response in v2 to this comment from Daniel. Was it lost somehow?

Hmmm, I'll investigate that ^ in the next round of mxsfb clean ups.

Yeah this was just a quick comment about how to do this cleanly, not meant to hold up a bugfix or anything like that.
-Daniel

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch