FAILED: patch "[PATCH] drm/vmwgfx: validate pitch coming from userspace" failed to apply to 6.12-stable tree
Subsystems (4)
[email protected]
maintainerThe patch below does not apply to the 6.12-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.12.y
git checkout FETCH_HEAD
git cherry-pick -x 21bc51cb89ced74d6645a138cc2f21184bc75094
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026101207-unpaid-wok-72a4@gregkh' --subject-prefix 'PATCH 6.12.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 21bc51cb89ced74d6645a138cc2f21184bc75094 Mon Sep 17 00:00:00 2001
From: Zack Rusin <[email protected]>
Date: Sun, 9 Aug 2026 16:45:15 -0400
Subject: [PATCH] drm/vmwgfx: validate pitch coming from userspace
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.
drivers/gpu/drm/vmwgfx/vmwgfx_cursor_plane.c +21 -5
@@ -324,6 +324,7 @@ void vmw_kms_cursor_snoop(struct vmw_surface *srf,unsigned long kmap_num;SVGA3dCopyBox *box;u32 box_count; +u64 src_extent;void *virtual;bool is_iomem;struct vmw_dma_cmd {
@@ -335,6 +336,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 */
@@ -372,8 +375,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 )) {
@@ -387,14 +401,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); } srf->snooper.id++;
Sasha Levin
maintainerPATCH 1/2 drm/vmwgfx: Stop using dev_private to store driver data.
From: Maaz Mombasawala <[email protected]>
[ Upstream commit 1b1d5fe66ca591d34c5501aab8f5f09f347e8a3e ]
Currently vmwgfx uses the dev_private opaque pointer in drm_device to store driver data in vmw_private struct. Using dev_private is deprecated, and the recommendation is to embed struct drm_device in the larger per-device structure.
The vmwgfx driver already embeds struct drm_device in its struct vmw_private, so switch to using that exclusively and stop using dev_private.
Stable-dep-of: 21bc51cb89ce ("drm/vmwgfx: validate pitch coming from userspace")
--- drivers/gpu/drm/vmwgfx/vmwgfx_drv.c | 2 -- drivers/gpu/drm/vmwgfx/vmwgfx_drv.h | 2 +- drivers/gpu/drm/vmwgfx/vmwgfx_kms.c | 4 ++-- 3 files changed, 3 insertions(+), 5 deletions(-)
drivers/gpu/drm/vmwgfx/vmwgfx_drv.c +0 -2
@@ -856,8 +856,6 @@ static int vmw_driver_load(struct vmw_private *dev_priv, u32 pci_id)bool refuse_dma = false;struct pci_dev *pdev =to_pci_dev (dev_priv->drm.dev); - dev_priv->drm.dev_private = dev_priv; -vmw_sw_context_init (dev_priv);mutex_init (&dev_priv->cmdbuf_mutex);
drivers/gpu/drm/vmwgfx/vmwgfx_drv.h +1 -1
@@ -639,7 +639,7 @@ static inline struct vmw_surface *vmw_res_to_srf(struct vmw_resource *res)static inline struct vmw_private *vmw_priv (struct drm_device *dev) { -return (struct vmw_private *)dev->dev_private; + return container_of(dev, struct vmw_private, drm); }static inline struct vmw_private *vmw_priv_from_ttm (struct ttm_device *bdev)
drivers/gpu/drm/vmwgfx/vmwgfx_kms.c +2 -2
@@ -280,7 +280,7 @@ static void vmw_du_put_cursor_mob(struct vmw_cursor_plane *vcp,static int vmw_du_get_cursor_mob (struct vmw_cursor_plane *vcp,struct vmw_plane_state *vps) { -struct vmw_private *dev_priv = vcp->base.dev->dev_private; +struct vmw_private *dev_priv =vmw_priv (vcp->base.dev);u32 size =vmw_du_cursor_mob_size (vps->base.crtc_w, vps->base.crtc_h);u32 i;u32 cursor_max_dim, mob_max_size;
@@ -519,7 +519,7 @@ void vmw_du_cursor_plane_destroy(struct drm_plane *plane)struct vmw_cursor_plane *vcp =vmw_plane_to_vcp (plane);u32 i; -vmw_cursor_update_position (plane->dev->dev_private, false,0 ,0 ); +vmw_cursor_update_position (vmw_priv (plane->dev), false,0 ,0 );for (i =0 ; i <ARRAY_SIZE (vcp->cursor_mobs); i++)vmw_du_destroy_cursor_mob (&vcp->cursor_mobs[i]);
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 2/2 drm/vmwgfx: validate pitch coming from userspace
From: Zack Rusin <[email protected]>
[ 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.
--- drivers/gpu/drm/vmwgfx/vmwgfx_kms.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-)
drivers/gpu/drm/vmwgfx/vmwgfx_kms.c +21 -5
@@ -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); }
Signature · 1 line
2.53.0