From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A5D1F606A68F for ; Sat, 21 Nov 2026 05:58:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=jz+cpobc; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=NKTiTFCm DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Reply-To:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Date: Content-Transfer-Encoding:Content-Type:References:In-Reply-To:Cc:To:Subject: From:Message-ID:MIME-Version:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Unsubscribe-Post:List-Owner; bh=nHgcj4reAewShIct0fcYEQHlKrmsjIW5S883i48uYO0=; b=jz+cpobc+Cwp+Zf/D8WcUs5TOC JgxEwkAAIe1Hmw6JSL/vpaoLhctfmMXAb115K4NxmIc9R2sAKukmLoiDMMIx4+zd+bNeegjflxMbW cB23qIqZrv0CjEzhAO5FH3Zi7KUG0iw0gTg/QDicW2P3zxl48IujXOjXY6FM+4sqDjg8gOfE8x/Xw Y5irhxcEV2IBxSlziR2wbED1QyGmZRMtyVwyu17PE/OTJk5Z8TY2IpE4Ao1gaO0uVgtSxPhT8EsRa gSXReLnbSrwx6sTDbcaFucBXons8noGOXtW3xTDebVNdcDEISjstWRQ9j88oQM5fAlPr8RVYYFpjO dY24MtfQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xUe7e-0000000GmUh-1SXF; Sat, 21 Nov 2026 05:58:50 +0000 Received: from tor.source.kernel.org ([172.105.4.254]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xUe7d-0000000GmUT-12UC for linux-nvme@lists.infradead.org; Sat, 21 Nov 2026 05:58:49 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id 516A2601C7; Sat, 21 Nov 2026 05:58:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B3DF51F000C4; Sat, 21 Nov 2026 05:58:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795240728; bh=nHgcj4reAewShIct0fcYEQHlKrmsjIW5S883i48uYO0=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=NKTiTFCmUe9wV/wkagz+EE4Kd6FBLLeeRild/NLY+1KadNk2ZDKp+Aol1cruswpDc dyoxXGVMj2zWLx1VrpmZdBd5cvQT7anKY5OWfaFpfwcwAHH17lung+G3bGPvkL2CbA dnkqBIt9f6NaoRWUZQvkcEeyveyi8ETSBlP51zM6mF7LvR68mzS90wjinQAqySZftz x16OkaQd0ZdtTxTcpVgI33MAFFC6H59HWgr8N7jxVjZ02oVCR2TGNmJrSKmKL6Nef0 tbprkB97zbxR6P0oJcAHbQPOBK3bc+ItmqIKVHkT0so+bJF8nWG5rVwZ+NHRJvOz3o ywc7F1pQrtbqg== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v3 13/24] udmabuf: Convert to the SGT mapping type To: "Alistair Popple" , dri-devel@lists.freedesktop.org, intel-xe@lists.freedesktop.org, amd-gfx@lists.freedesktop.org, linux-rdma@vger.kernel.org, linux-nvme@lists.infradead.org Cc: media-ci@linuxtv.org In-Reply-To: <20261120-dma_mapping_type_v4-v3-13-c0183a409bdf@nvidia.com> References: <20261120-dma_mapping_type_v4-v3-0-c0183a409bdf@nvidia.com> <20261120-dma_mapping_type_v4-v3-13-c0183a409bdf@nvidia.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sat, 21 Nov 2026 05:58:47 +0000 X-BeenThere: linux-nvme@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: sashiko-reviews@lists.linux.dev Sender: "Linux-nvme" X-Spam-Status: No, score=-10.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 X-Archived-By: Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [High] udmabuf: premature publication of ubuf->sg in begin_cpu_udmabuf() -- commit f138ffdf3b226fef46f9eda6001d750e3e320cdd Author: Alistair Popple udmabuf: Convert to the SGT mapping type This commit converts udmabuf to the SGT mapping type by having get_sg_table() and put_sg_table() operate on a caller-allocated struct sg_table and embedding the DMA-buf mapping table in struct dma_buf_sgt_mapping. > diff --git a/drivers/dma-buf/udmabuf.c b/drivers/dma-buf/udmabuf.c > index df6dd00462423..ef77ae063ae4c 100644 > --- a/drivers/dma-buf/udmabuf.c > +++ b/drivers/dma-buf/udmabuf.c [ ... ] > @@ -226,16 +233,19 @@ static int begin_cpu_udmabuf(struct dma_buf *buf, > struct device *dev =3D ubuf->device->this_device; > =20 > if (!ubuf->sg) { > - ubuf->sg =3D get_sg_table(dev, buf, direction); > - if (IS_ERR(ubuf->sg)) { > - int ret; > + int ret; > + > + ubuf->sg =3D kzalloc_obj(*ubuf->sg); > + if (!ubuf->sg) > + return -ENOMEM; > =20 > - ret =3D PTR_ERR(ubuf->sg); > + ret =3D get_sg_table(dev, buf, ubuf->sg, direction); > + if (ret) { > + kfree(ubuf->sg); > ubuf->sg =3D NULL; > return ret; > - } else { > - ubuf->sg_dir =3D direction; > } > + ubuf->sg_dir =3D direction; > } > =20 > dma_sync_sgtable_for_cpu(dev, ubuf->sg, direction); [Severity: High] Can assigning ubuf->sg before get_sg_table() finishes expose an uninitialized, unmapped, or freed sg_table to concurrent DMA_BUF_IOCTL_SYNC callers? dma_buf_ioctl() invokes begin_cpu_udmabuf() and end_cpu_udmabuf() without holding a lock. Previously, get_sg_table() allocated, populated, and DMA-mapped a local struct sg_table before returning it to be stored in ubuf->sg. With ubuf->sg assigned immediately after kzalloc_obj(), a second thread can observe a non-NULL ubuf->sg while the first thread is still inside get_sg_table() (or after kfree(ubuf->sg) on the error path): CPU0 CPU1 begin_cpu_udmabuf() ubuf->sg =3D kzalloc_obj(...) get_sg_table(..., ubuf->sg, ...) sg_alloc_table_from_pages() begin_cpu_udmabuf() if (!ubuf->sg) /* false */ dma_sync_sgtable_for_cpu(..., ubuf->sg, ...) /* uninitialized or freed sgt */ If two threads both enter the !ubuf->sg block, the second kzalloc_obj() also overwrites ubuf->sg while the first thread passes ubuf->sg to get_sg_table(), leaking the first allocation and initializing the same struct sg_table concurrently. Allocating into a local struct sg_table *sg and assigning ubuf->sg only after get_sg_table() succeeds avoids publishing the table prematurely. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261120-dma_mappin= g_type_v4-v3-0-c0183a409bdf@nvidia.com?part=3D13