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=1796386528; b=I2RdQYQU5TrK1STfn3Tb8I7j9ZL6hPfCdPaHnNJKOgWaHek5CuneZZToPF7LVmGqSfGn 16jFmdryuxdkewdryYRRwmb/F/+420XKxkM5Miwju6RYmp4m5VqAEGjWxt8ngbreaFtkb EOcyjEoVGGEBtUeNkiPRzsV9XEoiA4ut/q4yxi+vPXXIk8CNnn053VxERzXEWt+Y/tkkw OLZCiRNf4RBjQL/SKelAxMn+n8+FFI0dmuirokDIyn76V9L7gqMeck+re6d34WPARaApG sv5dI7/RcTX9RF5AyTLS0hGcSM7Ve+sby6hV+n0gvFW8EzNOm3sUo5/3pr+M2jd+uyA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796386528; 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=s7UHPJFI5WTDARu9NeIbMilgQhYXcEp2pXETUgj6NSc=; b=IebiSUT9cfvDYr136vuGnHlicCmwjUcX4LPCOcJwB12gL9I6X5S6GpxD/4rpzf4ngcT0 zocq0EzqWKBxQNnokSxbTdmQGIHCVRCHDoPZneexG3+qvpISofx8apU5twOESWrbwa3KL IQC/BMUxuvjAmTAddYzpZsjCSxWHZVKw5W28cLS6AKj9QQG/7R5y4cmNzcNb4/xaP7vDK hwar18JJ+pxPYbRYOmREpgTHeM4fE+WugZgeSTK/7GMf644VvUsp7eCtF4ZYPCF/SY5Nz 6B73kgKqZznSaUoYbULdAHGw5md68ZNGxyDiHKV6jast91dYMOgOFgPnKR8dEMyIsew== 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=VjxTKC86; 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 D9F93606A32D; Fri, 4 Dec 2026 12:15:28 +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=VjxTKC86 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 518091F00936; Fri, 4 Dec 2026 12:15:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796386528; bh=s7UHPJFI5WTDARu9NeIbMilgQhYXcEp2pXETUgj6NSc=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=VjxTKC86OnIgXm5mButgm0EaElhwM/kG7/UmQdrpT2wiP3vq4/yltaEZTsWB3mqiG r4m971/5ve4jXQvo/ISNfT8y4PseqoHfGJTr2IMD0S9oLRs/ssMh6ClzaupE7QsJ07 IrhBMe1/+FMMkgufl0PtUsSc6MnOQfvB+oSHDV7I= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Aldo Ariel Panzardo , Zack Rusin Subject: [PATCH 6.6 1001/1167] drm/vmwgfx: do not hand the embedded sg_table to the PRIME core Date: Fri, 4 Dec 2026 19:07:08 +0900 Message-ID: <20261204100728.282741423@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 030e6d11d3e5eb7328f7a3e8177737a4b1c30654 upstream. vmw_gem_object_get_sg_table() returns vmw_tt->vsgt.sgt when the buffer object has already been DMA mapped. vmw_ttm_map_dma() sets that field to &vmw_tt->sgt, which is a member embedded inside the struct vmw_ttm_tt allocation and not a table of its own. The core owns whatever .get_sg_table returns. drm_gem_map_dma_buf() takes the table and drm_gem_unmap_dma_buf() destroys it in full: dma_unmap_sgtable(attach->dev, sgt, dir, DMA_ATTR_SKIP_CPU_SYNC); sg_free_table(sgt); kfree(sgt); Both are ops of drm_gem_prime_dmabuf_ops, so the core ends up calling kfree() on &vmw_tt->sgt, which is not the start of an allocation. The preceding sg_free_table() also destroys a scatterlist that vmwgfx still considers its own and frees again from vmw_ttm_unmap_dma(). drm_gem_unmap_dma_buf() runs from dma_buf_detach(), including the importer's error path, so a failed import is enough to reach it: exporting a bound buffer with DRM_IOCTL_PRIME_HANDLE_TO_FD and importing it on a second DRM device with DRM_IOCTL_PRIME_FD_TO_HANDLE is sufficient. Both ioctls are DRM_RENDER_ALLOW. Observed on 6.12.101 with KASAN, as uid 65534: BUG: KASAN: invalid-free in drm_gem_unmap_dma_buf+0xb3/0xf0 Free of addr ffff888008290450 by task poc_mm04_sgtabl/321 CPU: 1 UID: 65534 PID: 321 Comm: poc_mm04_sgtabl Not tainted 6.12.101 #4 kasan_report_invalid_free+0x94/0xc0 check_slab_allocation+0x116/0x120 kfree+0x103/0x360 drm_gem_unmap_dma_buf+0xb3/0xf0 dma_buf_detach+0x165/0x510 drm_gem_prime_import_dev+0x33e/0x430 which belongs to the cache kmalloc-192 of size 192 The buggy address is located 80 bytes inside of 144-byte region [ffff888008290400, ffff888008290490) 80 is offsetof(struct vmw_ttm_tt, sgt) and 144 is sizeof(struct vmw_ttm_tt), which identifies the freed pointer as the embedded member. Always return a table the core can own, as the other drivers do. Reusing the cached representation would require copying it into a freshly allocated sg_table, never returning the alias. Fixes: 8afa13a0583f ("drm/vmwgfx: Implement DRIVER_GEM") Cc: stable@vger.kernel.org Signed-off-by: Aldo Ariel Panzardo Reviewed-by: Zack Rusin Signed-off-by: Zack Rusin Link: https://patch.msgid.link/20260923122601.438892-1-qwe.aldo@gmail.com Signed-off-by: Greg Kroah-Hartman --- drivers/gpu/drm/vmwgfx/vmwgfx_gem.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) --- a/drivers/gpu/drm/vmwgfx/vmwgfx_gem.c +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_gem.c @@ -83,10 +83,13 @@ static struct sg_table *vmw_gem_object_g struct vmw_ttm_tt *vmw_tt = container_of(bo->ttm, struct vmw_ttm_tt, dma_ttm); - if (vmw_tt->vsgt.sgt) - return vmw_tt->vsgt.sgt; - - return drm_prime_pages_to_sg(obj->dev, vmw_tt->dma_ttm.pages, vmw_tt->dma_ttm.num_pages); + /* + * Do not return &vmw_tt->sgt: the core owns what this returns and + * drm_gem_unmap_dma_buf() sg_free_table()s and kfree()s it, but that + * sg_table is embedded in the vmw_ttm_tt allocation. + */ + return drm_prime_pages_to_sg(obj->dev, vmw_tt->dma_ttm.pages, + vmw_tt->dma_ttm.num_pages); } static const struct vm_operations_struct vmw_vm_ops = {