Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: bfa3357ef9ab ("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

authored by

Christian König and committed by
Alex Deucher
c92db8d6 5598d7c2

+9 -9
+9 -9
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
··· 515 515 goto out; 516 516 } 517 517 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 + 518 527 if (adev->mman.buffer_funcs_enabled) { 519 528 if (((old_mem->mem_type == TTM_PL_SYSTEM && 520 529 new_mem->mem_type == TTM_PL_VRAM) || ··· 552 543 r = ttm_bo_move_memcpy(bo, ctx, new_mem); 553 544 if (r) 554 545 return r; 555 - } 556 - 557 - if (bo->type == ttm_bo_type_device && 558 - new_mem->mem_type == TTM_PL_VRAM && 559 - old_mem->mem_type != TTM_PL_VRAM) { 560 - /* amdgpu_bo_fault_reserve_notify will re-set this if the CPU 561 - * accesses the BO after it's moved. 562 - */ 563 - abo->flags &= ~AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED; 564 546 } 565 547 566 548 out: