Skip to content

Commit 1e1d357

Browse files
asahilinaLuben Tuikov
authored andcommitted
drm/scheduler: Fix UAF race in drm_sched_entity_push_job()
After a job is pushed into the queue, it is owned by the scheduler core and may be freed at any time, so we can't write nor read the submit timestamp after that point. Fixes oopses observed with the drm/asahi driver, found with kASAN. Signed-off-by: Asahi Lina <[email protected]> Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Luben Tuikov <[email protected]> Signed-off-by: Luben Tuikov <[email protected]>
1 parent 0ec8671 commit 1e1d357

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

drivers/gpu/drm/scheduler/sched_entity.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -507,12 +507,19 @@ void drm_sched_entity_push_job(struct drm_sched_job *sched_job)
507507
{
508508
struct drm_sched_entity *entity = sched_job->entity;
509509
bool first;
510+
ktime_t submit_ts;
510511

511512
trace_drm_sched_job(sched_job, entity);
512513
atomic_inc(entity->rq->sched->score);
513514
WRITE_ONCE(entity->last_user, current->group_leader);
515+
516+
/*
517+
* After the sched_job is pushed into the entity queue, it may be
518+
* completed and freed up at any time. We can no longer access it.
519+
* Make sure to set the submit_ts first, to avoid a race.
520+
*/
521+
sched_job->submit_ts = submit_ts = ktime_get();
514522
first = spsc_queue_push(&entity->job_queue, &sched_job->queue_node);
515-
sched_job->submit_ts = ktime_get();
516523

517524
/* first job wakes up scheduler */
518525
if (first) {
@@ -529,7 +536,7 @@ void drm_sched_entity_push_job(struct drm_sched_job *sched_job)
529536
spin_unlock(&entity->rq_lock);
530537

531538
if (drm_sched_policy == DRM_SCHED_POLICY_FIFO)
532-
drm_sched_rq_update_fifo(entity, sched_job->submit_ts);
539+
drm_sched_rq_update_fifo(entity, submit_ts);
533540

534541
drm_sched_wakeup(entity->rq->sched);
535542
}

0 commit comments

Comments
 (0)