drm/vmwgfx: Do not drop the reference to the handle too soon
Subsystems (4)
PATCH v2 1/1 drm/vmwgfx: Do not drop the reference to the handle too soon
From: Zack Rusin <[email protected]>
v2: Update the commit message to include note describing why the second usag of vmw_gem_object_create_with_handle in vmwgfx_surface.c wasn't changed
It is possible for userspace to predict the next buffer handle and to destroy the buffer while it's still used by the kernel. Delay dropping the internal reference on the buffers until kernel is done with them.
Also fixes the second usage of vmw_gem_object_create_with_handle in vmwgfx_surface.c which wasn't grabbing an explicit reference to the gem object which could have been destroyed by the userspace on the owning surface at any point.
--- drivers/gpu/drm/vmwgfx/vmwgfx_bo.c | 3 ++- drivers/gpu/drm/vmwgfx/vmwgfx_gem.c | 4 ++-- drivers/gpu/drm/vmwgfx/vmwgfx_surface.c | 1 - 3 files changed, 4 insertions(+), 4 deletions(-)
drivers/gpu/drm/vmwgfx/vmwgfx_bo.c +2 -1
@@ -708,7 +708,8 @@ int vmw_dumb_create(struct drm_file *file_priv, ret =vmw_gem_object_create_with_handle (dev_priv, file_priv, args->size, &args->handle, &vbo); - +/* drop reference from allocate - handle holds it now */ +drm_gem_object_put (&vbo->tbo.base);return ret; }
drivers/gpu/drm/vmwgfx/vmwgfx_gem.c +2 -2
@@ -133,8 +133,6 @@ int vmw_gem_object_create_with_handle(struct vmw_private *dev_priv, (*p_vbo)->tbo.base.funcs = &vmw_gem_object_funcs; ret =drm_gem_handle_create (filp, &(*p_vbo)->tbo.base, handle); -/* drop reference from allocate - handle holds it now */ -drm_gem_object_put (&(*p_vbo)->tbo.base); out_no_bo:return ret; }
@@ -161,6 +159,8 @@ int vmw_gem_object_create_ioctl(struct drm_device *dev, void *data, rep->map_handle =drm_vma_node_offset_addr (&vbo->tbo.base.vma_node); rep->cur_gmr_id = handle; rep->cur_gmr_offset =0 ; +/* drop reference from allocate - handle holds it now */ +drm_gem_object_put (&vbo->tbo.base); out_no_bo:return ret; }
drivers/gpu/drm/vmwgfx/vmwgfx_surface.c +0 -1
@@ -867,7 +867,6 @@ int vmw_surface_define_ioctl(struct drm_device *dev, void *data, goto out_unlock; }vmw_bo_reference (res->guest_memory_bo); -drm_gem_object_get (&res->guest_memory_bo->tbo.base); } tmp =vmw_resource_reference (&srf->res);
Signature · 1 line
2.38.1
From: Martin Krastev <[email protected]>
LGTM
Regards,
Martin
Quoted 73 lines · Zack Rusin
From: Zack Rusin <[email protected]>
v2: Update the commit message to include note describing why the second usag of
vmw_gem_object_create_with_handleinvmwgfx_surface.cwasn't changedIt is possible for userspace to predict the next buffer handle and to destroy the buffer while it's still used by the kernel. Delay dropping the internal reference on the buffers until kernel is done with them.
Also fixes the second usage of
vmw_gem_object_create_with_handleinvmwgfx_surface.cwhich wasn't grabbing an explicit reference to the gem object which could have been destroyed by the userspace on the owning surface at any point.Signed-off-by Zack Rusin <[email protected]>Fixes 8afa13a0583f ("drm/vmwgfx: Implement DRIVER_GEM")Cc <[email protected]> # v5.17+--- drivers/gpu/drm/vmwgfx/vmwgfx_bo.c | 3 ++- drivers/gpu/drm/vmwgfx/vmwgfx_gem.c | 4 ++-- drivers/gpu/drm/vmwgfx/vmwgfx_surface.c | 1 - 3 files changed, 4 insertions(+), 4 deletions(-)drivers/gpu/drm/vmwgfx/vmwgfx_bo.c +2
-1@@ -708,7 +708,8 @@ int vmw_dumb_create(struct drm_file *file_priv, ret =vmw_gem_object_create_with_handle (dev_priv, file_priv, args->size, &args->handle, &vbo); - +/* drop reference from allocate - handle holds it now */ +drm_gem_object_put (&vbo->tbo.base);return ret; }drivers/gpu/drm/vmwgfx/vmwgfx_gem.c +2
-2@@ -133,8 +133,6 @@ int vmw_gem_object_create_with_handle(struct vmw_private *dev_priv, (*p_vbo)->tbo.base.funcs = &vmw_gem_object_funcs; ret =drm_gem_handle_create (filp, &(*p_vbo)->tbo.base, handle); -/* drop reference from allocate - handle holds it now */ -drm_gem_object_put (&(*p_vbo)->tbo.base); out_no_bo:return ret; }@@ -161,6 +159,8 @@ int vmw_gem_object_create_ioctl(struct drm_device *dev, void *data, rep->map_handle =drm_vma_node_offset_addr (&vbo->tbo.base.vma_node); rep->cur_gmr_id = handle; rep->cur_gmr_offset =0 ; +/* drop reference from allocate - handle holds it now */ +drm_gem_object_put (&vbo->tbo.base); out_no_bo:return ret; }drivers/gpu/drm/vmwgfx/vmwgfx_surface.c +0
-1@@ -867,7 +867,6 @@ int vmw_surface_define_ioctl(struct drm_device *dev, void *data, goto out_unlock; }vmw_bo_reference (res->guest_memory_bo); -drm_gem_object_get (&res->guest_memory_bo->tbo.base); } tmp =vmw_resource_reference (&srf->res);