drm/radeon: check bo_va->bo is non-NULL before using it
Subsystems (2)
PATCH 1/1 drm/radeon: check bo_va->bo is non-NULL before using it
The call to radeon_vm_clear_freed might clear bo_va->bo, so we have to check it before dereferencing it.
--- drivers/gpu/drm/radeon/radeon_gem.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/gpu/drm/radeon/radeon_gem.c +10 -1
@@ -641,8 +641,17 @@ static void radeon_gem_va_update_vm(struct radeon_device *rdev,if (r) goto error_unlock; -if (bo_va->it.start) +if (bo_va->it.start) { +if (bo_va->bo ==NULL ) { +/* Buggy userspace can try to use RADEON_VA_UNMAP after +* closing the BO. In this case, radeon_vm_clear_freed +* will unset bo_va->bo. +*/ + r = -ENOENT ; + goto error_unlock; + } r =radeon_vm_bo_update (rdev, bo_va, bo_va->bo->tbo.resource); + } error_unlock:mutex_unlock (&bo_va->vm->mutex);
Signature · 1 line
2.45.2
Christian König
maintainerAm 25.06.24 um 14:41 schrieb Pierre-Eric Pelloux-Prayer:
Quoted 13 lines
The call to
radeon_vm_clear_freedmight clearbo_va->bo, so we have to check it before dereferencing it.Signed-off-by Pierre-Eric Pelloux-Prayer <[email protected]>--- drivers/gpu/drm/radeon/radeon_gem.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)drivers/gpu/drm/radeon/radeon_gem.c +0
-0
drivers/gpu/drm/radeon/radeon_gem.c static void radeon_gem_va_update_vm(struct radeon_device *rdev, · line 645
Quoted 6 lines
drivers/gpu/drm/radeon/radeon_gem.c +2
-1@@ -641,8 +641,17 @@ static void radeon_gem_va_update_vm(struct radeon_device *rdev,if (r) goto error_unlock; -if (bo_va->it.start) +if (bo_va->it.start) { +if (bo_va->bo ==NULL ) {
In the kernel you should probably use !bo_va->bo instead.
drivers/gpu/drm/radeon/radeon_gem.c static void radeon_gem_va_update_vm(struct radeon_device *rdev, · line 649
Quoted 4 lines
drivers/gpu/drm/radeon/radeon_gem.c +4
-0+/* Buggy userspace can try to use RADEON_VA_UNMAP after +* closing the BO. In this case, radeon_vm_clear_freed +* will unset bo_va->bo. +*/
I think you can drop that comment, it's perfectly valid for userspace to unmap a region after closing the BO.
It's just that the radeon VM support was never designed very well.
Regards,
Christian.
Quoted 8 lines
drivers/gpu/drm/radeon/radeon_gem.c +4
-0+ r = -ENOENT ; + goto error_unlock; + } r =radeon_vm_bo_update (rdev, bo_va, bo_va->bo->tbo.resource); + } error_unlock:mutex_unlock (&bo_va->vm->mutex);