Patch "drm/sched: Fix potential double free in drm_sched_job_add_resv_dependencies" has been added to the 6.12-stable tree
Subsystems (3)
[email protected]
AppliedThis is a note to let you know that I've just added the patch titled
drm/sched: Fix potential double free in drm_sched_job_add_resv_dependencies
to the 6.12-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary
The filename of the patch is:
drm-sched-fix-potential-double-free-in-drm_sched_job_add_resv_dependencies.patch
and it can be found in the queue-6.12 subdirectory.
If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.
From 5801e65206b065b0b2af032f7f1eef222aa2fd83 Mon Sep 17 00:00:00 2001
From: Tvrtko Ursulin <[email protected]>
Date: Wed, 15 Oct 2025 09:40:15 +0100
Subject: drm/sched: Fix potential double free in drm_sched_job_add_resv_dependencies
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
From: Tvrtko Ursulin <[email protected]>
commit 5801e65206b065b0b2af032f7f1eef222aa2fd83 upstream.
When adding dependencies with drm_sched_job_add_dependency(), that function consumes the fence reference both on success and failure, so in the latter case the dma_fence_put() on the error path (xarray failed to expand) is a double free.
Interestingly this bug appears to have been present ever since commit ebd5f74255b9 ("drm/sched: Add dependency tracking"), since the code back then looked like this:
drm_sched_job_add_implicit_dependencies():
...
for (i = 0; i < fence_count; i++) {
ret = drm_sched_job_add_dependency(job, fences[i]);
if (ret)
break;
}
for (; i < fence_count; i++)
dma_fence_put(fences[i]);Which means for the failing 'i' the dma_fence_put was already a double free. Possibly there were no users at that time, or the test cases were insufficient to hit it.
The bug was then only noticed and fixed after
commit 9c2ba265352a ("drm/scheduler: use new iterator in drm_sched_job_add_implicit_dependencies v2") landed, with its fixup of
commit 4eaf02d6076c ("drm/scheduler: fix drm_sched_job_add_implicit_dependencies").
At that point it was a slightly different flavour of a double free, which commit 963d0b356935 ("drm/scheduler: fix drm_sched_job_add_implicit_dependencies harder") noticed and attempted to fix.
But it only moved the double free from happening inside the drm_sched_job_add_dependency(), when releasing the reference not yet obtained, to the caller, when releasing the reference already released by the former in the failure case.
As such it is not easy to identify the right target for the fixes tag so lets keep it simple and just continue the chain.
While fixing we also improve the comment and explain the reason for taking the reference and not dropping it.
--- drivers/gpu/drm/scheduler/sched_main.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
drivers/gpu/drm/scheduler/sched_main.c +7 -6
@@ -952,13 +952,14 @@ int drm_sched_job_add_resv_dependencies(dma_resv_assert_held (resv);dma_resv_for_each_fence (&cursor, resv, usage, fence) { -/* Make sure to grab an additional ref on the added fence */ -dma_fence_get (fence); - ret =drm_sched_job_add_dependency (job, fence); -if (ret) { -dma_fence_put (fence); +/* +* As drm_sched_job_add_dependency always consumes the fence +* reference (even when it fails), and dma_resv_for_each_fence +* is not obtaining one, we need to grab one before calling. +*/ + ret =drm_sched_job_add_dependency (job,dma_fence_get (fence)); +if (ret)return ret; - } }return 0 ; }
Patches currently in stable-queue which might be from [email protected] are
queue-6.12/drm-sched-fix-potential-double-free-in-drm_sched_job_add_resv_dependencies.patch