Skip to contentSkip to conversation

drm/msm: Defer fd_install()

PATCH New Rob Clark 1 participant 3 messages Jul 23, 2025

Subsystems (3)
lore
Share & tools
lore

Rob Clark

author maintainer
#0 lore raw

cover drm/msm: Defer fd_install()

The first patch fixes an issue that Dan Carpenter reported in
https://lore.kernel.org/all/[email protected]/
and the second fixes the same issue in the more recently introduced VM_BIND ioctl.

Rob Clark (2):
drm/msm: Defer fd_install in SUBMIT ioctl
drm/msm: Defer fd_install in VM_BIND ioctl

 drivers/gpu/drm/msm/msm_gem_submit.c | 14 +++++++-------
 drivers/gpu/drm/msm/msm_gem_vma.c    | 14 +++++++-------
 2 files changed, 14 insertions(+), 14 deletions(-)
Signature · 1 line
2.50.1
author maintainer
#1 lore raw

PATCH 1/2 drm/msm: Defer fd_install in SUBMIT ioctl

Avoid fd_install() until there are no more potential error paths, to avoid put_unused_fd() after the fd is made visible to userspace.

Fixes 68dc6c2d5eec ("drm/msm: Fix submit error-path leaks")
---
 drivers/gpu/drm/msm/msm_gem_submit.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/gpu/drm/msm/msm_gem_submit.c +7 -7
index 0ac4c199ec93..bfea19baf6d9 100644
@@ -770,12 +770,8 @@ int msm_ioctl_gem_submit(struct drm_device *dev, void *data,
 
 	if (ret == 0 && args->flags & MSM_SUBMIT_FENCE_FD_OUT) {
 		sync_file = sync_file_create(submit->user_fence);
-		if (!sync_file) {
+		if (!sync_file)
 			ret = -ENOMEM;
-		} else {
-			fd_install(out_fence_fd, sync_file->file);
-			args->fence_fd = out_fence_fd;
-		}
 	}
 
 	if (ret)
@@ -813,10 +809,14 @@ int msm_ioctl_gem_submit(struct drm_device *dev, void *data,
 out_unlock:
 	mutex_unlock(&queue->lock);
 out_post_unlock:
-	if (ret && (out_fence_fd >= 0)) {
-		put_unused_fd(out_fence_fd);
+	if (ret) {
+		if (out_fence_fd >= 0)
+			put_unused_fd(out_fence_fd);
 		if (sync_file)
 			fput(sync_file->file);
+	} else if (sync_file) {
+		fd_install(out_fence_fd, sync_file->file);
+		args->fence_fd = out_fence_fd;
 	}
 
 	if (!IS_ERR_OR_NULL(submit)) {
Signature · 1 line
2.50.1
author maintainer
#2 lore raw

PATCH 2/2 drm/msm: Defer fd_install in VM_BIND ioctl

In reply to Rob Clark

Avoid fd_install() until there are no more potential error paths, to avoid put_unused_fd() after the fd is made visible to userspace.

Fixes 03b6becb03c8 ("Merge tag 'drm-msm-next-2025-07-05' into HEAD")
---
 drivers/gpu/drm/msm/msm_gem_vma.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/gpu/drm/msm/msm_gem_vma.c +7 -7
index e5162db436a6..d4b1cfb3aa03 100644
@@ -1473,12 +1473,8 @@ msm_ioctl_vm_bind(struct drm_device *dev, void *data, struct drm_file *file)
 
 	if (args->flags & MSM_VM_BIND_FENCE_FD_OUT) {
 		sync_file = sync_file_create(job->fence);
-		if (!sync_file) {
+		if (!sync_file)
 			ret = -ENOMEM;
-		} else {
-			fd_install(out_fence_fd, sync_file->file);
-			args->fence_fd = out_fence_fd;
-		}
 	}
 
 	if (ret)
@@ -1507,10 +1503,14 @@ msm_ioctl_vm_bind(struct drm_device *dev, void *data, struct drm_file *file)
 out_unlock:
 	mutex_unlock(&queue->lock);
 out_post_unlock:
-	if (ret && (out_fence_fd >= 0)) {
-		put_unused_fd(out_fence_fd);
+	if (ret) {
+		if (out_fence_fd >= 0)
+			put_unused_fd(out_fence_fd);
 		if (sync_file)
 			fput(sync_file->file);
+	} else if (sync_file) {
+		fd_install(out_fence_fd, sync_file->file);
+		args->fence_fd = out_fence_fd;
 	}
 
 	if (!IS_ERR_OR_NULL(job)) {
Signature · 1 line
2.50.1