Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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 <zackr@vmware.com>
Fixes: 8afa13a0583f ("drm/vmwgfx: Implement DRIVER_GEM")
Reviewed-by: Maaz Mombasawala <mombasawalam@vmware.com>
Reviewed-by: Martin Krastev <krastevm@vmware.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20230208180050.2093426-1-zack@kde.org
(cherry picked from commit 36d421e632e9a0e8375eaed0143551a34d81a7e3)
Cc: <stable@vger.kernel.org> # v5.17+

+5 -3
+3 -1
drivers/gpu/drm/vmwgfx/vmwgfx_bo.c
··· 462 462 return -ENOMEM; 463 463 } 464 464 465 + /* 466 + * vmw_bo_init will delete the *p_bo object if it fails 467 + */ 465 468 ret = vmw_bo_init(vmw, *p_bo, size, 466 469 placement, interruptible, pin, 467 470 bo_free); ··· 473 470 474 471 return ret; 475 472 out_error: 476 - kfree(*p_bo); 477 473 *p_bo = NULL; 478 474 return ret; 479 475 }
+2 -2
drivers/gpu/drm/vmwgfx/vmwgfx_gem.c
··· 146 146 &vmw_sys_placement : 147 147 &vmw_vram_sys_placement, 148 148 true, false, &vmw_gem_destroy, p_vbo); 149 - 150 - (*p_vbo)->base.base.funcs = &vmw_gem_object_funcs; 151 149 if (ret != 0) 152 150 goto out_no_bo; 151 + 152 + (*p_vbo)->base.base.funcs = &vmw_gem_object_funcs; 153 153 154 154 ret = drm_gem_handle_create(filp, &(*p_vbo)->base.base, handle); 155 155 /* drop reference from allocate - handle holds it now */