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=1796380859; b=nRElX3ciVUY5o5kJmde2RSLTxUX3heOsI/c6aWPCnTcxmfCirqchgD4mrlWi1rFpM7bn w7yv7QHn1q1vFegV0UgY23EsVEVD8pwdXqSkSrGLiFNpSUMx6sqpy9DWqEN0ysTUBZ7Hh DI3VDGlnkVhrMkB4VwCdgSB7vfs8TfMMdtNzw4xv0fYyqrOxqdwrK0kzfDf7iASjpE9fd ZGgcTucOJxVqORO0MrkTLRkmHO7bWjx12G5nwyynSihdX7WMzRl6nUuDTTxFb3l8Kka+Y pvqzR9AOD7HSwwuqe2Jc7hH9V5FsLr3rh26XCuNymEK7BKzAlkSAcJj5Yjar++HPPdA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796380859; 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=MWnk+gUeE8MOGzxjWYTTFSRMftwk9hzCyC1WRg7npOk=; b=y14dmW1N2j5gTo6HQMbI7rzy3qLPtUQcqW0BHTyNVJ4GXvCBcjN9bq21DFuWoeuNnOZg 6gBcCz32deLBsBMn1uVwMKiZGKNVAbYp8vEawsDD00TcYXNKJiqe7LKAnW2aQlxPSdzrN vneMwR1NgHz6f1RN1Sf17ZJ4zR6ka5Yt3xMkKple0FfSqyuVmYJtOR2FPnrrFbuH3rZUP kK3SXrfM9clmGDEiLPtuC5W9bMX/IhIJ9xwok/SFFZzKs8qNRHIZJLzXgfH783RMXyz4j ZOskjEaueBf7IdRBTitlqyycTgR6Tko9Y7xssVvDvq7hdkcHsx96SLuf7cvzL/JSsIg== 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="06ry/J/2"; 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 BF0EC606A322; Fri, 4 Dec 2026 10:40:59 +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=06ry/J/2 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0B33A1F000C2; Fri, 4 Dec 2026 10:40:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796380859; bh=MWnk+gUeE8MOGzxjWYTTFSRMftwk9hzCyC1WRg7npOk=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=06ry/J/2yUGpwg3UHy09dtUxXdvLPIwjyln/LOCx+ryD75993PxsKGhSk7CfCJPj3 ONVqQiUWXoGTPQ+uBR2KelrseAb4XjvBVIhroLz3MhDvKLSfbmQulgMCFAfQVHb43F tAky0Vg63+zM8fOJ3YZJ1Ps1ieXPOquS2WpHGKas= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Giorgi Kobakhia , Michael Kelley , Marek Szyprowski Subject: [PATCH 7.3 456/742] dma: swiotlb: Round restricted DMA pool size down to IO_TLB_SEGSIZE Date: Fri, 4 Dec 2026 19:05:20 +0900 Message-ID: <20261204100647.276540154@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: Marek Szyprowski commit 5b4b87935bf9c6c81b603558c2e167fc27c22a1b upstream. 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 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 @@ -2020,6 +2020,19 @@ static int rmem_swiotlb_device_init(stru */ 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_obj(*mem); if (!mem) @@ -2047,7 +2060,7 @@ static int rmem_swiotlb_device_init(stru mem->cc_shared = true; ret = set_memory_decrypted((unsigned long)phys_to_virt(rmem->base), - rmem->size >> PAGE_SHIFT); + (nslabs << IO_TLB_SHIFT) >> PAGE_SHIFT); if (ret) { dev_err(dev, "Failed to decrypt restricted DMA pool\n"); kfree(pool->areas);