Skip to content

Commit 14a14da

Browse files
zackrgregkh
authored andcommitted
drm/vmwgfx: Stop accessing buffer objects which failed init
commit 1a68979 upstream. ttm_bo_init_reserved on failure puts the buffer object back which causes it to be deleted, but kfree was still being called on the same buffer in vmw_bo_create leading to a double free. After the double free the vmw_gem_object_create_with_handle was setting the gem function objects before checking the return status of vmw_bo_create leading to null pointer access. Fix the entire path by relaying on ttm_bo_init_reserved to delete the buffer objects on failure and making sure the return status is checked before setting the gem function objects on the buffer object. Signed-off-by: Zack Rusin <[email protected]> Fixes: 8afa13a ("drm/vmwgfx: Implement DRIVER_GEM") Reviewed-by: Maaz Mombasawala <[email protected]> Reviewed-by: Martin Krastev <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected] (cherry picked from commit 36d421e) Cc: <[email protected]> # v5.17+ Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 020ecca commit 14a14da

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

drivers/gpu/drm/vmwgfx/vmwgfx_bo.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,9 @@ int vmw_bo_create(struct vmw_private *vmw,
462462
return -ENOMEM;
463463
}
464464

465+
/*
466+
* vmw_bo_init will delete the *p_bo object if it fails
467+
*/
465468
ret = vmw_bo_init(vmw, *p_bo, size,
466469
placement, interruptible, pin,
467470
bo_free);
@@ -470,7 +473,6 @@ int vmw_bo_create(struct vmw_private *vmw,
470473

471474
return ret;
472475
out_error:
473-
kfree(*p_bo);
474476
*p_bo = NULL;
475477
return ret;
476478
}

drivers/gpu/drm/vmwgfx/vmwgfx_gem.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,11 @@ int vmw_gem_object_create_with_handle(struct vmw_private *dev_priv,
146146
&vmw_sys_placement :
147147
&vmw_vram_sys_placement,
148148
true, false, &vmw_gem_destroy, p_vbo);
149-
150-
(*p_vbo)->base.base.funcs = &vmw_gem_object_funcs;
151149
if (ret != 0)
152150
goto out_no_bo;
153151

152+
(*p_vbo)->base.base.funcs = &vmw_gem_object_funcs;
153+
154154
ret = drm_gem_handle_create(filp, &(*p_vbo)->base.base, handle);
155155
/* drop reference from allocate - handle holds it now */
156156
drm_gem_object_put(&(*p_vbo)->base.base);

0 commit comments

Comments
 (0)