Skip to contentSkip to conversation

drm/panthor: validate userspace queue count against initialized firmware slot count

PATCH In review Osama Abdelkader 4 participants 5 messages Aug 4 – Sep 30

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

PATCH 1/1 drm/panthor: validate userspace queue count against initialized firmware slot count

In panthor_drv.c:panthor_ioctl_group_create(),
the queue count is validated against the hardcoded maximum:

	if (!args->queues.count || args->queues.count > MAX_CS_PER_CSG)
		return -EINVAL;

However, if the firmware reports fewer slots than MAX_CS_PER_CSG, panthor_fw_init_ifaces() will only initialize that smaller number of stream interfaces.

If unprivileged userspace requests more queues than the firmware reported (but no more than MAX_CS_PER_CSG), cs_slot_prog_locked() fetches an uninitialized stream interface and may crash when dereferencing cs_iface->input->ringbuf_base.

Fixes de8548813824 ("drm/panthor: Add the scheduler logical block")
Reported-by [email protected]
---
 drivers/gpu/drm/panthor/panthor_sched.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/gpu/drm/panthor/panthor_sched.c +3 -0
index 5832dccfc093..64749750e6ee 100644
@@ -3673,6 +3673,9 @@ int panthor_group_create(struct panthor_file *pfile,
 	    hweight64(group_args->tiler_core_mask) < group_args->max_tiler_cores)
 		return -EINVAL;
 
+	if (group_args->queues.count > sched->cs_slot_count)
+		return -EINVAL;
+
 	group = kzalloc_obj(*group);
 	if (!group)
 		return -ENOMEM;
Signature · 1 line
2.43.0
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 15 lines · On Tue, 4 Aug 2026 18:00:47 +0200 Osama Abdelkader…

In panthor_drv.c:panthor_ioctl_group_create(),
the queue count is validated against the hardcoded maximum:

	if (!args->queues.count || args->queues.count > MAX_CS_PER_CSG)
		return -EINVAL;

However, if the firmware reports fewer slots than MAX_CS_PER_CSG, panthor_fw_init_ifaces() will only initialize that smaller number of stream interfaces.

If unprivileged userspace requests more queues than the firmware reported (but no more than MAX_CS_PER_CSG), cs_slot_prog_locked() fetches an uninitialized stream interface and may crash when dereferencing cs_iface->input->ringbuf_base.

Quoted 5 lines
Fixes de8548813824 ("drm/panthor: Add the scheduler logical block")
Reported-by [email protected]
Quoted 18 lines
---
 drivers/gpu/drm/panthor/panthor_sched.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/gpu/drm/panthor/panthor_sched.c +3 -0
index 5832dccfc093..64749750e6ee 100644
@@ -3673,6 +3673,9 @@ int panthor_group_create(struct panthor_file *pfile,
 	    hweight64(group_args->tiler_core_mask) < group_args->max_tiler_cores)
 		return -EINVAL;
 
+	if (group_args->queues.count > sched->cs_slot_count)
+		return -EINVAL;
+
 	group = kzalloc_obj(*group);
 	if (!group)
 		return -ENOMEM;
maintainer Reviewed-by on v1 1/1
#2 lore raw
In reply to Osama Abdelkader
Quoted 15 lines · Osama Abdelkader

In panthor_drv.c:panthor_ioctl_group_create(),
the queue count is validated against the hardcoded maximum:

	if (!args->queues.count || args->queues.count > MAX_CS_PER_CSG)
		return -EINVAL;

However, if the firmware reports fewer slots than MAX_CS_PER_CSG, panthor_fw_init_ifaces() will only initialize that smaller number of stream interfaces.

If unprivileged userspace requests more queues than the firmware reported (but no more than MAX_CS_PER_CSG), cs_slot_prog_locked() fetches an uninitialized stream interface and may crash when dereferencing cs_iface->input->ringbuf_base.

Quoted 5 lines
Fixes de8548813824 ("drm/panthor: Add the scheduler logical block")
Reported-by [email protected]

