Skip to contentSkip to conversation

drm/v3d: reject an invalid indirect CSD buffer handle

PATCH In review JaeHoon Lee 2 participants 2 messages Jun 15 – Jun 16

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

PATCH 1/1 drm/v3d: reject an invalid indirect CSD buffer handle

v3d_get_cpu_indirect_csd_params() does not check the result of drm_gem_object_lookup(). A bogus indirect CSD handle from userspace makes it store NULL in info->indirect; when the CPU job runs, v3d_rewrite_csd_job_wg_counts_from_indirect() dereferences it through v3d_get_bo_vaddr() and oopses the kernel. Any unprivileged client can trigger this.

Reject the NULL handle with -ENOENT, as every other GEM lookup in this driver does. v3d_cpu_job_free() drops the reference under a NULL check, so the error path leaks nothing.

Fixes 18b8413b25b7 ("drm/v3d: Create a CPU job extension for a indirect CSD job")
---
 drivers/gpu/drm/v3d/v3d_submit.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/gpu/drm/v3d/v3d_submit.c +2 -0
index ee2ac2540ed5..05f98379c1a4 100644
@@ -605,6 +605,8 @@ v3d_get_cpu_indirect_csd_params(struct drm_file *file_priv,
 	       sizeof(indirect_csd.wg_uniform_offsets));
 
 	info->indirect = drm_gem_object_lookup(file_priv, indirect_csd.indirect);
+	if (!info->indirect)
+		return -ENOENT;
 
 	return 0;
 }
Signature · 1 line
2.43.0
maintainer
#1 lore raw

Hi JaeHoon,

Duplicated patch, please check [1].

[1] https://lore.kernel.org/dri-devel/[email protected]/T/#m42c7a8cf94b8cb787cca01dfbdaf5fdce40c7332

Best regards,
- Maíra

Quoted 31 lines · JaeHoon Lee

v3d_get_cpu_indirect_csd_params() does not check the result of drm_gem_object_lookup(). A bogus indirect CSD handle from userspace makes it store NULL in info->indirect; when the CPU job runs, v3d_rewrite_csd_job_wg_counts_from_indirect() dereferences it through v3d_get_bo_vaddr() and oopses the kernel. Any unprivileged client can trigger this.

Reject the NULL handle with -ENOENT, as every other GEM lookup in this driver does. v3d_cpu_job_free() drops the reference under a NULL check, so the error path leaks nothing.

Fixes 18b8413b25b7 ("drm/v3d: Create a CPU job extension for a indirect CSD job")
---
  drivers/gpu/drm/v3d/v3d_submit.c | 2 ++
  1 file changed, 2 insertions(+)
drivers/gpu/drm/v3d/v3d_submit.c +2 -0
index ee2ac2540ed5..05f98379c1a4 100644
@@ -605,6 +605,8 @@ v3d_get_cpu_indirect_csd_params(struct drm_file *file_priv,
  	       sizeof(indirect_csd.wg_uniform_offsets));
 
  	info->indirect = drm_gem_object_lookup(file_priv, indirect_csd.indirect);
+	if (!info->indirect)
+		return -ENOENT;
 
  	return 0;
  }