]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
drm/msm: Defer fd_install in SUBMIT ioctl
authorRob Clark <robin.clark@oss.qualcomm.com>
Wed, 23 Jul 2025 20:28:22 +0000 (13:28 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 4 Sep 2025 13:31:45 +0000 (15:31 +0200)
[ Upstream commit f22853435bbd1e9836d0dce7fd99c040b94c2bf1 ]

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")
Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
Signed-off-by: Rob Clark <robin.clark@oss.qualcomm.com>
Patchwork: https://patchwork.freedesktop.org/patch/665363/
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/gpu/drm/msm/msm_gem_submit.c

index 4b3a8ee8e278f09647f350303ad054f35e49e9fc..3eee6517541e3f1c6c9b56dc53f7b958c4e71615 100644 (file)
@@ -879,12 +879,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)
@@ -912,10 +908,14 @@ out:
 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)) {