From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796208801; b=vr2edTD6yLqF7YcXt17buq/BR//r9mfxoKHdCmQ/8WlUoMxDHFQVb+a+apT5S6USAdUo wssvuhHQYPZL5ujaS+ylsej2uFVA5D6T84WU0mTcrLdQxAhFwGHKp54YG26xF+0LfI2AY UhpUQ9m61pzmxdYU2X5MF5wWHlR5V7CXHiyxWyEY7AJS51criZPIzfzQ+EfJHuPn1gNDV 6CWf2Tcfqwc/+/dFXSeB8IMz827CAhU/vZI0m5B7QSS+xZq49/Gps58EdJoyh5IjXuuaR 1ZLIBzwkyzzD7vpiFSGKcm8O82jkDry8pX/c/sneZXh+DLEWV+RJynvV/ZgOyPxQRxQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796208801; h=Received:DKIM-Signature:Subject:To:Cc:From:Date:Message-ID: MIME-Version:Content-Type:Content-Transfer-Encoding; bh=+3ZKdrfPI+fyJJ6JNSXg0X5+0IVwXYoG4fdvB53ZkiM=; b=4vYlYUQjNgHbl/JGxSwLyxszR2Vl6aOpU/rwxrOsGXd/TsxNXUe8y3XNDWI85lhqxPDH 4cJJx12fvyiXWpXxZrqOXgP/66wP6smWM2Wh2vBVkkyp/Uv0i7X3NyfnzCDL52xA8qcGX ElZVvSmMdMbn+6PiXcxzvIgueyo18ttowpru5CkaT9k/yFVt9QUtPA10muKSJi0RObezd jvKuwqJ419cs6FmtgRzciQl1PEpHJq20hHTtxHtomKlCjE8noF0EJ/QwYBARLIPRPXfY4 KNRH75vN0OfQojAiFrJAOHvuTGhZ2YVTkTdYyPy/iNIl8CF+d7mpMWFRjwXmROElCdA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=ps2H07aY; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1A17E606A31A for ; Wed, 2 Dec 2026 10:53:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=ps2H07aY Received: by smtp.kernel.org (Postfix) with ESMTPSA id 54D731F00924; Wed, 2 Dec 2026 10:53:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796208800; bh=+3ZKdrfPI+fyJJ6JNSXg0X5+0IVwXYoG4fdvB53ZkiM=; h=Subject:To:Cc:From:Date; b=ps2H07aY0hWgYCvM0twWRDxZRXNci6P9Q71shlsj7FNOfp9xso12rGo0Ha+otL8jm PDzFuo0XpwliAwSHfxg+OCHu1+Q7AvZSQyno1QtENkHoCic2/VczVI9eYnhLV0MPpl 6CtlDVK56kFmV9k/ITp1wpWcy53yVTM3JJUPfEUw= Subject: FAILED: patch "[PATCH] drm/sched: Ensure stopped entity cannot be re-added to the" failed to apply to 6.18-stable tree To: tvrtko.ursulin@igalia.com,airlied@gmail.com,andrey.grodzovsky@amd.com,christian.koenig@amd.com,dakr@kernel.org,luben.tuikov@amd.com,matthew.brost@intel.com,phasta@kernel.org,simona@ffwll.ch Cc: From: Date: Wed, 02 Dec 2026 11:53:18 +0100 Message-ID: <2026120218-politely-chain-ca03@gregkh> X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The patch below does not apply to the 6.18-stable tree. If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to . To reproduce the conflict and resubmit, you may use the following commands: git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.18.y git checkout FETCH_HEAD git cherry-pick -x 7e2645d5c05ac03f240685fe76a2c04733d36a1a # git commit -s git send-email --to '' --in-reply-to '2026120218-politely-chain-ca03@gregkh' --subject-prefix 'PATCH 6.18.y' 'HEAD^..' Possible dependencies: thanks, greg k-h ------------------ original commit in Linus's tree ------------------ >From 7e2645d5c05ac03f240685fe76a2c04733d36a1a Mon Sep 17 00:00:00 2001 From: Tvrtko Ursulin Date: Mon, 9 Nov 2026 16:07:43 +0000 Subject: [PATCH] drm/sched: Ensure stopped entity cannot be re-added to the run-queue MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When entities are torn down in drm_sched_entity_kill() a multi-step process is undertaken to synchronize with a drm_sched_run_job_work() consuming jobs from the same entity. First the entity is marked as stopped and removed from the run-queue, with both the entity and run-queue lock correctly taken. The process then waits for the entity idle via the completion after which point it assumes it is the only accessor to the entity in question. What can happen however in drm_sched_run_job_work() if there are at least two outstanding runnable jobs on an entity, is that drm_sched_entity_pop_job() can re-add it to the run-queue due the unconditial add to the rbtree via drm_sched_rq_update_fifo_locked(). What is required is that the teardown starts after the run job has selected the entity and that it gets to it's completion waiting stage before the run job goes to dequeue a job, and for the run job to be able to de-queue a job before teardown has consumed too many. Run job will then see there is another job pending (after the one about to be de-queued) and it will re-add the entity to the run-queue. Run job will then signal the completion and entity teardown will proceed incorrectly thinking it's removal of the entity was final. End result is a pointer to an entity about to be freed dangling forever in the rbtree. drm_sched_run_job_work() drm_sched_entity_kill() drm_sched_select_entity stops and removes entity wait_for_completion drm_sched_entity_pop_job -> re-adds to run-queue due more jobs complete_all drm_sched_entity_queue_pop ... fini entity ... drm_sched_run_job_queue drm_sched_select_entity - UAF This race existed ever since the FIFO policy was first added. Lets mirror the guard from drm_sched_rq_add_entity() in drm_sched_rq_pop_entity() and close this gap. Signed-off-by: Tvrtko Ursulin References: https://sashiko.dev/#/patchset/20261020154123.33631-1-tvrtko.ursulin@igalia.com?part=7 Fixes: 08fb97de03aa ("drm/sched: Add FIFO sched policy to run queue") Cc: Luben Tuikov Cc: Christian König Cc: Andrey Grodzovsky Cc: Matthew Brost Cc: Danilo Krummrich Cc: Philipp Stanner Cc: David Airlie Cc: Simona Vetter Cc: stable@vger.kernel.org # v6.2+ Signed-off-by: Philipp Stanner Link: https://patch.msgid.link/20261109160743.17020-1-tvrtko.ursulin@igalia.com diff --git a/drivers/gpu/drm/scheduler/sched_rq.c b/drivers/gpu/drm/scheduler/sched_rq.c index 23f46ec610e7..6f67a146d99c 100644 --- a/drivers/gpu/drm/scheduler/sched_rq.c +++ b/drivers/gpu/drm/scheduler/sched_rq.c @@ -345,6 +345,13 @@ void drm_sched_rq_pop_entity(struct drm_sched_entity *entity) lockdep_assert_held(&entity->lock); + /* + * If entity is getting torn down via drm_sched_entity_kill() we need + * to ensure it does not get re-added to the tree behind it's back. + */ + if (entity->stopped) + return; + spin_lock(&rq->lock); /*