Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6905B51E422 for ; Tue, 13 Oct 2026 16:54:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791910498; cv=none; b=LfofdhMzePpB4c1GJiYVV8jpb5qGvufDDG8N+OlOLtxAWdkrXSZD6vrNcGe9c+56aW1KhiH4nLt4EKa01S6HdHUGbp8WNivSZvCtLxF9C1YRNnHgT5uAemBrF5llDsDRYHefJ9fsZQnnurix02ZQ6IMd5/blF5EaLdyw9bdC4tI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791910498; c=relaxed/simple; bh=eQPYo7ob4zbDEwJV86D2WX6nlgvrkj+zi01A9Dfe+I4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=g2IybTmV6R6huIuCP6xIQp10IoGSwoCKpd3ksAxgTrBHSu0sZGnrjiGTnTinChk1bcD8lZEf6AD6QawgEpuqMp+FhTU8LfPu2tEScevIAsveWR97CpI0OqrYzSCEoNGbrMWyyPZW0DdhtSHH4dsfwjrJbf1bnA85g759ZY77l1U= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=gqkOuvRZ; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="gqkOuvRZ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 877A11F00893; Tue, 13 Oct 2026 16:54:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1791910497; bh=Y9sSbNiO2Zz087MHSd3wLLx4VyurQnXWfq/7sPglcMY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=gqkOuvRZX6dApDGXMY4sQzkvzeMJVAtXfHcCJB0o6gYlBiQtElGq6BmEopvcfGtGy F8eUdxwDBj6gEqpOx2k64ZckMhkwINgPF/hCCTEB61wdhzRHcoH7LehCOTsdhdQ0xF 19b6J09n30GmQj9gqIIT6hQx8nlacNp9u0poiwbEpRDeYtvrh6vXpEnhi+DbrRdrVP M+unn+esJWctsbQYKKZPIFu3O14U8ZTRA2Un9W1lZZrb5ngItAccAPzSQ9S4N3UBdm 40quCGGhnv+SOvEOQaWEOkbK60xqppgTDacjpkthrW4uWVFk6KPfx+etCIddbBbB92 Uhb2g3bxVYYsQ== From: Sasha Levin To: stable@vger.kernel.org Cc: Zack Rusin , Youness HFA , Maaz Mombasawala , Sasha Levin Subject: [PATCH 6.12.y 2/2] drm/vmwgfx: validate pitch coming from userspace Date: Tue, 13 Oct 2026 12:54:54 -0400 Message-ID: <20261013165424.426719-2-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261013165424.426719-1-sashal@kernel.org> References: <2026101207-unpaid-wok-72a4@gregkh> <20261013165424.426719-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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: Applied the changes to vmw_kms_cursor_snoop() in its original location because the cursor refactor is absent. ] Signed-off-by: Sasha Levin --- drivers/gpu/drm/vmwgfx/vmwgfx_kms.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c index 800a79e035ed6..985774f22a130 100644 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c @@ -382,6 +382,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 is_iomem; struct vmw_dma_cmd { @@ -393,6 +394,8 @@ void vmw_kms_cursor_snoop(struct vmw_surface *srf, vmw_surface_get_desc(VMW_CURSOR_SNOOP_FORMAT); const u32 image_pitch = VMW_CURSOR_SNOOP_WIDTH * desc->pitchBytesPerBlock; + BUILD_BUG_ON(sizeof(*srf->snooper.image) != desc->pitchBytesPerBlock); + cmd = container_of(header, struct vmw_dma_cmd, header); /* No snooper installed, nothing to copy */ @@ -430,8 +433,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 * desc->pitchBytesPerBlock; + 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 = (VMW_CURSOR_SNOOP_HEIGHT*image_pitch) >> PAGE_SHIFT; + kmap_num = PFN_UP(src_extent); ret = ttm_bo_reserve(bo, true, false, NULL); if (unlikely(ret != 0)) { @@ -445,14 +459,16 @@ void vmw_kms_cursor_snoop(struct vmw_surface *srf, virtual = ttm_kmap_obj_virtual(&map, &is_iomem); - if (box->w == VMW_CURSOR_SNOOP_WIDTH && cmd->dma.guest.pitch == image_pitch) { + if (box->w == VMW_CURSOR_SNOOP_WIDTH && + box->h == VMW_CURSOR_SNOOP_HEIGHT && + cmd->dma.guest.pitch == image_pitch) { memcpy(srf->snooper.image, virtual, VMW_CURSOR_SNOOP_HEIGHT*image_pitch); } else { - /* Image is unsigned pointer. */ + /* The destination stride is in pixels. */ for (i = 0; i < box->h; i++) - memcpy(srf->snooper.image + i * image_pitch, - virtual + i * cmd->dma.guest.pitch, + memcpy(srf->snooper.image + i * VMW_CURSOR_SNOOP_WIDTH, + virtual + (size_t)i * cmd->dma.guest.pitch, box->w * desc->pitchBytesPerBlock); } -- 2.53.0