Skip to content

Commit c92db8d

Browse files
ChristianKoenigAMDalexdeucher
authored andcommitted
drm/amdgpu: fix use after free during BO move
The memory backing old_mem is already freed at that point, move the check a bit more up. Signed-off-by: Christian König <christian.koenig@amd.com> Fixes: bfa3357 ("drm/ttm: allocate resource object instead of embedding it v2") Bug: https://gitlab.freedesktop.org/drm/amd/-/issues/1699 Acked-by: Nirmoy Das <nirmoy.das@amd.com> Reviewed-by: Michel Dänzer <mdaenzer@redhat.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com> Cc: stable@vger.kernel.org
1 parent 5598d7c commit c92db8d

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

‎drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,15 @@ static int amdgpu_bo_move(struct ttm_buffer_object *bo, bool evict,
515515
goto out;
516516
}
517517

518+
if (bo->type == ttm_bo_type_device &&
519+
new_mem->mem_type == TTM_PL_VRAM &&
520+
old_mem->mem_type != TTM_PL_VRAM) {
521+
/* amdgpu_bo_fault_reserve_notify will re-set this if the CPU
522+
* accesses the BO after it's moved.
523+
*/
524+
abo->flags &= ~AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED;
525+
}
526+
518527
if (adev->mman.buffer_funcs_enabled) {
519528
if (((old_mem->mem_type == TTM_PL_SYSTEM &&
520529
new_mem->mem_type == TTM_PL_VRAM) ||
@@ -545,15 +554,6 @@ static int amdgpu_bo_move(struct ttm_buffer_object *bo, bool evict,
545554
return r;
546555
}
547556

548-
if (bo->type == ttm_bo_type_device &&
549-
new_mem->mem_type == TTM_PL_VRAM &&
550-
old_mem->mem_type != TTM_PL_VRAM) {
551-
/* amdgpu_bo_fault_reserve_notify will re-set this if the CPU
552-
* accesses the BO after it's moved.
553-
*/
554-
abo->flags &= ~AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED;
555-
}
556-
557557
out:
558558
/* update statistics */
559559
atomic64_add(bo->base.size, &adev->num_bytes_moved);

0 commit comments

Comments
 (0)