Skip to content

Commit faebb7b

Browse files
committed
accel/amdxdna: Fix use-after-free of mm_struct in job scheduler
amdxdna_cmd_submit() stores current->mm in job->mm without holding any reference. aie2_sched_job_run() later access job->mm from the DRM scheduler worker thread. With only a raw pointer and no structural reference, the mm_struct can be freed before the scheduler runs the job. Fix this by calling mmgrab() to hold a structural mm_count reference for the lifetime of the job, paired with mmdrop() in every cleanup path. Fixes: aac2430 ("accel/amdxdna: Add command execution") Reviewed-by: Max Zhen <max.zhen@amd.com> Signed-off-by: Lizhi Hou <lizhi.hou@amd.com> Link: https://patch.msgid.link/20260716151305.1595780-1-lizhi.hou@amd.com
1 parent 266cddf commit faebb7b

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

drivers/accel/amdxdna/amdxdna_ctx.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,7 @@ void amdxdna_sched_job_cleanup(struct amdxdna_sched_job *job)
577577
amdxdna_arg_bos_put(job);
578578
amdxdna_gem_put_obj(job->cmd_bo);
579579
dma_fence_put(job->fence);
580+
mmdrop(job->mm);
580581
}
581582

582583
int amdxdna_cmd_submit(struct amdxdna_client *client,
@@ -642,6 +643,7 @@ int amdxdna_cmd_submit(struct amdxdna_client *client,
642643

643644
job->hwctx = hwctx;
644645
job->mm = current->mm;
646+
mmgrab(job->mm);
645647

646648
job->fence = amdxdna_fence_create(hwctx);
647649
if (!job->fence) {
@@ -676,6 +678,8 @@ int amdxdna_cmd_submit(struct amdxdna_client *client,
676678
cmd_put:
677679
amdxdna_gem_put_obj(job->cmd_bo);
678680
free_job:
681+
if (job->mm)
682+
mmdrop(job->mm);
679683
kfree(job);
680684
return ret;
681685
}

0 commit comments

Comments
 (0)