From: Sasha Levin <sashal@kernel.org>
To: stable@vger.kernel.org
Cc: Marek Szyprowski <m.szyprowski@samsung.com>,
Giorgi Kobakhia <gkobakhi@asu.edu>,
Michael Kelley <mhklinux@outlook.com>,
Sasha Levin <sashal@kernel.org>
Subject: [PATCH 6.12.y] dma: swiotlb: Round restricted DMA pool size down to IO_TLB_SEGSIZE
Date: Thu, 3 Dec 2026 14:22:51 -0500 [thread overview]
Message-ID: <20261203192217.628646-1-sashal@kernel.org> (raw)
In-Reply-To: <2026120222-bottom-shortwave-016f@gregkh>
From: Marek Szyprowski <m.szyprowski@samsung.com>
[ 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 <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>
[ sashal: adapted to older tree: kzalloc(sizeof(*mem), GFP_KERNEL) instead of kzalloc_obj, and the size fix applied to the plain set_memory_decrypted() call (no cc_shared/ret error handling). ]
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
kernel/dma/swiotlb.c | 15 ++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)
diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index c0cc95297222b..58eba9f70b0f6 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -1849,6 +1849,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(sizeof(*mem), GFP_KERNEL);
if (!mem)
@@ -1870,7 +1883,7 @@ static int rmem_swiotlb_device_init(struct reserved_mem *rmem,
}
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);
--
2.53.0
prev parent reply other threads:[~2026-12-03 19:22 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 13:00 FAILED: patch "[PATCH] dma: swiotlb: Round restricted DMA pool size down to" failed to apply to 6.12-stable tree gregkh
2026-12-03 19:22 ` Sasha Levin [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261203192217.628646-1-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=gkobakhi@asu.edu \
--cc=m.szyprowski@samsung.com \
--cc=mhklinux@outlook.com \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.