Skip to content

Commit 36d421e

Browse files
committed
drm/vmwgfx: Stop accessing buffer objects which failed init
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]
1 parent a44df74 commit 36d421e

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
@@ -416,13 +416,15 @@ int vmw_bo_create(struct vmw_private *vmw,
416416
return -ENOMEM;
417417
}
418418

419+
/*
420+
* vmw_bo_init will delete the *p_bo object if it fails
421+
*/
419422
ret = vmw_bo_init(vmw, *p_bo, params, vmw_bo_free);
420423
if (unlikely(ret != 0))
421424
goto out_error;
422425

423426
return ret;
424427
out_error:
425-
kfree(*p_bo);
426428
*p_bo = NULL;
427429
return ret;
428430
}

drivers/gpu/drm/vmwgfx/vmwgfx_gem.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,11 @@ int vmw_gem_object_create_with_handle(struct vmw_private *dev_priv,
127127
};
128128

129129
ret = vmw_bo_create(dev_priv, &params, p_vbo);
130-
131-
(*p_vbo)->tbo.base.funcs = &vmw_gem_object_funcs;
132130
if (ret != 0)
133131
goto out_no_bo;
134132

133+
(*p_vbo)->tbo.base.funcs = &vmw_gem_object_funcs;
134+
135135
ret = drm_gem_handle_create(filp, &(*p_vbo)->tbo.base, handle);
136136
/* drop reference from allocate - handle holds it now */
137137
drm_gem_object_put(&(*p_vbo)->tbo.base);

0 commit comments

Comments
 (0)