Skip to contentSkip to conversation

accel/amdxdna: Remove drv_cmd tracing from job free callback

PATCH In review Lizhi Hou 3 participants 5 messages May 29 – Jun 3

Subsystems (2)
lore
Share & tools
lore

Lizhi Hou

author maintainer
#0 lore raw

PATCH 1/1 accel/amdxdna: Remove drv_cmd tracing from job free callback

aie2_sched_job_free() accesses job->drv_cmd for tracing purposes. However, job->drv_cmd is owned by the caller and may already have been freed when the job free callback runs, leading to a potential use-after-free.

Remove the job->drv_cmd access from aie2_sched_job_free().

Fixes 8711eb2dde2e ("accel/amdxdna: Improve tracing for job lifecycle and mailbox RX worker")
---
 drivers/accel/amdxdna/aie2_ctx.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/accel/amdxdna/aie2_ctx.c +2 -1
index 658a5fb1fda6..2ad343728782 100644
@@ -437,8 +437,9 @@ static void aie2_sched_job_free(struct drm_sched_job *sched_job)
 	struct amdxdna_sched_job *job = drm_job_to_xdna_job(sched_job);
 	struct amdxdna_hwctx *hwctx = job->hwctx;
 
+	/* job->drv_cmd could be freed, so use DEFAULT_IO */
 	trace_xdna_job(sched_job, hwctx->name, "job free",
-		       job->seq, job->drv_cmd ? job->drv_cmd->opcode : DEFAULT_IO);
+		       job->seq, DEFAULT_IO);
 	if (!job->job_done)
 		up(&hwctx->priv->job_sem);
 
Signature · 1 line
2.34.1
#1 lore raw
Quoted 17 lines · Lizhi Hou

aie2_sched_job_free() accesses job->drv_cmd for tracing purposes. However, job->drv_cmd is owned by the caller and may already have been freed when the job free callback runs, leading to a potential use-after-free.

Remove the job->drv_cmd access from aie2_sched_job_free().

Fixes 8711eb2dde2e ("accel/amdxdna: Improve tracing for job lifecycle and mailbox RX worker")
---
  drivers/accel/amdxdna/aie2_ctx.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
drivers/accel/amdxdna/aie2_ctx.c +0 -0
index 658a5fb1fda6..2ad343728782 100644

drivers/accel/amdxdna/aie2_ctx.c static void aie2_sched_job_free(struct drm_sched_job *sched_job) · line 442

Quoted 7 lines
drivers/accel/amdxdna/aie2_ctx.c +2 -1
@@ -437,8 +437,9 @@ static void aie2_sched_job_free(struct drm_sched_job *sched_job)
  	struct amdxdna_sched_job *job = drm_job_to_xdna_job(sched_job);
  	struct amdxdna_hwctx *hwctx = job->hwctx;
 
+	/* job->drv_cmd could be freed, so use DEFAULT_IO */
  	trace_xdna_job(sched_job, hwctx->name, "job free",
-		       job->seq, job->drv_cmd ? job->drv_cmd->opcode : DEFAULT_IO);
+		       job->seq, DEFAULT_IO);

Could this still be a race with dov->drv_cmd being valid when the first part of the expression is evaluated (job->drv_cmd) but invalid when job->drv_cmd->opcode is accessed?

Quoted 3 lines
drivers/accel/amdxdna/aie2_ctx.c +0 -0
  	if (!job->job_done)
  		up(&hwctx->priv->job_sem);
 
author maintainer
#2 lore raw
Quoted 15 lines · Mario Limonciello
Quoted 12 lines · Lizhi Hou

aie2_sched_job_free() accesses job->drv_cmd for tracing purposes. However, job->drv_cmd is owned by the caller and may already have been freed when the job free callback runs, leading to a potential use-after-free.

Remove the job->drv_cmd access from aie2_sched_job_free().

Fixes 8711eb2dde2e ("accel/amdxdna: Improve tracing for job lifecycle and mailbox RX worker")

---
  drivers/accel/amdxdna/aie2_ctx.c | 3 ++-

  1 file changed, 2 insertions(+), 1 deletion(-)
Quoted 15 lines
Quoted 8 lines
drivers/accel/amdxdna/aie2_ctx.c +0 -0
index 658a5fb1fda6..2ad343728782 100644
@@ -437,8 +437,9 @@ static void aie2_sched_job_free(struct 
 drm_sched_job *sched_job)
       struct amdxdna_sched_job *job = drm_job_to_xdna_job(sched_job);
       struct amdxdna_hwctx *hwctx = job->hwctx;
Quoted 5 lines

  +    /* job->drv_cmd could be freed, so use DEFAULT_IO */ trace_xdna_job(sched_job, hwctx->name, "job free", -               job->seq, job->drv_cmd ? job->drv_cmd->opcode :
DEFAULT_IO);
+               job->seq, DEFAULT_IO);

