Skip to content

Commit 5ac2c02

Browse files
committed
drm/vmwgfx: Fix a null-ptr access in the cursor snooper
Check that the resource which is converted to a surface exists before trying to use the cursor snooper on it. vmw_cmd_res_check allows explicit invalid (SVGA3D_INVALID_ID) identifiers because some svga commands accept SVGA3D_INVALID_ID to mean "no surface", unfortunately functions that accept the actual surfaces as objects might (and in case of the cursor snooper, do not) be able to handle null objects. Make sure that we validate not only the identifier (via the vmw_cmd_res_check) but also check that the actual resource exists before trying to do something with it. Fixes unchecked null-ptr reference in the snooping code. Signed-off-by: Zack Rusin <[email protected]> Fixes: c0951b7 ("drm/vmwgfx: Refactor resource management") Reported-by: Kuzey Arda Bulut <[email protected]> Cc: Broadcom internal kernel review list <[email protected]> Cc: [email protected] Reviewed-by: Ian Forbes <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 7d9c344 commit 5ac2c02

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1497,6 +1497,7 @@ static int vmw_cmd_dma(struct vmw_private *dev_priv,
14971497
SVGA3dCmdHeader *header)
14981498
{
14991499
struct vmw_bo *vmw_bo = NULL;
1500+
struct vmw_resource *res;
15001501
struct vmw_surface *srf = NULL;
15011502
VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdSurfaceDMA);
15021503
int ret;
@@ -1532,18 +1533,24 @@ static int vmw_cmd_dma(struct vmw_private *dev_priv,
15321533

15331534
dirty = (cmd->body.transfer == SVGA3D_WRITE_HOST_VRAM) ?
15341535
VMW_RES_DIRTY_SET : 0;
1535-
ret = vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface,
1536-
dirty, user_surface_converter,
1537-
&cmd->body.host.sid, NULL);
1536+
ret = vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface, dirty,
1537+
user_surface_converter, &cmd->body.host.sid,
1538+
NULL);
15381539
if (unlikely(ret != 0)) {
15391540
if (unlikely(ret != -ERESTARTSYS))
15401541
VMW_DEBUG_USER("could not find surface for DMA.\n");
15411542
return ret;
15421543
}
15431544

1544-
srf = vmw_res_to_srf(sw_context->res_cache[vmw_res_surface].res);
1545+
res = sw_context->res_cache[vmw_res_surface].res;
1546+
if (!res) {
1547+
VMW_DEBUG_USER("Invalid DMA surface.\n");
1548+
return -EINVAL;
1549+
}
15451550

1546-
vmw_kms_cursor_snoop(srf, sw_context->fp->tfile, &vmw_bo->tbo, header);
1551+
srf = vmw_res_to_srf(res);
1552+
vmw_kms_cursor_snoop(srf, sw_context->fp->tfile, &vmw_bo->tbo,
1553+
header);
15471554

15481555
return 0;
15491556
}

0 commit comments

Comments
 (0)