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=1796386540; b=tozjVCa/6IPzFOKC51XZ0jxVtHYiJsBhRpo5PrkU9LNwrh4xQsGWxRfZ4SvnXhiL+5oI WV5hTIlNusaPwaQjWqhc1eEJqIAy2QQJDmSbl7p+9XNsLOgPMnxSrJ+H5Z98ERB/Z1oSb XpjT+slHpVC0Xjd9TtKbyvU2AGRVGUsfTSfk2/ELzqRAMSasm8r/dQgwsPLjCNy07rFj3 spiGZsBTGFOgdRuzdehW38NJ59XIPh8gQzpsPNEUOcD+RLPD0QeY34622XeXb76VzjLzi EIRlZgQcLKz+V1kOmKjUiOwv0h0mhyjQ9SMK7a2Hte06bwfJ0qRIIFhCoXUxEbc7jvw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796386540; 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=pFXJNrpJlha3WEbkX2dVFTNgDGyDFWIfT/jKO0zqWPk=; b=X8x42OauXUNHaofTkzbksmCtN6iuADqSix/M/4g3JrBnUQDS1pF4KueMRtLuiHDRdh05 ZotQNCZVYa5+1PyRiEqys1cgkdJ9RoRsZ6YHBDXKxBJ7HyzOVQYVprTRpuUZI4LxgOSd9 MoOgOzSE6n4FHGLTTpya/uGbw54EH5lEiT3S+rtUtUll3uuUYhfs1I+9MXMXvbx9YiDJ2 xQ4QQ4Poy8luezoTuyoJIrh98iyGFfwN5Vri1NZHoDbSXjUG0P9NDzFdVPytFLU2OJLDn HR7adxYCQg45iAJPTehsJLvErSGGaxzqPRpSt0KN3lm+D54ib7DxxcMBE7O0P+fASPQ== 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=M43lXe0i; 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 9A570606A32D; Fri, 4 Dec 2026 12:15:40 +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=M43lXe0i Received: by smtp.kernel.org (Postfix) with ESMTPSA id CE22A1F00931; Fri, 4 Dec 2026 12:15:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796386540; bh=pFXJNrpJlha3WEbkX2dVFTNgDGyDFWIfT/jKO0zqWPk=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=M43lXe0iqQYJhFQcE7QLrmifmgiav19YrwKvQGINZgoUBMpn17e5jcCQHrbxwHHlG 7Sg1i4bs9FZCXXJoL8PceJZhMP3pGTVgtQX9GBA0X5r/hV1quDEVC6muz/NSaHaJ3g 6mKh85wQwEC8sjoOclbMvPUQlTIFfDTsLke94OTQ= 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.6 1006/1167] drm/vmwgfx: close TOCTOU on guest_memory_bo in surface reference ioctl Date: Fri, 4 Dec 2026 19:07:13 +0900 Message-ID: <20261204100728.411319084@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100702.047403948@linuxfoundation.org> References: <20261204100702.047403948@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.6-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 @@ -1621,23 +1621,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]; @@ -1650,9 +1659,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 =