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=1796383067; b=J7uhCRnoJKi2vTC5YH18pzh+wu8e5MFVPiwAearg9Pven63LM88uDt0HnTk9BafM7WpF VVW8teAwJCwkClC/3PB4Q+eKUmY5LZmvMRTxryVv+S4D8O/haYSZ7YU5+IwHt1oTepF9q UdiKrIjLESSYrz6gY8OFHz1+PniZ6Jg36To2LM0061g1DsyrbVqPY38r3nCr8KDevnY70 Pi62EuGj1q8en3EAlxjcWFS7EGY2kjm+uQJzOfcuLST1X+l4mtNVtsEFyo+are+oohAHp u4iOiPK9xBT64FZ29V1pDpEZof2oCxZrKmuN3RqarTF3qbaNGcRltoQdcbRA4kZiBeg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796383067; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=TSidT2w2M0A1KiOb3SOW2ex4q7luvGAcGVvA3ZWo5s4=; b=QLCDCFzKttoM1df+o6q+Q/aba/gGh4r3cm+gKPeWha5QooCjJp7L3Bz5YOvdifuGg6Ec 4qwM1HimWLhug+OsRu4odCmqu2GZ0I40rv4Fkt7KfSc7TaxAm6yEDD7JKJbv/hhlnf1CV MzjLA3q6Sbi4RUc9suui4uHknjokrzEU1OJVjbzm5QZHztYVnLx8OTfOipanZc1CN4+5F UDx98+NB/k44mbzG7ybJHua9WLBk8gagcflNjstXXUu8rW7PyAbGtW8nL/uWaGLWfnljb TKjrumR/owRYfkUY/cdQWe13GZA2158xQ5u+w5SURr3nOh2hOtS2lo+Jcezsh9rAQug== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=Jz0iQKfu; 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 8B4B8606A322; Fri, 4 Dec 2026 11:17:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=Jz0iQKfu Received: by smtp.kernel.org (Postfix) with ESMTPSA id 75D501F00937; Fri, 4 Dec 2026 11:17:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796383066; bh=TSidT2w2M0A1KiOb3SOW2ex4q7luvGAcGVvA3ZWo5s4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Jz0iQKfu1SD+QjHDHkB7S/2EnVFh/oOzVESax+/9hHz2jW+9W9rWS0++V8mfHij30 p6fc9ZZBgkkvUd4fQE0MK/rFtijvIf5zotTi4eBgXyTKIMPsGtmVJ+RvB92DzIyEbn M+L//2wTcvMpFCWwkRVhDl1boidQUloT2LRFBxwY= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Zack Rusin , Ian Forbes , Sasha Levin , Zero Day Initiative Subject: [PATCH 6.18 678/703] drm/vmwgfx: validate backup buffer size in command buffer processing Date: Fri, 4 Dec 2026 19:09:37 +0900 Message-ID: <20261204100645.852608131@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100627.522266145@linuxfoundation.org> References: <20261204100627.522266145@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ 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: Replaced kmalloc_obj/kzalloc_obj with kzalloc(sizeof(*x), GFP_KERNEL) in the DX shader and streamoutput allocations, since this tree lacks the *_obj helpers. ] Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- 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(-) --- a/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c @@ -1794,6 +1794,7 @@ static int vmw_cmd_res_switch_backup(str { struct vmw_bo *vbo; void *info; + u64 end; int ret; info = vmw_execbuf_info_from_res(sw_context, res); @@ -1804,6 +1805,13 @@ static int vmw_cmd_res_switch_backup(str if (ret) return ret; + if (check_add_overflow((u64)backup_offset, + (u64)res->guest_memory_size, &end) || + end > vbo->tbo.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; --- a/drivers/gpu/drm/vmwgfx/vmwgfx_shader.c +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_shader.c @@ -597,7 +597,7 @@ int vmw_dx_shader_add(struct vmw_cmdbuf_ 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; } --- a/drivers/gpu/drm/vmwgfx/vmwgfx_streamoutput.c +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_streamoutput.c @@ -284,7 +284,7 @@ int vmw_dx_streamoutput_add(struct vmw_c 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; }