Could this still be a race with dov->drv_cmd being valid when the first part of the expression is evaluated (job->drv_cmd) but invalid when job->drv_cmd->opcode is accessed?

When aie2_sched_job_free() is called, the job->drv_cmd could already be freed. So it should never access job->drv_cmd at all. The entire expression "job->drv_cmd ? job->drv_cmd->opcode :  DEFAULT_IO" is removed.

Lizhi

Quoted 4 lines
Quoted 3 lines

      if (!job->job_done)
          up(&hwctx->priv->job_sem);

Reviewed-by
#3 lore raw
Quoted 33 lines · Lizhi Hou
Quoted 15 lines · Mario Limonciello
Quoted 12 lines · Lizhi Hou

aie2_sched_job_free() accesses job->drv_cmd for tracing purposes. However, job->drv_cmd is owned by the caller and may already have been freed when the job free callback runs, leading to a potential use-after-free.

Remove the job->drv_cmd access from aie2_sched_job_free().

Fixes 8711eb2dde2e ("accel/amdxdna: Improve tracing for job lifecycle and mailbox RX worker")

---
  drivers/accel/amdxdna/aie2_ctx.c | 3 ++-

  1 file changed, 2 insertions(+), 1 deletion(-)
Quoted 15 lines
Quoted 8 lines
drivers/accel/amdxdna/aie2_ctx.c +0 -0
index 658a5fb1fda6..2ad343728782 100644
@@ -437,8 +437,9 @@ static void aie2_sched_job_free(struct 
 drm_sched_job *sched_job)
       struct amdxdna_sched_job *job = drm_job_to_xdna_job(sched_job);
       struct amdxdna_hwctx *hwctx = job->hwctx;
Quoted 5 lines

  +    /* job->drv_cmd could be freed, so use DEFAULT_IO */ trace_xdna_job(sched_job, hwctx->name, "job free", -               job->seq, job->drv_cmd ? job->drv_cmd->opcode :
DEFAULT_IO);
+               job->seq, DEFAULT_IO);

Could this still be a race with dov->drv_cmd being valid when the first part of the expression is evaluated (job->drv_cmd) but invalid when job->drv_cmd->opcode is accessed?

Quoted 1 line

When aie2_sched_job_free() is called, the job->drv_cmd could already be freed. So it should never access job->drv_cmd at all. The entire expression "job->drv_cmd ? job->drv_cmd->opcode :  DEFAULT_IO" is removed.

Quoted 7 lines

Lizhi

Quoted 4 lines
Quoted 3 lines

      if (!job->job_done)
          up(&hwctx->priv->job_sem);

author maintainer Applied
#4 lore raw

Applied to drm-misc-next-fixes

Quoted 46 lines · Mario Limonciello
Quoted 33 lines · Lizhi Hou
Quoted 15 lines · Mario Limonciello
Quoted 12 lines · Lizhi Hou

aie2_sched_job_free() accesses job->drv_cmd for tracing purposes. However, job->drv_cmd is owned by the caller and may already have been freed when the job free callback runs, leading to a potential use-after-free.

Remove the job->drv_cmd access from aie2_sched_job_free().

Fixes 8711eb2dde2e ("accel/amdxdna: Improve tracing for job lifecycle and mailbox RX worker")

---
  drivers/accel/amdxdna/aie2_ctx.c | 3 ++-

  1 file changed, 2 insertions(+), 1 deletion(-)
Quoted 15 lines
Quoted 8 lines
drivers/accel/amdxdna/aie2_ctx.c +0 -0
index 658a5fb1fda6..2ad343728782 100644
@@ -437,8 +437,9 @@ static void aie2_sched_job_free(struct 
 drm_sched_job *sched_job)
       struct amdxdna_sched_job *job = drm_job_to_xdna_job(sched_job);
       struct amdxdna_hwctx *hwctx = job->hwctx;
Quoted 5 lines

  +    /* job->drv_cmd could be freed, so use DEFAULT_IO */ trace_xdna_job(sched_job, hwctx->name, "job free", -               job->seq, job->drv_cmd ? job->drv_cmd->opcode :
DEFAULT_IO);
+               job->seq, DEFAULT_IO);

Could this still be a race with dov->drv_cmd being valid when the first part of the expression is evaluated (job->drv_cmd) but invalid when job->drv_cmd->opcode is accessed?

Quoted 1 line

When aie2_sched_job_free() is called, the job->drv_cmd could already be freed. So it should never access job->drv_cmd at all. The entire expression "job->drv_cmd ? job->drv_cmd->opcode :  DEFAULT_IO" is removed.

Quoted 7 lines

Lizhi

Quoted 4 lines
Quoted 3 lines

      if (!job->job_done)
          up(&hwctx->priv->job_sem);