* [PATCH v3] drm/panthor: Fix UAF race between device unplug and FW event processing
@ 2025-10-27 14:02 Ketil Johnsen
2025-10-27 14:31 ` Boris Brezillon
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Ketil Johnsen @ 2025-10-27 14:02 UTC (permalink / raw)
To: Boris Brezillon, Steven Price, Liviu Dudau, Maarten Lankhorst,
Maxime Ripard, Thomas Zimmermann, David Airlie, Simona Vetter,
Heiko Stuebner
Cc: Ketil Johnsen, dri-devel, linux-kernel
The function panthor_fw_unplug() will free the FW memory sections.
The problem is that there could still be pending FW events which are yet
not handled at this point. process_fw_events_work() can in this case try
to access said freed memory.
Simply call disable_work_sync() to both drain and prevent future
invocation of process_fw_events_work().
Signed-off-by: Ketil Johnsen <ketil.johnsen@arm.com>
Fixes: de85488138247 ("drm/panthor: Add the scheduler logical block")
---
v2:
- Followed Boris's advice and handle the race purely within the
scheduler block (by adding a destroyed state)
v3:
- New approach, one single call to disable_work_sync()
---
drivers/gpu/drm/panthor/panthor_sched.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/gpu/drm/panthor/panthor_sched.c b/drivers/gpu/drm/panthor/panthor_sched.c
index 0cc9055f4ee52..b7595beaa0205 100644
--- a/drivers/gpu/drm/panthor/panthor_sched.c
+++ b/drivers/gpu/drm/panthor/panthor_sched.c
@@ -3880,6 +3880,7 @@ void panthor_sched_unplug(struct panthor_device *ptdev)
struct panthor_scheduler *sched = ptdev->scheduler;
cancel_delayed_work_sync(&sched->tick_work);
+ disable_work_sync(&sched->fw_events_work);
mutex_lock(&sched->lock);
if (sched->pm.has_ref) {
--
2.47.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v3] drm/panthor: Fix UAF race between device unplug and FW event processing
2025-10-27 14:02 [PATCH v3] drm/panthor: Fix UAF race between device unplug and FW event processing Ketil Johnsen
@ 2025-10-27 14:31 ` Boris Brezillon
2025-11-03 12:12 ` Liviu Dudau
2025-11-03 14:38 ` Liviu Dudau
2 siblings, 0 replies; 4+ messages in thread
From: Boris Brezillon @ 2025-10-27 14:31 UTC (permalink / raw)
To: Ketil Johnsen
Cc: Steven Price, Liviu Dudau, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, David Airlie, Simona Vetter, Heiko Stuebner,
dri-devel, linux-kernel
On Mon, 27 Oct 2025 15:02:15 +0100
Ketil Johnsen <ketil.johnsen@arm.com> wrote:
> The function panthor_fw_unplug() will free the FW memory sections.
> The problem is that there could still be pending FW events which are yet
> not handled at this point. process_fw_events_work() can in this case try
> to access said freed memory.
>
> Simply call disable_work_sync() to both drain and prevent future
> invocation of process_fw_events_work().
>
> Signed-off-by: Ketil Johnsen <ketil.johnsen@arm.com>
> Fixes: de85488138247 ("drm/panthor: Add the scheduler logical block")
Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
Would you mind sending a patch on top of this one turning all
cancel_[delayed_]work_sync() happening in the unplug path int
disable_[delayed_]work_sync(), so we're sure we won't face other "work
in queued after being cancelled" issues in the future.
> ---
> v2:
> - Followed Boris's advice and handle the race purely within the
> scheduler block (by adding a destroyed state)
>
> v3:
> - New approach, one single call to disable_work_sync()
> ---
> drivers/gpu/drm/panthor/panthor_sched.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/gpu/drm/panthor/panthor_sched.c b/drivers/gpu/drm/panthor/panthor_sched.c
> index 0cc9055f4ee52..b7595beaa0205 100644
> --- a/drivers/gpu/drm/panthor/panthor_sched.c
> +++ b/drivers/gpu/drm/panthor/panthor_sched.c
> @@ -3880,6 +3880,7 @@ void panthor_sched_unplug(struct panthor_device *ptdev)
> struct panthor_scheduler *sched = ptdev->scheduler;
>
> cancel_delayed_work_sync(&sched->tick_work);
> + disable_work_sync(&sched->fw_events_work);
>
> mutex_lock(&sched->lock);
> if (sched->pm.has_ref) {
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v3] drm/panthor: Fix UAF race between device unplug and FW event processing
2025-10-27 14:02 [PATCH v3] drm/panthor: Fix UAF race between device unplug and FW event processing Ketil Johnsen
2025-10-27 14:31 ` Boris Brezillon
@ 2025-11-03 12:12 ` Liviu Dudau
2025-11-03 14:38 ` Liviu Dudau
2 siblings, 0 replies; 4+ messages in thread
From: Liviu Dudau @ 2025-11-03 12:12 UTC (permalink / raw)
To: Ketil Johnsen
Cc: Boris Brezillon, Steven Price, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, David Airlie, Simona Vetter, Heiko Stuebner,
dri-devel, linux-kernel
On Mon, Oct 27, 2025 at 03:02:15PM +0100, Ketil Johnsen wrote:
> The function panthor_fw_unplug() will free the FW memory sections.
> The problem is that there could still be pending FW events which are yet
> not handled at this point. process_fw_events_work() can in this case try
> to access said freed memory.
>
> Simply call disable_work_sync() to both drain and prevent future
> invocation of process_fw_events_work().
>
> Signed-off-by: Ketil Johnsen <ketil.johnsen@arm.com>
> Fixes: de85488138247 ("drm/panthor: Add the scheduler logical block")
Reviewed-by: Liviu Dudau <liviu.dudau@arm.com>
Best regards,
Liviu
> ---
> v2:
> - Followed Boris's advice and handle the race purely within the
> scheduler block (by adding a destroyed state)
>
> v3:
> - New approach, one single call to disable_work_sync()
> ---
> drivers/gpu/drm/panthor/panthor_sched.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/gpu/drm/panthor/panthor_sched.c b/drivers/gpu/drm/panthor/panthor_sched.c
> index 0cc9055f4ee52..b7595beaa0205 100644
> --- a/drivers/gpu/drm/panthor/panthor_sched.c
> +++ b/drivers/gpu/drm/panthor/panthor_sched.c
> @@ -3880,6 +3880,7 @@ void panthor_sched_unplug(struct panthor_device *ptdev)
> struct panthor_scheduler *sched = ptdev->scheduler;
>
> cancel_delayed_work_sync(&sched->tick_work);
> + disable_work_sync(&sched->fw_events_work);
>
> mutex_lock(&sched->lock);
> if (sched->pm.has_ref) {
> --
> 2.47.2
>
--
====================
| I would like to |
| fix the world, |
| but they're not |
| giving me the |
\ source code! /
---------------
¯\_(ツ)_/¯
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v3] drm/panthor: Fix UAF race between device unplug and FW event processing
2025-10-27 14:02 [PATCH v3] drm/panthor: Fix UAF race between device unplug and FW event processing Ketil Johnsen
2025-10-27 14:31 ` Boris Brezillon
2025-11-03 12:12 ` Liviu Dudau
@ 2025-11-03 14:38 ` Liviu Dudau
2 siblings, 0 replies; 4+ messages in thread
From: Liviu Dudau @ 2025-11-03 14:38 UTC (permalink / raw)
To: Ketil Johnsen
Cc: Boris Brezillon, Steven Price, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, David Airlie, Simona Vetter, Heiko Stuebner,
dri-devel, linux-kernel
On Mon, Oct 27, 2025 at 03:02:15PM +0100, Ketil Johnsen wrote:
> The function panthor_fw_unplug() will free the FW memory sections.
> The problem is that there could still be pending FW events which are yet
> not handled at this point. process_fw_events_work() can in this case try
> to access said freed memory.
>
> Simply call disable_work_sync() to both drain and prevent future
> invocation of process_fw_events_work().
>
> Signed-off-by: Ketil Johnsen <ketil.johnsen@arm.com>
> Fixes: de85488138247 ("drm/panthor: Add the scheduler logical block")
Pushed to drm-misc-next.
Best regards,
Liviu
> ---
> v2:
> - Followed Boris's advice and handle the race purely within the
> scheduler block (by adding a destroyed state)
>
> v3:
> - New approach, one single call to disable_work_sync()
> ---
> drivers/gpu/drm/panthor/panthor_sched.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/gpu/drm/panthor/panthor_sched.c b/drivers/gpu/drm/panthor/panthor_sched.c
> index 0cc9055f4ee52..b7595beaa0205 100644
> --- a/drivers/gpu/drm/panthor/panthor_sched.c
> +++ b/drivers/gpu/drm/panthor/panthor_sched.c
> @@ -3880,6 +3880,7 @@ void panthor_sched_unplug(struct panthor_device *ptdev)
> struct panthor_scheduler *sched = ptdev->scheduler;
>
> cancel_delayed_work_sync(&sched->tick_work);
> + disable_work_sync(&sched->fw_events_work);
>
> mutex_lock(&sched->lock);
> if (sched->pm.has_ref) {
> --
> 2.47.2
>
--
====================
| I would like to |
| fix the world, |
| but they're not |
| giving me the |
\ source code! /
---------------
¯\_(ツ)_/¯
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-11-03 14:38 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-27 14:02 [PATCH v3] drm/panthor: Fix UAF race between device unplug and FW event processing Ketil Johnsen
2025-10-27 14:31 ` Boris Brezillon
2025-11-03 12:12 ` Liviu Dudau
2025-11-03 14:38 ` Liviu Dudau
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox