]> git.hungrycats.org Git - linux/commitdiff
drm/msm: Move nr_cmds initialization
authorRob Clark <robin.clark@oss.qualcomm.com>
Wed, 29 Jul 2026 15:55:42 +0000 (08:55 -0700)
committerRob Clark <robin.clark@oss.qualcomm.com>
Wed, 29 Jul 2026 18:56:02 +0000 (11:56 -0700)
Previously if we entered an error path between these two points, we
could leak the relocs tables due to submit->nr_cmds still being zero.

In practice, relocs are disallowed on a6xx+, and non-ancient userspace
will not use relocs on earlier gens unless running on an ancient kernel.
But userspace could use this to trigger a memory leak.

Reported-by: Sashiko <sashiko-bot@kernel.org>
Signed-off-by: Rob Clark <robin.clark@oss.qualcomm.com>
Patchwork: https://patchwork.freedesktop.org/patch/743085/
Message-ID: <20260729155609.20190-6-robin.clark@oss.qualcomm.com>

drivers/gpu/drm/msm/msm_gem_submit.c

index 3c6bc90c3d4861d2857dda1769a152e8f08844a1..aa48ea4e7f5846007a1b2def459ac9752c37ffd3 100644 (file)
@@ -260,6 +260,9 @@ static int submit_lookup_cmds(struct msm_gem_submit *submit,
                        ret = -ENOMEM;
                        goto out;
                }
+
+               submit->nr_cmds = i + 1;
+
                ret = copy_from_user(submit->cmd[i].relocs, userptr, sz);
                if (ret) {
                        ret = -EFAULT;
@@ -719,8 +722,6 @@ int msm_ioctl_gem_submit(struct drm_device *dev, void *data,
                        goto out;
        }
 
-       submit->nr_cmds = args->nr_cmds;
-
        idr_preload(GFP_KERNEL);
 
        spin_lock(&queue->idr_lock);