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=1796383026; b=rm8Jf/mcuA5/t8Vn1oKC2qEHAhUNtrsiO9I56C/sE0GL+S2sIXTGUwxXnD8otDdQIZP9 kCfTNFGsoLeM0S8oagPSFlvpU3A0iFvFmS3mCjS82qIoo6uTUyZnaq7P+jgUz148C1RXe nA7KIuKrSWADDQ5NKolIJ+hZ+A/hCVpe5BSw7lnbtOQSeoeK/uT9WW5k8cRpr9iGrvYCl st/yktkWr1vppkDIreKe+gPJakIusckYchpujPmdieIAblW3h3YpL87hTnZOGXe4mq1vf g7+gK+QMEq3GGHspM/FKlwxK/Vcu+5khzXAx2DWmxk2tzyZYSirqPhIi68F8+woPobw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796383026; 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=RFXNcbzifXLQgyZtdIuB8emdBolf1QE6m9MVVgY75UU=; b=iQ6vkuKnM2swlfVUm5voM0SEC2md0s9NWJZecaLH7vmEtThRply++UVDz1c3OVai6cqN eF/n94ZEijy33h9mJ4h16m4JfGZ7lyh3zOtbNPfdbhpqTRj99y/OhHNarepjdvBoL8ujf Cufb0pGJsS8tqWMzTltlAxOdL9S0Z8DwXbybHRntRvFOQeChz14IADDeMCV2pOuWviL5A dbCQ+Zjmn0aya8UxVTb5SeLyyyKvzwyvqee9cxHQcn/26OrmSPlWNmLEL4cFLRgvqB8il j2Vxb44dEpmBEPeqNBgEYi12ogShUkYRnsC/P/YwOmx1x9OkTv/URq5vm2/7gBN9IxA== 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=uyiFigia; 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 EACFF606A32F; Fri, 4 Dec 2026 11:17:05 +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=uyiFigia Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5A2FC1F00A07; Fri, 4 Dec 2026 11:17:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796383025; bh=RFXNcbzifXLQgyZtdIuB8emdBolf1QE6m9MVVgY75UU=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=uyiFigiaATuDXeIZ9JeGlnAiVYc1Lvupq86oM09+kLgXyHI1xzKIfXBmWV5RnA3hn Sj7qV266YKBaD1NKz1GHX/vvdFo8Pf2hFy+kOwLySuBhH+g26DVlDMFhOajsqAJ6zw 2trBPxwJrASDrzCY7eI+oPBnKZ5tw/nYnV3Rl30I= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Giorgi Kobakhia , Michael Kelley , Marek Szyprowski , Sasha Levin Subject: [PATCH 6.18 695/703] dma: swiotlb: Round restricted DMA pool size down to IO_TLB_SEGSIZE Date: Fri, 4 Dec 2026 19:09:54 +0900 Message-ID: <20261204100646.329834704@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: 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 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Marek Szyprowski [ Upstream commit 5b4b87935bf9c6c81b603558c2e167fc27c22a1b ] All other paths creating a swiotlb pool ensure that nslabs is a multiple of IO_TLB_SEGSIZE, and the swiotlb code relies on that. Since commit 0b84e4f8b793 ("swiotlb: Add restricted DMA pool initialization") a restricted pool can have an arbitrary size taken from the device tree. If the pool size is not a multiple of IO_TLB_SEGSIZE, the last segment is partial and swiotlb_release_slots() reads mem->slots[index + nslabs], which is one past the end of the slots array when the freed buffer ends at the end of the pool: BUG: KASAN: slab-out-of-bounds in swiotlb_release_slots Read of size 2 Round the pool size down to a multiple of IO_TLB_SEGSIZE, wasting a bit of memory, and warn about it. Reported-by: Giorgi Kobakhia Closes: https://lore.kernel.org/all/20261026032007.1957949-1-gkobakhi@asu.edu/ Fixes: 0b84e4f8b793 ("swiotlb: Add restricted DMA pool initialization") CC: stable@vger.kernel.org Reviewed-by: Michael Kelley Link: https://lore.kernel.org/r/20261103155016.1107958-1-m.szyprowski@samsung.com Signed-off-by: Marek Szyprowski [ sashal: Adapted the set_memory_decrypted() hunk to the base's bare call (no cc_shared or error check) and used plain kzalloc(sizeof(*mem), GFP_KERNEL) in place of kzalloc_obj(). ] Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- kernel/dma/swiotlb.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) --- a/kernel/dma/swiotlb.c +++ b/kernel/dma/swiotlb.c @@ -1849,6 +1849,19 @@ static int rmem_swiotlb_device_init(stru mem = rmem->priv; if (!mem) { struct io_tlb_pool *pool; + unsigned long aligned_nslabs = ALIGN_DOWN(nslabs, IO_TLB_SEGSIZE); + + if (aligned_nslabs != nslabs) { + dev_warn(dev, "Restricted DMA pool size %zu is not a multiple of %lu, rounding down to %lu bytes\n", + (size_t)rmem->size, + (unsigned long)IO_TLB_SEGSIZE << IO_TLB_SHIFT, + aligned_nslabs << IO_TLB_SHIFT); + nslabs = aligned_nslabs; + } + if (!nslabs) { + dev_err(dev, "Restricted DMA pool is too small\n"); + return -EINVAL; + } mem = kzalloc(sizeof(*mem), GFP_KERNEL); if (!mem) @@ -1870,7 +1883,7 @@ static int rmem_swiotlb_device_init(stru } set_memory_decrypted((unsigned long)phys_to_virt(rmem->base), - rmem->size >> PAGE_SHIFT); + (nslabs << IO_TLB_SHIFT) >> PAGE_SHIFT); swiotlb_init_io_tlb_pool(pool, rmem->base, phys_to_virt(rmem->base), nslabs, false, nareas);