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=1796380788; b=sw9C9deW6kzclQQd1AOVLLpAfoe8vKp5xenTs8YtcP7/Bji/nSkf99B7/+frGAZvqQdi s6Jr4OOHdc+dQJcqGpRDlsq+gDf2MkqkYGbjwHhMGw+YJllNbRvfVfi6tDFBRY6SlDT5R BV1yzkEo/b43hZpCcnJ9UXrtoENJst6+elSPo5eilzaJ6jg/lSD72DEw1jjL17UQys4Dr tGbln/fJmfs+pAkh+d6kfnEGBH8YI430UBxGifqtBg60vbkqRViZimhQIBZwpDUOYvO41 WVbDU41PpcEfHahQpJyGNcOYzde1/j8jnS1VhhV542UwSdWsbChSvzys941JcJnPmug== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796380788; 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=ywqaPRvhQ4m/Wa4R9qOWe4JVg7qnDWP+gWUSFOiSoCo=; b=eIU2iGGvJqgHl9HYfW62AVkCVfhuPxvgM7/0Pzg1wTLA3JRRLOn+skBpAVOaMtNudjdH M9EV9GfG+3TYzCx+3oZW1aWdxZk2QpH2psS52CYpcfexQtwOSpUHmAf16SNxOSTyIPcEF WnRm0hd/+trzGz+TOLmO26fzwnMQAImnltgVcQF3Uc4Tc9G1HVDlutbbA0iVfvG3S8fE4 A1POeoIH31eU9xwXyos/ymaGV8ZzFZqu9Z+nsYwlCwKA4A852mdEaLqs1chXq3zahGp3k ZNO3VmY0uFvvuTMXobMwpr4NcDN2aTvPaxAyjPW0QEOduZBZ2Xs4vpq1iAcR57KrL2Q== 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=pORy3ZBO; 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 17912606A322; Fri, 4 Dec 2026 10:39: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=pORy3ZBO Received: by smtp.kernel.org (Postfix) with ESMTPSA id 811371F000CE; Fri, 4 Dec 2026 10:39:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796380787; bh=ywqaPRvhQ4m/Wa4R9qOWe4JVg7qnDWP+gWUSFOiSoCo=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=pORy3ZBO6T/n5YvNCqbvCs7S1/ALB8HcO418IiQVCCMM9kceGnm1rwfn+G9xSMF3y VOZUBrqGx8ayWVU/Gygkq4nzthF8O0rhtK120eFGo1JMZoUQBNqBtF1KGE9M9MN9jd V8CBgEyLTTHFBbqy1JkmazVXyiBgoRmEPwX6y738= 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 7.3 424/742] drm/vmwgfx: close TOCTOU on guest_memory_bo in surface reference ioctl Date: Fri, 4 Dec 2026 19:04:48 +0900 Message-ID: <20261204100646.365982333@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: 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 7.3-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 =