* FAILED: patch "[PATCH] dma: swiotlb: Round restricted DMA pool size down to" failed to apply to 6.1-stable tree
@ 2026-12-02 13:00 gregkh
0 siblings, 0 replies; only message in thread
From: gregkh @ 2026-12-02 13:00 UTC (permalink / raw)
To: m.szyprowski, gkobakhi, mhklinux; +Cc: stable
The patch below does not apply to the 6.1-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 <stable@vger.kernel.org>.
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.1.y
git checkout FETCH_HEAD
git cherry-pick -x 5b4b87935bf9c6c81b603558c2e167fc27c22a1b
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<stable@vger.kernel.org>' --in-reply-to '2026120224-send-each-3f44@gregkh' --subject-prefix 'PATCH 6.1.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 <m.szyprowski@samsung.com>
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 <gkobakhi@asu.edu>
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 <mhklinux@outlook.com>
Link: https://lore.kernel.org/r/20261103155016.1107958-1-m.szyprowski@samsung.com
Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
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);
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-12-02 14:17 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02 13:00 FAILED: patch "[PATCH] dma: swiotlb: Round restricted DMA pool size down to" failed to apply to 6.1-stable tree gregkh
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox