mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Aldo Ariel Panzardo <qwe.aldo@gmail.com>
To: Zack Rusin <zack.rusin@broadcom.com>
Cc: Broadcom internal kernel review list
	<bcm-kernel-feedback-list@broadcom.com>,
	Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
	Maxime Ripard <mripard@kernel.org>,
	Thomas Zimmermann <tzimmermann@suse.de>,
	David Airlie <airlied@gmail.com>, Simona Vetter <simona@ffwll.ch>,
	dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org,
	Aldo Ariel Panzardo <qwe.aldo@gmail.com>
Subject: [PATCH] drm/vmwgfx: reject SURFACE_DMA commands smaller than body + suffix
Date: Sun,  9 Aug 2026 10:25:14 -0300	[thread overview]
Message-ID: <20260809132514.421679-1-qwe.aldo@gmail.com> (raw)

vmw_cmd_dma() locates the SVGA3dCmdSurfaceDMASuffix at the end of the
command and dereferences it:

	suffix = (SVGA3dCmdSurfaceDMASuffix *)((unsigned long) &cmd->body +
					       header->size - sizeof(*suffix));
	if (unlikely(suffix->suffixSize != sizeof(*suffix))) {

header->size comes straight from userspace through DRM_IOCTL_VMW_EXECBUF
(DRM_RENDER_ALLOW) and is only bounded from above: vmw_cmd_check()
rejects header->size > SVGA_CMD_MAX_DATASIZE and commands that do not fit
the buffer, and struct vmw_cmd_entry carries no per-command minimum size.
There is no lower bound. When header->size is smaller than sizeof(*suffix)
the pointer arithmetic underflows and the read of suffix->suffixSize is an
out-of-bounds read ahead of the command; when it is smaller than the body
plus the suffix, the body accesses that follow are out of bounds as well.

Reject the command before computing the suffix pointer when header->size
cannot hold both the fixed body and the trailing suffix.

Found by a syzkaller instance fuzzing the vmwgfx command stream:

  BUG: KASAN: vmalloc-out-of-bounds in vmw_cmd_dma+0x508/0x5b0
  Read of size 4 ...
   vmw_cmd_dma+0x508/0x5b0 drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c
   vmw_execbuf_process+0xd06/0x35f0
   vmw_execbuf_ioctl+0x1cc/0x5a0

Fixes: cbd75e97a525 ("drm/vmwgfx: Make sure user-space can't DMA across buffer object boundaries v2")
Cc: stable@vger.kernel.org
Signed-off-by: Aldo Ariel Panzardo <qwe.aldo@gmail.com>
---
 drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c b/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c
index 6b921db2dcd2..02eb383f91b5 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c
@@ -1524,6 +1524,12 @@ static int vmw_cmd_dma(struct vmw_private *dev_priv,
 	bool dirty;
 
 	cmd = container_of(header, typeof(*cmd), header);
+
+	if (unlikely(header->size < sizeof(cmd->body) + sizeof(*suffix))) {
+		VMW_DEBUG_USER("Invalid SURFACE_DMA command size.\n");
+		return -EINVAL;
+	}
+
 	suffix = (SVGA3dCmdSurfaceDMASuffix *)((unsigned long) &cmd->body +
 					       header->size - sizeof(*suffix));
 
-- 
2.43.0


             reply	other threads:[~2026-08-09 13:25 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-09 13:25 Aldo Ariel Panzardo [this message]
     [not found] ` <CAP48HfvqpeMhxJZwzcjXo9akVvV5WU6nN4xVuNaAvX07q2OBEQ@mail.gmail.com>
2026-09-23 14:35   ` Zack Rusin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260809132514.421679-1-qwe.aldo@gmail.com \
    --to=qwe.aldo@gmail.com \
    --cc=airlied@gmail.com \
    --cc=bcm-kernel-feedback-list@broadcom.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=mripard@kernel.org \
    --cc=simona@ffwll.ch \
    --cc=tzimmermann@suse.de \
    --cc=zack.rusin@broadcom.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®