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=1796380783; b=m2WbQUbCBYaPlvEoVMNn4YlKS44m7QuSnBQYuDgEFc/Xk0s0fXczLnFXxbABK8sRe0OG AXCxVI7GAsUzjVN4GWpnlAbpw5iTPFLHiHaFZxQHE7SbH1rAk30r8vgvOijlPr32JW27N uPscYFURLIe3piZ/Cyao3mxcDAS9IBcboLi1wXdoPTI3Olc7OXvS0/HDOZsKN0eBRGvb5 MzPJym+RbXGUM+4y9KDkJ+fsjnPgwmZryWb+skxwCH59jnf/99dritnUDiLKHgApqA1HE U0fI+mHr+Kn01X8s7QwlAhxPfsDbhFv/7KeRzFcnRteRgqpHj6A7NQ/eubVV8A9TioQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796380783; 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=zvjXyBDsDBihG0m9S2a0PvKgF2/C+U3Pq6cxI8gkWys=; b=g5a9GHndgvlSyNWRW3CBnCUEwpcRXyNbxU79Twcz/2CAy2RnP/IkuvaoFlN2XW7Xp/AT LrPOzJrgb1dubLpR7soZIdc5TargpJEdhysblCVrwBTWQ1xy5cJ5rcqgR0gfjtV3Xwvf/ vlMxtBgA/TFdAtZ6j1QpPawXO9Wy79e1Th/Mc3vXaWvTOHXKIZNlDamWhB7h6pXItiVwF 495C1q5IokD1cPfUcgainf/gk+5HICWgwVlSP1kHL1wWPvXmyjfjjBE6PrFxd1y9ze6oL VJ5gITJJlC5UCvnDTcNLTUtfVNUI/yq96B6/508DgfgZSmaWREETOADKIQRVfDqckKQ== 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=esSKsjFw; 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 ACBAC606A68C; Fri, 4 Dec 2026 10:39:43 +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=esSKsjFw Received: by smtp.kernel.org (Postfix) with ESMTPSA id 29A8D1F0092C; Fri, 4 Dec 2026 10:39:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796380783; bh=zvjXyBDsDBihG0m9S2a0PvKgF2/C+U3Pq6cxI8gkWys=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=esSKsjFwxw8NbNuNXtjyqIf2Pp3LWKbbtrJXB24QO/NxWgrbeuDVNLO+2fmpthphU 9tCVLTd5IiYxDjvk3oLfqeWDi5m6gv6UbxRhMdO+o6LJq/ucXnhc8BJZvffCyPmG99 chiZjXnsmFlXbLIhI4GTrKxKvmb0hJAxvSTEmnLs= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Zack Rusin , Maaz Mombasawala , fausten Subject: [PATCH 7.3 423/742] drm/vmwgfx: validate the framebuffer selected for cursor updates Date: Fri, 4 Dec 2026 19:04:47 +0900 Message-ID: <20261204100646.338809344@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100635.034361255@linuxfoundation.org> References: <20261204100635.034361255@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore 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 7.3-stable review patch. If anyone has any objections, please let me know. ------------------ From: Zack Rusin commit d6263d9bfa931dfc7e0dd922a6ee52b5535caa74 upstream. Cursor atomic checks select an update path and look up surfaces through vps->uo. That object is copied from the previous plane state and is only replaced with the new framebuffer's object in prepare_fb(). Switching between snooped surfaces and buffer objects therefore applies the old framebuffer's cursor limits to the new image. KMS clients can also submit a guest-backed surface without a backing BO. The check accepts it, but the MOB update later copies from a NULL source. Zero-sized MOB images pass the check as well, then fail preparation when mapping zero pages, so TEST_ONLY accepts a commit that cannot succeed. Resolve the user object directly from the selected framebuffer in both validation and preparation. Apply the matching cursor limits, reject zero dimensions and require a backing BO for GB-only and MOB images. Recheck the backing BO in preparation before mapping it, while keeping snooped surfaces independent of a BO mapping. Fixes: 965544150d1c ("drm/vmwgfx: Refactor cursor handling") Cc: stable@vger.kernel.org Assisted-by: LLM Signed-off-by: Zack Rusin Reviewed-by: Maaz Mombasawala Tested-by: fausten Link: https://patch.msgid.link/20261027211729.646988-6-zack.rusin@broadcom.com Signed-off-by: Greg Kroah-Hartman --- drivers/gpu/drm/vmwgfx/vmwgfx_cursor_plane.c | 59 +++++++++++++++++++-------- 1 file changed, 42 insertions(+), 17 deletions(-) --- a/drivers/gpu/drm/vmwgfx/vmwgfx_cursor_plane.c +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_cursor_plane.c @@ -89,10 +89,26 @@ vmw_cursor_plane_update_legacy(struct vm } } +static struct vmw_user_object +vmw_cursor_plane_user_object(struct drm_framebuffer *fb) +{ + struct vmw_user_object uo = { 0 }; + + if (!fb) + return uo; + + if (vmw_framebuffer_to_vfb(fb)->bo) + uo.buffer = vmw_framebuffer_to_vfbd(fb)->buffer; + else + uo = vmw_framebuffer_to_vfbs(fb)->uo; + + return uo; +} + static enum vmw_cursor_update_type -vmw_cursor_update_type(struct vmw_private *vmw, struct vmw_plane_state *vps) +vmw_cursor_update_type(struct vmw_private *vmw, struct vmw_user_object *uo) { - struct vmw_surface *surface = vmw_user_object_surface(&vps->uo); + struct vmw_surface *surface = vmw_user_object_surface(uo); if (surface && surface->snooper.image) return VMW_CURSOR_UPDATE_LEGACY; @@ -649,17 +665,10 @@ int vmw_cursor_plane_prepare_fb(struct d if (!vmw_user_object_is_null(&vps->uo)) vmw_user_object_unref(&vps->uo); - if (fb) { - if (vmw_framebuffer_to_vfb(fb)->bo) { - vps->uo.buffer = vmw_framebuffer_to_vfbd(fb)->buffer; - vps->uo.surface = NULL; - } else { - memcpy(&vps->uo, &vmw_framebuffer_to_vfbs(fb)->uo, sizeof(vps->uo)); - } - vmw_user_object_ref(&vps->uo); - } + vps->uo = vmw_cursor_plane_user_object(fb); + vmw_user_object_ref(&vps->uo); - vps->cursor.update_type = vmw_cursor_update_type(vmw, vps); + vps->cursor.update_type = vmw_cursor_update_type(vmw, &vps->uo); switch (vps->cursor.update_type) { case VMW_CURSOR_UPDATE_LEGACY: surface = vmw_user_object_surface(&vps->uo); @@ -669,6 +678,9 @@ int vmw_cursor_plane_prepare_fb(struct d case VMW_CURSOR_UPDATE_GB_ONLY: case VMW_CURSOR_UPDATE_MOB: { bo = vmw_user_object_buffer(&vps->uo); + if (fb && !bo) + return -EINVAL; + if (bo) { struct ttm_operation_ctx ctx = { false, false }; size_t size = (size_t)new_state->crtc_w * @@ -751,7 +763,7 @@ int vmw_cursor_plane_atomic_check(struct int ret = 0; struct drm_crtc_state *crtc_state = NULL; struct vmw_surface *surface = NULL; - struct vmw_plane_state *vps = vmw_plane_state_to_vps(new_state); + struct vmw_user_object uo; enum vmw_cursor_update_type update_type; struct drm_framebuffer *fb = new_state->fb; @@ -770,7 +782,21 @@ int vmw_cursor_plane_atomic_check(struct if (!fb) return 0; - update_type = vmw_cursor_update_type(vmw, vps); + if (!new_state->crtc_w || !new_state->crtc_h) { + drm_dbg_kms(&vmw->drm, + "Cursor dimensions (%u, %u) must be nonzero\n", + new_state->crtc_w, new_state->crtc_h); + return -EINVAL; + } + + /* The duplicated plane state's user object still belongs to the old FB. */ + uo = vmw_cursor_plane_user_object(fb); + update_type = vmw_cursor_update_type(vmw, &uo); + if ((update_type == VMW_CURSOR_UPDATE_GB_ONLY || + update_type == VMW_CURSOR_UPDATE_MOB) && + !vmw_user_object_buffer(&uo)) + return -EINVAL; + if (update_type == VMW_CURSOR_UPDATE_LEGACY) { if (new_state->crtc_w != VMW_CURSOR_SNOOP_WIDTH || new_state->crtc_h != VMW_CURSOR_SNOOP_HEIGHT) { @@ -779,7 +805,7 @@ int vmw_cursor_plane_atomic_check(struct new_state->crtc_w, new_state->crtc_h); return -EINVAL; } - surface = vmw_user_object_surface(&vps->uo); + surface = vmw_user_object_surface(&uo); if (!surface || !surface->snooper.image) { drm_warn(&vmw->drm, "surface not suitable for cursor\n"); @@ -796,8 +822,7 @@ int vmw_cursor_plane_atomic_check(struct SVGA_CB_MAX_COMMAND_SIZE - sizeof(struct vmw_svga_fifo_cmd_define_cursor)); - if (!new_state->crtc_w || !new_state->crtc_h || - new_state->crtc_w > SVGA_MAX_CURSOR_CMD_DIMENSION || + if (new_state->crtc_w > SVGA_MAX_CURSOR_CMD_DIMENSION || new_state->crtc_h > SVGA_MAX_CURSOR_CMD_DIMENSION || image_size > max_size) { drm_dbg_kms(&vmw->drm,