]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
drm/imagination: take paired job reference
authorBrendan King <Brendan.King@imgtec.com>
Tue, 18 Mar 2025 14:53:13 +0000 (14:53 +0000)
committerMatt Coster <matt.coster@imgtec.com>
Tue, 25 Mar 2025 17:17:37 +0000 (17:17 +0000)
For paired jobs, have the fragment job take a reference on the
geometry job, so that the geometry job cannot be freed until
the fragment job has finished with it.

The geometry job structure is accessed when the fragment job is being
prepared by the GPU scheduler. Taking the reference prevents the
geometry job being freed until the fragment job no longer requires it.

Fixes a use after free bug detected by KASAN:

[  124.256386] BUG: KASAN: slab-use-after-free in pvr_queue_prepare_job+0x108/0x868 [powervr]
[  124.264893] Read of size 1 at addr ffff0000084cb960 by task kworker/u16:4/63

Cc: stable@vger.kernel.org
Fixes: eaf01ee5ba28 ("drm/imagination: Implement job submission and scheduling")
Signed-off-by: Brendan King <brendan.king@imgtec.com>
Reviewed-by: Matt Coster <matt.coster@imgtec.com>
Link: https://lore.kernel.org/r/20250318-ddkopsrc-1337-use-after-free-in-pvr_queue_prepare_job-v1-1-80fb30d044a6@imgtec.com
Signed-off-by: Matt Coster <matt.coster@imgtec.com>
drivers/gpu/drm/imagination/pvr_job.c
drivers/gpu/drm/imagination/pvr_queue.c

index 618503a212a7d34a17a2cb241231e38f83eb9cff..aad183a5737183291fb1194353b3172b415f19b7 100644 (file)
@@ -677,6 +677,13 @@ pvr_jobs_link_geom_frag(struct pvr_job_data *job_data, u32 *job_count)
                geom_job->paired_job = frag_job;
                frag_job->paired_job = geom_job;
 
+               /* The geometry job pvr_job structure is used when the fragment
+                * job is being prepared by the GPU scheduler. Have the fragment
+                * job hold a reference on the geometry job to prevent it being
+                * freed until the fragment job has finished with it.
+                */
+               pvr_job_get(geom_job);
+
                /* Skip the fragment job we just paired to the geometry job. */
                i++;
        }
index 43411be930a214f122ee674668cf4af8f529c01a..fa1afe1193e1d3171221126f1ef2e3a48804f160 100644 (file)
@@ -866,6 +866,10 @@ static void pvr_queue_free_job(struct drm_sched_job *sched_job)
        struct pvr_job *job = container_of(sched_job, struct pvr_job, base);
 
        drm_sched_job_cleanup(sched_job);
+
+       if (job->type == DRM_PVR_JOB_TYPE_FRAGMENT && job->paired_job)
+               pvr_job_put(job->paired_job);
+
        job->paired_job = NULL;
        pvr_job_put(job);
 }