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=1796380725; b=Mi3xGhVoKRrlL3ISrtGgZNG9A0h7W3Gq/L28Ge6zNKaLWAaitwuY4ft3OV5925UU3jPp jP+9cC2q+yzTlFfF5fmWG3dLS6lPIQgD+89RoAG7NKUwPWX3uZyUweyDi1X5oUeAWTu7M MktDfF2vbmGvy5R3LZiYRt5ITxfkNK2vq2l0bVNF1FeIanehOExxn4VbWf7IREY+Zu1Ny OSSnttwtxRhX7u29x9ouLW18oDW9ESQqVu68vZhgem941bxsjmaMpYyjedpb9M6Cc4gMx 0Z7ZoJ30WfYFMTj7e32eiB2h7BJ2FrdtZrAbDK/apWLSTG4ZuVsRZZC/tQRoyw+NbTQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796380725; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Type:Content-Transfer-Encoding; bh=uGIMa7pDFiG7Tz1P+63V1yRvmBBuDkmnE6kzKAfb840=; b=vF/BRVq70uQh4Xhrr67+EAekUcqZzjhz5uM6kRs4J/nR95r1+prvzybq62jtfbrBTi8X RwXXEXqh76/ZcsF3eGwa+Fdiis8dt8XmY5+wnJ6FtzHPFKXQAEhQiezCrerSwU9dQG8lb InmUTs4HtTtMAl8bJIJFlBm2DC1vgG/cmWOOvQJvz+TiPa55E3+RnP9Qokfl31DXoJvdS +GvepwWhPXWvoSsJvZHA1bPs1KfR630OfnKUb4YhAnrM110mmyx0Ie7Kg71/gq0GzD1T1 38hPT5WLiJ6HSXhWCElnAeCCwDhXRmIGfzk2LsjUA8Fqeie+j2gyKXf51LTxflIdvwg== 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=c9ppaGZy; 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 EA12A606A322; Fri, 4 Dec 2026 10:38:44 +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=c9ppaGZy Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6DB291F000CE; Fri, 4 Dec 2026 10:38:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796380724; bh=uGIMa7pDFiG7Tz1P+63V1yRvmBBuDkmnE6kzKAfb840=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=c9ppaGZyY1UiWYu5aReYful7poMTCBsl5wXxBy8mRBlwgQ4aaP1V2v1USajEQuDSP BeOxO/M6lTqmmCwscITV0RDj24hwBH5QV2fr6zWUUYkHYNtzg5F6Fv6S5hfOnuMueJ tvu+IXyp+2dkjgoGftf0feFOLBRE/AbdZO8ChkUE= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Tvrtko Ursulin , Luben Tuikov , =?UTF-8?q?Christian=20K=C3=B6nig?= , Andrey Grodzovsky , Matthew Brost , Danilo Krummrich , Philipp Stanner , David Airlie , Simona Vetter Subject: [PATCH 7.3 357/742] drm/sched: Ensure stopped entity cannot be re-added to the run-queue Date: Fri, 4 Dec 2026 19:03:41 +0900 Message-ID: <20261204100644.561777622@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100635.034361255@linuxfoundation.org> References: <20261204100635.034361255@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev 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 7.3-stable review patch. If anyone has any objections, please let me know. ------------------ From: Tvrtko Ursulin commit 7e2645d5c05ac03f240685fe76a2c04733d36a1a upstream. 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 Signed-off-by: Greg Kroah-Hartman --- drivers/gpu/drm/scheduler/sched_rq.c | 7 +++++++ 1 file changed, 7 insertions(+) --- 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_ 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); /*