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=1796382288; b=fp0vJbOjLPObSYWa4PhMzHmCjQ6IMEF3/f0ha8J5lwC6AAfoG3Ls3/6G1BDEtn0+w7k2 Bt5oWqXn9g8k9yYxGn5azc7wKCOlLqS5m1LnhHUilmWFifzyWpiVnWmVcY00bsZwwg3TV /VqqA7t3lDWzU0A9hBOCuYg9dqJ5Sxckz92fNq2Oq9z/XKLn1F427sstSljkWnYLFSo0x 3JwfAdoi0bnsvVNNFqydWcAGISsMOeQ+CrK3fM0QslLQ0Z9/bvXmBIbYHumt9OOO+B2k/ sIsZuS1Lqsjqsw0hwjmoAuZGQI5Bweliui+ID7q11LS4U70VLFntCyrntYF/VPyYE8g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796382288; 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=pDrDj94+yDD6rvP7uCYv9pzD1wAzz3T5JdnKCVJAYAw=; b=vBvLap2Ibds5Cs21YHaUEuHUEowrDw22YFscCf+9Z7QW73UJpI7BXjtyhCrnJuwHH6wV OuSYieaUDrbzy3fdd7CkyKC3ERUL5KlUPPmdo+RBgqbcONFRfOy0zeeCxi1WA8ClPp/SC zoYkH/ztok+rzMGLh4hFS3hyqCUHcVVVpIkqxTpIJ/0j7cTYprtO1DHdrP0iv+ilnpNCT 3+5SmBLoP5uxy5hhZwPOx3lr2bBDAeZVgmfFW73isi6PUvplzkJ5/b2wm0HLe775iAXTS zu4y7gS1mQIuSBygtC4cp0gFQUvmK4CNxPYIVIDVLsW4hetzkChWHAIjvbLAMZq4KQQ== 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=KPa3H19v; 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 37616606A322; Fri, 4 Dec 2026 11:04:48 +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=KPa3H19v Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9E1CE1F000CE; Fri, 4 Dec 2026 11:04:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796382288; bh=pDrDj94+yDD6rvP7uCYv9pzD1wAzz3T5JdnKCVJAYAw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=KPa3H19vPbovPfUQniW08dGFfrTPB5+uEaowU+ALBy4899O0pePKCjEnJ7bY1L0zL BveNobwG9Y1cZK+PCyZPbmcHcf87UArFWgQUX0a4og3p3xlmA6/WViu+y5zAUtUta9 lyVH6XBrHT/ObO7WXhPbObuvr62tKjJL3sp3komI= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Sashiko , Aldo Ariel Panzardo , Zack Rusin Subject: [PATCH 6.18 389/703] drm/vmwgfx: close TOCTOU on guest_memory_bo in surface reference ioctl Date: Fri, 4 Dec 2026 19:04:48 +0900 Message-ID: <20261204100638.187456739@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: 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 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Aldo Ariel Panzardo commit 30131b82b062180183a09a97183a944fadab72ee upstream. vmw_gb_surface_reference_internal() checks srf->res.guest_memory_bo for NULL and reads its vma_node offset and base.size outside the cmdbuf_mutex scope that protects the backup pointer. A concurrent backup switch, e.g. from SVGA_3D_CMD_BIND_GB_SURFACE via vmw_resource_unreserve(), drops its reference to the old buffer and installs a new one under cmdbuf_mutex. The unlocked check in the surface reference ioctl can see a transient NULL. The reads after the unlock can return another buffer's offset and size; a further switch can drop that buffer's last reference and free it while the ioctl reads from it. Move the NULL check inside the mutex, and read buffer_map_handle and buffer_size while still holding it. Fixes: a97e21923b42 ("drm/vmwgfx: Hook up guest-backed surfaces") Cc: stable@vger.kernel.org Reported-by: Sashiko Closes: https://lore.kernel.org/r/20260808233347.209DD1F000E9@smtp.kernel.org Signed-off-by: Aldo Ariel Panzardo Reviewed-by: Zack Rusin Signed-off-by: Zack Rusin Link: https://patch.msgid.link/20261007212051.2574235-3-qwe.aldo@gmail.com Signed-off-by: Greg Kroah-Hartman --- drivers/gpu/drm/vmwgfx/vmwgfx_surface.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) --- a/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c @@ -1718,23 +1718,32 @@ vmw_gb_surface_reference_internal(struct user_srf = container_of(base, struct vmw_user_surface, prime.base); srf = &user_srf->srf; + metadata = &srf->metadata; + + mutex_lock(&dev_priv->cmdbuf_mutex); + if (!srf->res.guest_memory_bo) { + mutex_unlock(&dev_priv->cmdbuf_mutex); DRM_ERROR("Shared GB surface is missing a backup buffer.\n"); ret = -EINVAL; goto out_bad_resource; } - metadata = &srf->metadata; - mutex_lock(&dev_priv->cmdbuf_mutex); /* Protect res->backup */ ret = drm_gem_handle_create(file_priv, &srf->res.guest_memory_bo->tbo.base, &backup_handle); - mutex_unlock(&dev_priv->cmdbuf_mutex); if (ret != 0) { + mutex_unlock(&dev_priv->cmdbuf_mutex); drm_err(dev, "Wasn't able to create a backing handle for surface sid = %u.\n", req->sid); goto out_bad_resource; } + rep->crep.buffer_map_handle = + drm_vma_node_offset_addr(&srf->res.guest_memory_bo->tbo.base.vma_node); + rep->crep.buffer_size = srf->res.guest_memory_bo->tbo.base.size; + + mutex_unlock(&dev_priv->cmdbuf_mutex); + rep->creq.base.svga3d_flags = SVGA3D_FLAGS_LOWER_32(metadata->flags); rep->creq.base.format = metadata->format; rep->creq.base.mip_levels = metadata->mip_levels[0]; @@ -1747,9 +1756,6 @@ vmw_gb_surface_reference_internal(struct rep->crep.handle = user_srf->prime.base.handle; rep->crep.backup_size = srf->res.guest_memory_size; rep->crep.buffer_handle = backup_handle; - rep->crep.buffer_map_handle = - drm_vma_node_offset_addr(&srf->res.guest_memory_bo->tbo.base.vma_node); - rep->crep.buffer_size = srf->res.guest_memory_bo->tbo.base.size; rep->creq.version = drm_vmw_gb_surface_v1; rep->creq.svga3d_flags_upper_32_bits =