From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796353438; b=WHzCxjcC+HdFkdPY7WH6sGnUOs3iAVbS8jQy/aPwvf9ZaSdPKy5PCw/hibG6NQjFSMlW xvVuNDdXi5O7Ca4wI3RJE6jFmzpAlnehemWr2zRqh07adM+xb/hG69kEoYJt4Er5MkpV/ Wu/KSH7Yp+TOXIYCzgyT4Fbr5Zo4PKRU7OQK5EwRHd4WLO9AFJlXMbBNu0Qy0KtJAdzFZ cmDrbT6yPAI0+6Nj1RrYpvkq8/bMv2Sf2POixWzOKqdlM5s5ffGUYJH8p+lIFn1AY/VE8 GdwAjADO64uoq0MtP82StyyspDVehT3Rx0aq0Ywc/2b+Av58ufffmfcN19agL3IYcpA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796353438; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=Y/tdyXgv/pTsEzIWo1XGrToDSWRkJJvdhnCqYOf/UJg=; b=aQr+sTA+3EOrKEWbtiiwT59aRqvZCUDCCIKs3mpghzGF2GDSV1rmWyJlayS0xph+IV2q xDgs8XOmFZbP6fO4qqIzXH+1F60BJMw6s55DLy/4/nGphKo/BEWbHkxLsReueCZXb593F qYZRBcHjLY/BefJkCcXfaefIFxr4415+NYYbvDTT+mHqZGLeh+O3Is12O2tbfZe1YhPP2 k3xQniTNBhJ56XiFCIJUa6rK4KvkgY1rZvNgcdwyvsp0x8n8ci+ZKiWG5N8E7fu3q6M0N OlMhCX37ewoHJckCDl+tI4yve6Tq2i184Ykwj/aElqUcod8LKHlzbRkN+uUpwQl170w== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=INRxpwmU; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C99F8606A322 for ; Fri, 4 Dec 2026 03:03:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=INRxpwmU Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0007B1F000C2; Fri, 4 Dec 2026 03:03:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796353438; bh=Y/tdyXgv/pTsEzIWo1XGrToDSWRkJJvdhnCqYOf/UJg=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=INRxpwmUkSdGz87DUAKM5T8WdFitqAmEPYCT6Uri+OAGe/A0OUNpCM+/VZznQAOfs V3NBZfE6NCpweqj8MJk9sHO8vu3L0fqub0jbanzSCalaXXVBlo/0O1FUJhyr2ZtA+G 34e48HrzEzirG5ChJjeZYRAq2IuLVkPV4t5Df6nwP5Nsintp5d4fhzVcCwqZQthe5p d5Nt5/0vvBn3Mc9YwcM/bTGYBDVQG4YZzncatiNouNk0MC+8BOIkEF1XH6j7Lk9WdY A0WC1CvUhUjBmFpeISr6C89O0xu2HKjN75nS1QCyCxTlcnYJwGwTXI3wu4JMClsOQo h+QdigZm/2Tng== From: Sasha Levin To: stable@vger.kernel.org Cc: Zack Rusin , Zero Day Initiative , Ian Forbes , Sasha Levin Subject: [PATCH 6.1.y] drm/vmwgfx: validate backup buffer size in command buffer processing Date: Thu, 3 Dec 2026 22:03:56 -0500 Message-ID: <20261204030315.2298433-1-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <2026120257-preamble-aside-db81@gregkh> References: <2026120257-preamble-aside-db81@gregkh> X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Zack Rusin [ Upstream commit c1e6267b9dd3e04f9dc29e500414cc4fc237dec1 ] vmw_cmd_res_switch_backup lets userspace bind an arbitrary MOB to a resource without checking that the MOB is large enough for the resource's guest_memory_size. The dirty-tracking bitmap is allocated based on the MOB size, but later accessed using the (larger) surface size, causing an out-of-bounds write in the bitmap that corrupts adjacent slab memory. Add a check that backup_offset + res->guest_memory_size does not exceed the buffer size before allowing the backup switch. DX shaders and stream outputs never set guest_memory_size, and both were allocated with kmalloc(), so the check would read uninitialized memory for SVGA_3D_CMD_DX_BIND_SHADER and SVGA_3D_CMD_DX_BIND_STREAMOUTPUT and could reject valid binds. Allocate both with kzalloc() so their guest_memory_size is 0 and the check only bounds the offset. Fixes: a97e21923b42 ("drm/vmwgfx: Hook up guest-backed surfaces") Cc: stable@vger.kernel.org Reported-by: Zero Day Initiative # ZDI-CAN-34068 Closes: https://lore.kernel.org/all/BYAPR01MB38301CFC012E873340F77E3D80662@BYAPR01MB3830.prod.exchangelabs.com/ Signed-off-by: Zack Rusin Reviewed-by: Ian Forbes Link: https://patch.msgid.link/20261027031533.2241918-1-zack.rusin@broadcom.com [ sashal: Adapted the bounds check to older names (vmw_buffer_object, backup_size, base.base.size) and used kzalloc in place of the missing kmalloc_obj/kzalloc_obj helpers. ] Signed-off-by: Sasha Levin --- drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c | 8 ++++++++ drivers/gpu/drm/vmwgfx/vmwgfx_shader.c | 2 +- drivers/gpu/drm/vmwgfx/vmwgfx_streamoutput.c | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c b/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c index e0d162d95ea44..bcd3603cbef52 100644 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c @@ -1804,6 +1804,7 @@ static int vmw_cmd_res_switch_backup(struct vmw_private *dev_priv, { struct vmw_buffer_object *vbo; void *info; + u64 end; int ret; info = vmw_execbuf_info_from_res(sw_context, res); @@ -1814,6 +1815,13 @@ static int vmw_cmd_res_switch_backup(struct vmw_private *dev_priv, if (ret) return ret; + if (check_add_overflow((u64)backup_offset, + (u64)res->backup_size, &end) || + end > vbo->base.base.size) { + VMW_DEBUG_USER("Backup buffer too small for resource.\n"); + return -EINVAL; + } + vmw_validation_res_switch_backup(sw_context->ctx, info, vbo, backup_offset); return 0; diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_shader.c b/drivers/gpu/drm/vmwgfx/vmwgfx_shader.c index 8325feda175d3..901eb431baf68 100644 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_shader.c +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_shader.c @@ -592,7 +592,7 @@ int vmw_dx_shader_add(struct vmw_cmdbuf_res_manager *man, if (!vmw_shader_id_ok(user_key, shader_type)) return -EINVAL; - shader = kmalloc(sizeof(*shader), GFP_KERNEL); + shader = kzalloc(sizeof(*shader), GFP_KERNEL); if (!shader) { return -ENOMEM; } diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_streamoutput.c b/drivers/gpu/drm/vmwgfx/vmwgfx_streamoutput.c index 2de97419d5c9a..6ce5c4e66e23a 100644 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_streamoutput.c +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_streamoutput.c @@ -282,7 +282,7 @@ int vmw_dx_streamoutput_add(struct vmw_cmdbuf_res_manager *man, struct vmw_private *dev_priv = ctx->dev_priv; int ret; - so = kmalloc(sizeof(*so), GFP_KERNEL); + so = kzalloc(sizeof(*so), GFP_KERNEL); if (!so) { return -ENOMEM; } -- 2.53.0