Best regards,
Liviu

Quoted 21 lines
---
 drivers/gpu/drm/panthor/panthor_sched.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/gpu/drm/panthor/panthor_sched.c +3 -0
index 5832dccfc093..64749750e6ee 100644
@@ -3673,6 +3673,9 @@ int panthor_group_create(struct panthor_file *pfile,
 	    hweight64(group_args->tiler_core_mask) < group_args->max_tiler_cores)
 		return -EINVAL;
 
+	if (group_args->queues.count > sched->cs_slot_count)
+		return -EINVAL;
+
 	group = kzalloc_obj(*group);
 	if (!group)
 		return -ENOMEM;
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!  /
  ---------------
    ¯\_(ツ)_/¯
maintainer Reviewed-by on v1 1/1
#3 lore raw
In reply to Osama Abdelkader
Quoted 15 lines · Osama Abdelkader

In panthor_drv.c:panthor_ioctl_group_create(),
the queue count is validated against the hardcoded maximum:

	if (!args->queues.count || args->queues.count > MAX_CS_PER_CSG)
		return -EINVAL;

However, if the firmware reports fewer slots than MAX_CS_PER_CSG, panthor_fw_init_ifaces() will only initialize that smaller number of stream interfaces.

If unprivileged userspace requests more queues than the firmware reported (but no more than MAX_CS_PER_CSG), cs_slot_prog_locked() fetches an uninitialized stream interface and may crash when dereferencing cs_iface->input->ringbuf_base.

Quoted 5 lines
Fixes de8548813824 ("drm/panthor: Add the scheduler logical block")
Reported-by [email protected]

Looks like this one got missed - I'll push it to drm-misc-fixes.

Thanks,
Steve

Quoted 18 lines
---
 drivers/gpu/drm/panthor/panthor_sched.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/gpu/drm/panthor/panthor_sched.c +3 -0
index 5832dccfc093..64749750e6ee 100644
@@ -3673,6 +3673,9 @@ int panthor_group_create(struct panthor_file *pfile,
 	    hweight64(group_args->tiler_core_mask) < group_args->max_tiler_cores)
 		return -EINVAL;
 
+	if (group_args->queues.count > sched->cs_slot_count)
+		return -EINVAL;
+
 	group = kzalloc_obj(*group);
 	if (!group)
 		return -ENOMEM;
maintainer
#4 lore raw
In reply to Osama Abdelkader
Quoted 15 lines · Osama Abdelkader

In panthor_drv.c:panthor_ioctl_group_create(),
the queue count is validated against the hardcoded maximum:

	if (!args->queues.count || args->queues.count > MAX_CS_PER_CSG)
		return -EINVAL;

However, if the firmware reports fewer slots than MAX_CS_PER_CSG, panthor_fw_init_ifaces() will only initialize that smaller number of stream interfaces.

If unprivileged userspace requests more queues than the firmware reported (but no more than MAX_CS_PER_CSG), cs_slot_prog_locked() fetches an uninitialized stream interface and may crash when dereferencing cs_iface->input->ringbuf_base.

Quoted 5 lines
Fixes de8548813824 ("drm/panthor: Add the scheduler logical block")
Reported-by [email protected]

Sorry for the delay caused by holidays and other things, this patch has now been merged.

Best regards,
Liviu

Quoted 21 lines
---
 drivers/gpu/drm/panthor/panthor_sched.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/gpu/drm/panthor/panthor_sched.c +3 -0
index 5832dccfc093..64749750e6ee 100644
@@ -3673,6 +3673,9 @@ int panthor_group_create(struct panthor_file *pfile,
 	    hweight64(group_args->tiler_core_mask) < group_args->max_tiler_cores)
 		return -EINVAL;
 
+	if (group_args->queues.count > sched->cs_slot_count)
+		return -EINVAL;
+
 	group = kzalloc_obj(*group);
 	if (!group)
 		return -ENOMEM;
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!  /
  ---------------
    ¯\_(ツ)_/¯