Skip to contentSkip to conversation

drm/panthor: Fix UAF race between device unplug and FW event processing

PATCH Applied Ketil Johnsen 3 participants 4 messages Oct 27, 2025 – Nov 3, 2025

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

PATCH v3 1/1 drm/panthor: Fix UAF race between device unplug and FW event processing

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().

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(+)
drivers/gpu/drm/panthor/panthor_sched.c +1 -0
index 0cc9055f4ee52..b7595beaa0205 100644
@@ -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) {
Signature · 1 line
2.47.2
maintainer Reviewed-by on v3 1/1
#1 lore raw
Quoted 10 lines · On Mon, 27 Oct 2025 15:02:15 +0100 Ketil Johnsen <[email protected]> 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().

Fixes de85488138247 ("drm/panthor: Add the scheduler logical block")

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.

Quoted 23 lines

---
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(+)
drivers/gpu/drm/panthor/panthor_sched.c +1 -0
index 0cc9055f4ee52..b7595beaa0205 100644
@@ -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) {
maintainer Reviewed-by on v3 1/1
#2 lore raw
In reply to Ketil Johnsen
Quoted 10 lines · Ketil Johnsen

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().

Fixes de85488138247 ("drm/panthor: Add the scheduler logical block")

Best regards,
Liviu

Quoted 26 lines

---
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(+)
drivers/gpu/drm/panthor/panthor_sched.c +1 -0
index 0cc9055f4ee52..b7595beaa0205 100644
@@ -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) {
Signature · 1 line
2.47.2
Signature · 8 lines
====================
| I would like to |
| fix the world,  |
| but they're not |
| giving me the   |
 \ source code!  /
  ---------------
    ¯\_(ツ)_/¯
maintainer Applied
#3 lore raw
In reply to Ketil Johnsen
Quoted 10 lines · Ketil Johnsen

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().

Fixes de85488138247 ("drm/panthor: Add the scheduler logical block")

Pushed to drm-misc-next.

Best regards,
Liviu

Quoted 26 lines

---
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(+)
drivers/gpu/drm/panthor/panthor_sched.c +1 -0
index 0cc9055f4ee52..b7595beaa0205 100644
@@ -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) {
Signature · 1 line
2.47.2
Signature · 8 lines
====================
| I would like to |
| fix the world,  |
| but they're not |
| giving me the   |
 \ source code!  /
  ---------------
    ¯\_(ツ)_/¯