Skip to content

Commit 7427686

Browse files
Sinclair Yehgregkh
authored andcommitted
drm/vmwgfx: Make sure backup_handle is always valid
commit 07678eca2cf9c9a18584e546c2b2a0d0c9a3150c upstream. 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. Reported-by: Murray McAllister <murray.mcallister@insomniasec.com> Signed-off-by: Sinclair Yeh <syeh@vmware.com> Reviewed-by: Deepak Rawat <drawat@vmware.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 619cc02 commit 7427686

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

drivers/gpu/drm/vmwgfx/vmwgfx_surface.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1288,7 +1288,7 @@ int vmw_gb_surface_define_ioctl(struct drm_device *dev, void *data,
12881288
struct ttm_object_file *tfile = vmw_fpriv(file_priv)->tfile;
12891289
int ret;
12901290
uint32_t size;
1291-
uint32_t backup_handle;
1291+
uint32_t backup_handle = 0;
12921292

12931293
if (req->multisample_count != 0)
12941294
return -EINVAL;
@@ -1331,12 +1331,16 @@ int vmw_gb_surface_define_ioctl(struct drm_device *dev, void *data,
13311331
ret = vmw_user_dmabuf_lookup(tfile, req->buffer_handle,
13321332
&res->backup,
13331333
&user_srf->backup_base);
1334-
if (ret == 0 && res->backup->base.num_pages * PAGE_SIZE <
1335-
res->backup_size) {
1336-
DRM_ERROR("Surface backup buffer is too small.\n");
1337-
vmw_dmabuf_unreference(&res->backup);
1338-
ret = -EINVAL;
1339-
goto out_unlock;
1334+
if (ret == 0) {
1335+
if (res->backup->base.num_pages * PAGE_SIZE <
1336+
res->backup_size) {
1337+
DRM_ERROR("Surface backup buffer is too small.\n");
1338+
vmw_dmabuf_unreference(&res->backup);
1339+
ret = -EINVAL;
1340+
goto out_unlock;
1341+
} else {
1342+
backup_handle = req->buffer_handle;
1343+
}
13401344
}
13411345
} else if (req->drm_surface_flags & drm_vmw_surface_flag_create_buffer)
13421346
ret = vmw_user_dmabuf_alloc(dev_priv, tfile,

0 commit comments

Comments
 (0)