6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Zack Rusin [ Upstream commit 21bc51cb89ced74d6645a138cc2f21184bc75094 ] Validate the pitch, alongside the box dimensions before trying to copy data from the underlying surface. Fixes possible out of bounds reads with cursor snooping. Fixes: 2ac863719e51 ("vmwgfx: Snoop DMA transfers with non-covering sizes") Cc: stable@vger.kernel.org Reported-by: Youness HFA Signed-off-by: Zack Rusin Reviewed-by: Maaz Mombasawala Link: https://patch.msgid.link/20260809204515.211045-1-zack.rusin@broadcom.com [ sashal: Adapted the changes to the existing cursor snooping function using fixed 64×64 dimensions and four-byte pixels. ] Signed-off-by: Sasha Levin --- drivers/gpu/drm/vmwgfx/vmwgfx_kms.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c index 5210b8084217c..38abdaf663ff6 100644 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c @@ -277,6 +277,7 @@ void vmw_kms_cursor_snoop(struct vmw_surface *srf, unsigned long kmap_num; SVGA3dCopyBox *box; unsigned box_count; + u64 src_extent; void *virtual; bool dummy; struct vmw_dma_cmd { @@ -285,6 +286,8 @@ void vmw_kms_cursor_snoop(struct vmw_surface *srf, } *cmd; int i, ret; + BUILD_BUG_ON(sizeof(*srf->snooper.image) != 4); + cmd = container_of(header, struct vmw_dma_cmd, header); /* No snooper installed */ @@ -322,8 +325,19 @@ void vmw_kms_cursor_snoop(struct vmw_surface *srf, return; } + if (box->w == 0 || box->h == 0) + return; + + src_extent = (u64)(box->h - 1) * cmd->dma.guest.pitch + + (u64)box->w * 4; + if (src_extent > bo->base.size) { + DRM_ERROR("Cursor snoop source of %llu bytes exceeds the %zu byte buffer\n", + src_extent, bo->base.size); + return; + } + kmap_offset = cmd->dma.guest.ptr.offset >> PAGE_SHIFT; - kmap_num = (64*64*4) >> PAGE_SHIFT; + kmap_num = PFN_UP(src_extent); ret = ttm_bo_reserve(bo, true, false, NULL); if (unlikely(ret != 0)) { @@ -337,13 +351,13 @@ void vmw_kms_cursor_snoop(struct vmw_surface *srf, virtual = ttm_kmap_obj_virtual(&map, &dummy); - if (box->w == 64 && cmd->dma.guest.pitch == 64*4) { + if (box->w == 64 && box->h == 64 && cmd->dma.guest.pitch == 64*4) { memcpy(srf->snooper.image, virtual, 64*64*4); } else { - /* Image is unsigned pointer. */ + /* The destination stride is in pixels. */ for (i = 0; i < box->h; i++) memcpy(srf->snooper.image + i * 64, - virtual + i * cmd->dma.guest.pitch, + virtual + (size_t)i * cmd->dma.guest.pitch, box->w * 4); } -- 2.53.0