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=1796352752; b=5tOyPkYA0q3ZSdyqUcDvVeXiJOPZIqvVe7iWsjQt9hgPajA0b9W6x3QSsUCqv55VLYMw GbPDVkxacWqQ3x6aaFHS4OUOSVsEyRmnsoflqZseu5AzsBgWxpHM+x8zJeWN8jpIbRhst 3UfiMzuRG7HDQEXMu6y/UB/1+hiVeYIshpltYL+ENR+mMu+YaenCKGtPVgebhjqyE1jAx s1kX5V2OBUZaEq9u7JssaKWbwtYlsaw+sP/a3NWtwUSTE5JEo6MLhugEPsbFhZ1X9DqK6 Q+vYZ47Ey3wjvlnFhZjpy9TFBXkIr7p6KaSjDUEt9kHv1O5vjP3qZ6zREDSAOoTqnHg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796352752; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=FNuh0DQSiMqtPS1rckckqETT5Pgg50LAmdwW5mbw088=; b=SyfRQN0N+uA2OUORW1Jw8LGhQEMPbcbx77tGeLSFbJZ6rO124sixDUJuoxKHWup+rld1 3uFia3sgFdWBy09vJp7LyEmebsYgpeKIm1IRfnRuVDmL2900tR1LfvoZS3aUyqJ+Gypc6 sezOGneYagsNKhcuLnWwQly6v0gOg8fMkzyR3TudHqlooAy4ihYIwvNxiJIP18IvnVIJM 0Snenh6v4drCu/6dUEtcnfeK4XqOk89jzOvU2ttLsKYzfuP2FuFRnPb5rF/W2vwv2edQJ R7Y+AA9vvup01o6xJmEbE7y4QRL254a8Q3dYt3ep5NE5avZdrVwKCyGlX14QLL0/1rw== 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=kDCEOrYo; 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 D8049606A322 for ; Fri, 4 Dec 2026 02:52:32 +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=kDCEOrYo Received: by smtp.kernel.org (Postfix) with ESMTPSA id C6F281F000C2; Fri, 4 Dec 2026 02:52:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796352752; bh=FNuh0DQSiMqtPS1rckckqETT5Pgg50LAmdwW5mbw088=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=kDCEOrYoYElk/hLCz1eVun2SUMuO5kYA0ng7QfZM1re9wAgs9dqAzNnKCi/W6yo3u JxcHeim6md5ao4yxPXqeynUc5REpBp89h/D+ijL23VoH0v4/7nYYXmY7sbSnBiTTej ZpHaksPeubBfgT/pR9SSezkHeeahTr6C5wnznM5SwVpEUF2Pq4EOb3cOpOuPhNwPT7 JUTnKNQh2wJNJtEK6ePYkqFpv8hul1q1Bl9xhZ/a+DMhkimnK9Y0K8SjF4jQ7egQDY RqSimRTgcDOZqJMz0rjqHGH/U3c6dKBs4Xt7P68Epm1RBkzQXctSgvDRE+HWrSXjHE aVOSyZFkEzXSA== From: Sasha Levin To: stable@vger.kernel.org Cc: Zack Rusin , Zero Day Initiative , Ian Forbes , Sasha Levin Subject: [PATCH 6.12.y] drm/vmwgfx: validate backup buffer size in command buffer processing Date: Thu, 3 Dec 2026 21:52:30 -0500 Message-ID: <20261204025148.2291898-1-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <2026120256-pants-schnapps-89b4@gregkh> References: <2026120256-pants-schnapps-89b4@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 kmalloc_obj()/kzalloc_obj() allocation helpers to the older kmalloc()/kzalloc() with sizeof and GFP_KERNEL in the shader and streamoutput hunks. ] 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 139efb1a3d898..5a462f52cd659 100644 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c @@ -1812,6 +1812,7 @@ static int vmw_cmd_res_switch_backup(struct vmw_private *dev_priv, { struct vmw_bo *vbo; void *info; + u64 end; int ret; info = vmw_execbuf_info_from_res(sw_context, res); @@ -1822,6 +1823,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->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; diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_shader.c b/drivers/gpu/drm/vmwgfx/vmwgfx_shader.c index bc89a137ab6d9..b53b8e43fa6de 100644 --- 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_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 edcc406590385..7a4bd668ff0d8 100644 --- 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_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