Skip to content

Commit 07678ec

Browse files
Sinclair Yehthomashvmw
Sinclair Yeh
authored andcommitted
drm/vmwgfx: Make sure backup_handle is always valid
When vmw_gb_surface_define_ioctl() is called with an existing buffer, we end up returning an uninitialized variable in the backup_handle. The fix is to first initialize backup_handle to 0 just to be sure, and second, when a user-provided buffer is found, we will use the req->buffer_handle as the backup_handle. Cc: <stable@vger.kernel.org> Reported-by: Murray McAllister <murray.mcallister@insomniasec.com> Signed-off-by: Sinclair Yeh <syeh@vmware.com> Reviewed-by: Deepak Rawat <drawat@vmware.com>
1 parent f0c62e9 commit 07678ec

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

Diff for: drivers/gpu/drm/vmwgfx/vmwgfx_surface.c

+11-7
Original file line numberDiff line numberDiff line change
@@ -1274,7 +1274,7 @@ int vmw_gb_surface_define_ioctl(struct drm_device *dev, void *data,
12741274
struct ttm_object_file *tfile = vmw_fpriv(file_priv)->tfile;
12751275
int ret;
12761276
uint32_t size;
1277-
uint32_t backup_handle;
1277+
uint32_t backup_handle = 0;
12781278

12791279
if (req->multisample_count != 0)
12801280
return -EINVAL;
@@ -1317,12 +1317,16 @@ int vmw_gb_surface_define_ioctl(struct drm_device *dev, void *data,
13171317
ret = vmw_user_dmabuf_lookup(tfile, req->buffer_handle,
13181318
&res->backup,
13191319
&user_srf->backup_base);
1320-
if (ret == 0 && res->backup->base.num_pages * PAGE_SIZE <
1321-
res->backup_size) {
1322-
DRM_ERROR("Surface backup buffer is too small.\n");
1323-
vmw_dmabuf_unreference(&res->backup);
1324-
ret = -EINVAL;
1325-
goto out_unlock;
1320+
if (ret == 0) {
1321+
if (res->backup->base.num_pages * PAGE_SIZE <
1322+
res->backup_size) {
1323+
DRM_ERROR("Surface backup buffer is too small.\n");
1324+
vmw_dmabuf_unreference(&res->backup);
1325+
ret = -EINVAL;
1326+
goto out_unlock;
1327+
} else {
1328+
backup_handle = req->buffer_handle;
1329+
}
13261330
}
13271331
} else if (req->drm_surface_flags & drm_vmw_surface_flag_create_buffer)
13281332
ret = vmw_user_dmabuf_alloc(dev_priv, tfile,

0 commit comments

Comments
 (0)