drm/amdgpu: fix GEM object leak on ENOMEM in userptr ioctl
Subsystems (3)
PATCH 1/1 drm/amdgpu: fix GEM object leak on ENOMEM in userptr ioctl
When amdgpu_hmm_range_alloc() fails amdgpu_gem_userptr_ioctl() returns -ENOMEM right away and skips the cleanup every other error path goes through. The GEM object, the bo->parent reference on the VM root and the MMU notifier registration are all left behind.
Use release_object here, not user_pages_done, range is still NULL at this point.
Fixes e095b55155ef ("drm/amdgpu: use user provided hmm_range buffer in amdgpu_ttm_tt_get_user_pages")
Signed-off-by Perry Yuan <[email protected]>
Reviewed-by Christian König <[email protected]>
--- drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +4 -2
@@ -576,8 +576,10 @@ int amdgpu_gem_userptr_ioctl(struct drm_device *dev, void *data,if (args->flags &AMDGPU_GEM_USERPTR_VALIDATE ) { range =amdgpu_hmm_range_alloc (NULL ); -if (unlikely (!range)) -return -ENOMEM ; +if (unlikely (!range)) { + r = -ENOMEM ; + goto release_object; + } r =amdgpu_ttm_tt_get_user_pages (bo, range);if (r) {amdgpu_hmm_range_free (range);
Signature · 1 line
2.34.1
PATCH 1/1 drm/amdkfd: Clear user_pages after freeing the array
Set mem->user_pages to NULL after freeing the temporary page-pointer array in amdgpu_amdkfd_gpuvm_free_memory_of_gpu().
Signed-off-by Perry Yuan <[email protected]>
Acked-by Christian König <[email protected]>
--- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 1 + 1 file changed, 1 insertion(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +1 -0
@@ -2068,6 +2068,7 @@ int amdgpu_amdkfd_gpuvm_free_memory_of_gpu( mem->bo->tbo.ttm->num_pages); kvfree(mem->user_pages); } + mem->user_pages =NULL ;#endif }
Signature · 1 line
2.34.1