All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drm/scheduler: set entity to NULL in drm_sched_entity_pop_job()
@ 2023-03-31  0:06 ` Danilo Krummrich
  0 siblings, 0 replies; 12+ messages in thread
From: Danilo Krummrich @ 2023-03-31  0:06 UTC (permalink / raw)
  To: luben.tuikov, airlied, daniel, l.stach, christian.koenig
  Cc: Danilo Krummrich, linux-kernel, dri-devel

It already happend a few times that patches slipped through which
implemented access to an entity through a job that was already removed
from the entities queue. Since jobs and entities might have different
lifecycles, this can potentially cause UAF bugs.

In order to make it obvious that a jobs entity pointer shouldn't be
accessed after drm_sched_entity_pop_job() was called successfully, set
the jobs entity pointer to NULL once the job is removed from the entity
queue.

Moreover, debugging a potential NULL pointer dereference is way easier
than potentially corrupted memory through a UAF.

Signed-off-by: Danilo Krummrich <dakr@redhat.com>
---
I'm aware that drivers could already use job->entity in arbitrary places, since
they in control of when the entity is actually freed. A quick grep didn't give
me any results where this would actually be the case, however maybe I also just
didn't catch it.

If, therefore, we don't want to set job->entity to NULL I think we should at
least add a comment somewhere.
---

 drivers/gpu/drm/scheduler/sched_entity.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/gpu/drm/scheduler/sched_entity.c b/drivers/gpu/drm/scheduler/sched_entity.c
index 15d04a0ec623..a9c6118e534b 100644
--- a/drivers/gpu/drm/scheduler/sched_entity.c
+++ b/drivers/gpu/drm/scheduler/sched_entity.c
@@ -448,6 +448,12 @@ struct drm_sched_job *drm_sched_entity_pop_job(struct drm_sched_entity *entity)
 			drm_sched_rq_update_fifo(entity, next->submit_ts);
 	}
 
+	/* Jobs and entities might have different lifecycles. Since we're
+	 * removing the job from the entities queue, set the jobs entity pointer
+	 * to NULL to prevent any future access of the entity through this job.
+	 */
+	sched_job->entity = NULL;
+
 	return sched_job;
 }
 
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2023-04-11 20:13 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-31  0:06 [PATCH] drm/scheduler: set entity to NULL in drm_sched_entity_pop_job() Danilo Krummrich
2023-03-31  0:06 ` Danilo Krummrich
2023-03-31  5:59 ` Christian König
2023-03-31  5:59   ` Christian König
2023-03-31 12:57   ` Luben Tuikov
2023-03-31 12:57     ` Luben Tuikov
2023-04-05 17:39   ` Luben Tuikov
2023-04-05 17:39     ` Luben Tuikov
2023-04-11 18:13     ` Danilo Krummrich
2023-04-11 18:13       ` Danilo Krummrich
2023-04-11 20:06       ` Luben Tuikov
2023-04-11 20:06         ` Luben Tuikov

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.