Skip to content

Commit 2c1030f

Browse files
amd-alysaliualexdeucher
authored andcommitted
drm/amdgpu: Fix use-after-free race in VM acquire
Replace non-atomic vm->process_info assignment with cmpxchg() to prevent race when parent/child processes sharing a drm_file both try to acquire the same VM after fork(). Reviewed-by: Harish Kasiviswanathan <Harish.Kasiviswanathan@amd.com> Signed-off-by: Alysa Liu <Alysa.Liu@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com> (cherry picked from commit c7c5732) Cc: stable@vger.kernel.org
1 parent 68785c5 commit 2c1030f

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1439,7 +1439,10 @@ static int init_kfd_vm(struct amdgpu_vm *vm, void **process_info,
14391439
*process_info = info;
14401440
}
14411441

1442-
vm->process_info = *process_info;
1442+
if (cmpxchg(&vm->process_info, NULL, *process_info) != NULL) {
1443+
ret = -EINVAL;
1444+
goto already_acquired;
1445+
}
14431446

14441447
/* Validate page directory and attach eviction fence */
14451448
ret = amdgpu_bo_reserve(vm->root.bo, true);
@@ -1479,6 +1482,7 @@ static int init_kfd_vm(struct amdgpu_vm *vm, void **process_info,
14791482
amdgpu_bo_unreserve(vm->root.bo);
14801483
reserve_pd_fail:
14811484
vm->process_info = NULL;
1485+
already_acquired:
14821486
if (info) {
14831487
dma_fence_put(&info->eviction_fence->base);
14841488
*process_info = NULL;

0 commit comments

Comments
 (0)