Skip to contentSkip to conversation

drm/panthor: Fix NULL pointer dereference in sync signal cleanup

PATCH In review Tuo Li 3 participants 3 messages Nov 13 – Nov 16

Subsystems (3)
lore
Share & tools
lore

Tuo Li

author
#0 lore raw

PATCH 1/1 drm/panthor: Fix NULL pointer dereference in sync signal cleanup

In panthor_submit_ctx_add_sync_signal(), drm_syncobj_find() may return NULL. The function then jumps to err_free_sig_sync, where panthor_sync_signal_free() unconditionally calls drm_syncobj_put() on the NULL pointer, causing a NULL pointer dereference.

Check sig_sync->syncobj before calling drm_syncobj_put() to avoid the NULL pointer dereference.

Fixes 4bdca1150792 ("drm/panthor: Add the driver frontend block")
---
 drivers/gpu/drm/panthor/panthor_drv.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/panthor/panthor_drv.c +3 -1
index dc8d0191aef4..8d73956530a8 100644
@@ -364,7 +364,9 @@ panthor_sync_signal_free(struct panthor_sync_signal *sig_sync)
 	if (!sig_sync)
 		return;
 
-	drm_syncobj_put(sig_sync->syncobj);
+	if (sig_sync->syncobj)
+		drm_syncobj_put(sig_sync->syncobj);
+
 	dma_fence_chain_free(sig_sync->chain);
 	dma_fence_put(sig_sync->fence);
 	kfree(sig_sync);
Signature · 1 line
2.43.0
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · On Fri, 13 Nov 2026 17:44:56 +0800 Tuo Li <[email protected]> wrote:

In panthor_submit_ctx_add_sync_signal(), drm_syncobj_find() may return NULL. The function then jumps to err_free_sig_sync, where panthor_sync_signal_free() unconditionally calls drm_syncobj_put() on the NULL pointer, causing a NULL pointer dereference.

Check sig_sync->syncobj before calling drm_syncobj_put() to avoid the NULL pointer dereference.

I really wish we had consistent behavior on those _put() helpers. Most of them check for NULL before calling kref_put(), but some don't, unfortunately...

Quoted 3 lines
Fixes 4bdca1150792 ("drm/panthor: Add the driver frontend block")
Quoted 19 lines
---
 drivers/gpu/drm/panthor/panthor_drv.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/panthor/panthor_drv.c +3 -1
index dc8d0191aef4..8d73956530a8 100644
@@ -364,7 +364,9 @@ panthor_sync_signal_free(struct panthor_sync_signal *sig_sync)
 	if (!sig_sync)
 		return;
 
-	drm_syncobj_put(sig_sync->syncobj);
+	if (sig_sync->syncobj)
+		drm_syncobj_put(sig_sync->syncobj);
+
 	dma_fence_chain_free(sig_sync->chain);
 	dma_fence_put(sig_sync->fence);
 	kfree(sig_sync);
maintainer Reviewed-by on v1 1/1
#2 lore raw
In reply to Tuo Li
Quoted 10 lines · Tuo Li

In panthor_submit_ctx_add_sync_signal(), drm_syncobj_find() may return NULL. The function then jumps to err_free_sig_sync, where panthor_sync_signal_free() unconditionally calls drm_syncobj_put() on the NULL pointer, causing a NULL pointer dereference.

Check sig_sync->syncobj before calling drm_syncobj_put() to avoid the NULL pointer dereference.

Fixes 4bdca1150792 ("drm/panthor: Add the driver frontend block")

Best regards,
Liviu

Quoted 22 lines
---
 drivers/gpu/drm/panthor/panthor_drv.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/panthor/panthor_drv.c +3 -1
index dc8d0191aef4..8d73956530a8 100644
@@ -364,7 +364,9 @@ panthor_sync_signal_free(struct panthor_sync_signal *sig_sync)
 	if (!sig_sync)
 		return;
 
-	drm_syncobj_put(sig_sync->syncobj);
+	if (sig_sync->syncobj)
+		drm_syncobj_put(sig_sync->syncobj);
+
 	dma_fence_chain_free(sig_sync->chain);
 	dma_fence_put(sig_sync->fence);
 	kfree(sig_sync);
Signature · 1 line
2.43.0
Signature · 8 lines
====================
| I would like to |
| fix the world,  |
| but they're not |
| giving me the   |
 \ source code!  /
  ---------------
    ¯\_(ツ)_/¯