dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drm/stm: Fix potential use-after-free of pending IRQ threads
@ 2026-12-03 11:58 Guangshuo Li
  2026-12-03 12:25 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Guangshuo Li @ 2026-12-03 11:58 UTC (permalink / raw)
  To: yannick.fertre, raphael.gallais-pou, philippe.cornu,
	maarten.lankhorst, mripard, tzimmermann, airlied, simona,
	mcoquelin.stm32, alexandre.torgue
  Cc: eric, neil.armstrong, dri-devel, linux-stm32, linux-arm-kernel

Disabling the LTDC interrupt source during removal does not wait for
an already awakened IRQ thread. The thread can still access the DRM
device and its managed data after stm_drm_platform_remove() drops the
last device reference.

Release the managed IRQs in ltdc_unload() before the DRM device is put.

Fixes: b759012c5fa7 ("drm/stm: Add STM32 LTDC driver")
Signed-off-by: Guangshuo Li <liguangshuo@mail.sdu.edu.cn>
---
 drivers/gpu/drm/stm/ltdc.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/drivers/gpu/drm/stm/ltdc.c b/drivers/gpu/drm/stm/ltdc.c
index 5311e0b3e8dc..35aa33f4c459 100644
--- a/drivers/gpu/drm/stm/ltdc.c
+++ b/drivers/gpu/drm/stm/ltdc.c
@@ -2103,8 +2103,15 @@ int ltdc_load(struct drm_device *ddev)
 
 void ltdc_unload(struct drm_device *ddev)
 {
+	struct platform_device *pdev = to_platform_device(ddev->dev);
+	struct ltdc_device *ldev = ddev->dev_private;
+	int i;
+
 	drm_dbg_driver(ddev, "\n");
 
+	for (i = 0; i < ldev->caps.nb_irq; i++)
+		devm_free_irq(ddev->dev, platform_get_irq(pdev, i), ddev);
+
 	pm_runtime_disable(ddev->dev);
 }
 

base-commit: d06ce6f1eb5eeffd4ebcfde345dc34a98131d106
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] drm/stm: Fix potential use-after-free of pending IRQ threads
  2026-12-03 11:58 [PATCH] drm/stm: Fix potential use-after-free of pending IRQ threads Guangshuo Li
@ 2026-12-03 12:25 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-12-03 12:25 UTC (permalink / raw)
  To: Guangshuo Li; +Cc: dri-devel

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] drm/stm: unchecked platform_get_irq() return in ltdc_unload()
--

commit 2451ff1129bd735ee3883ed5b8e4057603299d2b
Author: Guangshuo Li <liguangshuo@mail.sdu.edu.cn>

drm/stm: Fix potential use-after-free of pending IRQ threads

This commit frees the managed LTDC IRQs in ltdc_unload() before
pm_runtime_disable() so pending IRQ threads complete before the DRM device is
released.

> diff --git a/drivers/gpu/drm/stm/ltdc.c b/drivers/gpu/drm/stm/ltdc.c
> index 5311e0b3e8dcd..35aa33f4c4593 100644
> --- a/drivers/gpu/drm/stm/ltdc.c
> +++ b/drivers/gpu/drm/stm/ltdc.c
> @@ -2103,8 +2103,15 @@ int ltdc_load(struct drm_device *ddev)
>  
>  void ltdc_unload(struct drm_device *ddev)
>  {
> +	struct platform_device *pdev = to_platform_device(ddev->dev);
> +	struct ltdc_device *ldev = ddev->dev_private;
> +	int i;
> +
>  	drm_dbg_driver(ddev, "\n");
>  
> +	for (i = 0; i < ldev->caps.nb_irq; i++)
> +		devm_free_irq(ddev->dev, platform_get_irq(pdev, i), ddev);

[Severity: Medium]
Can platform_get_irq() fail here and pass a negative errno to devm_free_irq()?

When removing a DT overlay, of_overlay_remove() reverts the overlay properties
before of_platform_device_destroy() runs ltdc_unload(). Because OF platform
devices re-parse the interrupts property in platform_get_irq(), it fails with
-ENXIO and calls the probe-only helper dev_err_probe().

Passing that negative value as an unsigned int to devm_free_irq() triggers
WARN_ON() in devres_release() and leaves the registered IRQ active across
drm_dev_put(ddev), re-exposing the ltdc_irq_thread() use-after-free.

Saving the IRQ numbers in struct ltdc_device during ltdc_load() and freeing
those saved values in ltdc_unload() avoids re-querying the device tree during
teardown.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261203115854.2319339-1-liguangshuo@mail.sdu.edu.cn?part=1

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-12-03 12:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03 11:58 [PATCH] drm/stm: Fix potential use-after-free of pending IRQ threads Guangshuo Li
2026-12-03 12:25 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox