drm/amdgpu: Fix use-after-free in amdgpu_cs_ioctl
Subsystems (2)
PATCH 1/1 drm/amdgpu: Fix use-after-free in amdgpu_cs_ioctl
Hello,
This patch is reviewed by Andrey and Christian and pushed into bringup temp branch. It need to be cherry-picked to drm-next, too. Does anyone has any comments on this patch?
Thanks,
Yubiao Wang
[Why]
In amdgpu_cs_ioctl, amdgpu_job_free could be performed ealier if there is -ERESTARTSYS error. In this case, job->hw_fence could be not initialized yet. Putting hw_fence during amdgpu_job_free could lead to a use-after-free warning.
[How]
Check if drm_sched_job_init is performed before job_free by checking s_fence.
v2: Check hw_fence.ops instead since it could be NULL if fence is not initialized. Reverse the condition since !=NULL check is discouraged in kernel.
Signed-off-by YuBiao Wang <[email protected]>
Reviewed-by Andrey Grodzovsky <[email protected]>
--- drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +4 -1
@@ -162,7 +162,10 @@ void amdgpu_job_free(struct amdgpu_job *job)amdgpu_sync_free (&job->sync);amdgpu_sync_free (&job->sched_sync); -dma_fence_put (&job->hw_fence); +if (!job->hw_fence.ops) +kfree (job); +else +dma_fence_put (&job->hw_fence); } int amdgpu_job_submit(struct amdgpu_job *job, struct drm_sched_entity *entity,
Signature · 1 line
2.25.1