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=1796221019; b=uinUzEY33GpSWtFMoqGcpwcf9PjnmMAbvuK7pK69/K/gy62X1dCfCV1h/774WwjNN3YY AToH2TcsTwzFKIsse+Ia+y5qXGdLYTPs4Ig1o5JMUUYGY/uMrcYbm6coeT+KlR84F1MLt XmLQEsHdLb6KZgG6AtkuW056g0yoEJUaa4t9tYcMRc82DtuMEYrp7c54f59zLurbzA8Zb AQHNXklwPnBdtbhPB6SI5FDhOr/drMhdsc+/uOgGDOdnow+ioTlq2ajDGRiCx++iPaHAV uWP4KJoU8JDKVSN9M6J8k/zoocwUM1VmQWILlcdRy7mQLgH99Ue02kKmxQ3eaYswCSw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796221019; h=Received:DKIM-Signature:Subject:To:Cc:From:Date:Message-ID: MIME-Version:Content-Type:Content-Transfer-Encoding; bh=ki3sZoyTEOSFbmK44QADTNKhywtgTokkrLOEVo+Iaf8=; b=hgj+1fxDUBtPhsWjcmIs1xf5GdaFa7uizsu+cBmr4uT2lHQkuXA8kp8HM0iE8RH/AEoW /m7UzWeHnLG2kr6U/gzOYCOdtQ9P/GyYJCC2nHye8lzL1EI5O8nyTDtDNpbHqRbgSMLdt 8rm4d/pP9QszoWtmTC3uRejLrIP2vIjSzoFmbaFvT1oV6Zf7g/uCGr2q2k34db3vi8OP3 hvBVg+kq7OrF0I7NmiLzGoqFnwYHogyj/m8sVgGzwV9+Sx4hBy74sgUF6gaI2zJ9bhld6 sX/od03/X0z1FMqeJ1P0pUAhc9JzpFxfII8HHRJ6QG9WKZSyonxzKhbNODD/TrD/gRQ== 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=cQffEJ6+; 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 34E25606A33D for ; Wed, 2 Dec 2026 14:16: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=cQffEJ6+ Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6264A1F00899; Wed, 2 Dec 2026 14:16:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796221019; bh=ki3sZoyTEOSFbmK44QADTNKhywtgTokkrLOEVo+Iaf8=; h=Subject:To:Cc:From:Date; b=cQffEJ6+JgDWDXa3rXOBSQcyyOIIKHm7MuYB0aJa9woqv0x9Q7jNkAYpf1wNgVp/b 5pw5jBAYs3oh78Wc+BnMNUB3GLce8uxWj1EajDaI1yq2d9syD6QvNX8zwYPo2QYIbE sEaRRIvr+kYpUjoSqO/5T2QdCvni02DV95d21xA4= Subject: FAILED: patch "[PATCH] dma: swiotlb: Round restricted DMA pool size down to" failed to apply to 6.18-stable tree To: m.szyprowski@samsung.com,gkobakhi@asu.edu,mhklinux@outlook.com Cc: From: Date: Wed, 02 Dec 2026 14:00:22 +0100 Message-ID: <2026120222-jury-tactful-9b18@gregkh> 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-Type: text/plain; charset=ANSI_X3.4-1968 Content-Transfer-Encoding: 8bit The patch below does not apply to the 6.18-stable tree. If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to . To reproduce the conflict and resubmit, you may use the following commands: git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.18.y git checkout FETCH_HEAD git cherry-pick -x 5b4b87935bf9c6c81b603558c2e167fc27c22a1b # git commit -s git send-email --to '' --in-reply-to '2026120222-jury-tactful-9b18@gregkh' --subject-prefix 'PATCH 6.18.y' 'HEAD^..' Possible dependencies: thanks, greg k-h ------------------ original commit in Linus's tree ------------------ >From 5b4b87935bf9c6c81b603558c2e167fc27c22a1b Mon Sep 17 00:00:00 2001 From: Marek Szyprowski Date: Tue, 3 Nov 2026 16:50:15 +0100 Subject: [PATCH] dma: swiotlb: Round restricted DMA pool size down to IO_TLB_SEGSIZE 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 diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c index db731f7891b7..9b0bc272dd82 100644 --- a/kernel/dma/swiotlb.c +++ b/kernel/dma/swiotlb.c @@ -2012,6 +2012,19 @@ static int rmem_swiotlb_device_init(struct reserved_mem *rmem, 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_obj(*mem); if (!mem) @@ -2039,7 +2052,7 @@ static int rmem_swiotlb_device_init(struct reserved_mem *rmem, 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);