mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH V1] accel/amdxdna: Fix use-after-free of mm_struct in job scheduler
@ 2026-07-16 15:13 Lizhi Hou
  2026-07-16 15:27 ` Max Zhen
  0 siblings, 1 reply; 2+ messages in thread
From: Lizhi Hou @ 2026-07-16 15:13 UTC (permalink / raw)
  To: ogabbay, quic_jhugo, dri-devel, mario.limonciello, karol.wachowski
  Cc: Lizhi Hou, linux-kernel, max.zhen, sonal.santan

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: aac243092b70 ("accel/amdxdna: Add command execution")
Signed-off-by: Lizhi Hou <lizhi.hou@amd.com>
---
 drivers/accel/amdxdna/amdxdna_ctx.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/accel/amdxdna/amdxdna_ctx.c b/drivers/accel/amdxdna/amdxdna_ctx.c
index bdbd3db12a6c..31a414c3f0d9 100644
--- a/drivers/accel/amdxdna/amdxdna_ctx.c
+++ b/drivers/accel/amdxdna/amdxdna_ctx.c
@@ -577,6 +577,7 @@ void amdxdna_sched_job_cleanup(struct amdxdna_sched_job *job)
 	amdxdna_arg_bos_put(job);
 	amdxdna_gem_put_obj(job->cmd_bo);
 	dma_fence_put(job->fence);
+	mmdrop(job->mm);
 }
 
 int amdxdna_cmd_submit(struct amdxdna_client *client,
@@ -642,6 +643,7 @@ int amdxdna_cmd_submit(struct amdxdna_client *client,
 
 	job->hwctx = hwctx;
 	job->mm = current->mm;
+	mmgrab(job->mm);
 
 	job->fence = amdxdna_fence_create(hwctx);
 	if (!job->fence) {
@@ -676,6 +678,8 @@ int amdxdna_cmd_submit(struct amdxdna_client *client,
 cmd_put:
 	amdxdna_gem_put_obj(job->cmd_bo);
 free_job:
+	if (job->mm)
+		mmdrop(job->mm);
 	kfree(job);
 	return ret;
 }
-- 
2.34.1


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

* Re: [PATCH V1] accel/amdxdna: Fix use-after-free of mm_struct in job scheduler
  2026-07-16 15:13 [PATCH V1] accel/amdxdna: Fix use-after-free of mm_struct in job scheduler Lizhi Hou
@ 2026-07-16 15:27 ` Max Zhen
  0 siblings, 0 replies; 2+ messages in thread
From: Max Zhen @ 2026-07-16 15:27 UTC (permalink / raw)
  To: Lizhi Hou, ogabbay, quic_jhugo, dri-devel, mario.limonciello,
	karol.wachowski
  Cc: linux-kernel, sonal.santan



On 7/16/2026 Thu 08:13, Lizhi Hou wrote:
> 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: aac243092b70 ("accel/amdxdna: Add command execution")
> Signed-off-by: Lizhi Hou <lizhi.hou@amd.com>
Reviewed-by: Max Zhen <max.zhen@amd.com>
> ---
>   drivers/accel/amdxdna/amdxdna_ctx.c | 4 ++++
>   1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/accel/amdxdna/amdxdna_ctx.c b/drivers/accel/amdxdna/amdxdna_ctx.c
> index bdbd3db12a6c..31a414c3f0d9 100644
> --- a/drivers/accel/amdxdna/amdxdna_ctx.c
> +++ b/drivers/accel/amdxdna/amdxdna_ctx.c
> @@ -577,6 +577,7 @@ void amdxdna_sched_job_cleanup(struct amdxdna_sched_job *job)
>   	amdxdna_arg_bos_put(job);
>   	amdxdna_gem_put_obj(job->cmd_bo);
>   	dma_fence_put(job->fence);
> +	mmdrop(job->mm);
>   }
>   
>   int amdxdna_cmd_submit(struct amdxdna_client *client,
> @@ -642,6 +643,7 @@ int amdxdna_cmd_submit(struct amdxdna_client *client,
>   
>   	job->hwctx = hwctx;
>   	job->mm = current->mm;
> +	mmgrab(job->mm);
>   
>   	job->fence = amdxdna_fence_create(hwctx);
>   	if (!job->fence) {
> @@ -676,6 +678,8 @@ int amdxdna_cmd_submit(struct amdxdna_client *client,
>   cmd_put:
>   	amdxdna_gem_put_obj(job->cmd_bo);
>   free_job:
> +	if (job->mm)
> +		mmdrop(job->mm);
>   	kfree(job);
>   	return ret;
>   }


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

end of thread, other threads:[~2026-07-16 15:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-07-16 15:13 [PATCH V1] accel/amdxdna: Fix use-after-free of mm_struct in job scheduler Lizhi Hou
2026-07-16 15:27 ` Max Zhen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome