Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ARM: dma-mapping: Align atomic pool size to PAGE_SIZE
@ 2026-12-05  6:38 Praneeth Balasubramanian
  0 siblings, 0 replies; only message in thread
From: Praneeth Balasubramanian @ 2026-12-05  6:38 UTC (permalink / raw)
  To: Russell King; +Cc: Praneeth Balasubramanian, linux-arm-kernel, linux-kernel

The coherent_pool= boot option stores an arbitrary value in
atomic_pool_size. When the kernel has no default CMA area,
atomic_pool_init() passes that value to __alloc_remap_buffer(), which
forwards it to __dma_alloc_buffer().

__dma_alloc_buffer() requires a page aligned size. With a sub-page
value such as coherent_pool=1K it allocates one order-0 page. The loop
that frees excess pages then frees that page. __dma_clear_buffer()
writes to it after it is freed. Sizes that are not a multiple of the
page size overrun the clear into freshly freed pages in the same way.

The value comes from a boot option set by the user. The harm is limited
to that case and this is a robustness fix.

Round atomic_pool_size up with PAGE_ALIGN in atomic_pool_init() so the
page allocation, the remap and the gen_pool registration all use a
page aligned size.

This was found by an LLM-based audit that checks code against the rules
stated in kernel comments.

Signed-off-by: Praneeth Balasubramanian <praneethb2002@gmail.com>
---

Notes:
    This was found by an LLM-based audit, part of research at UCSB SecLab.
    An LLM turned a kernel comment into a rule, and three LLM votes checked
    the code against it. The fix and changelog were drafted with GLM-5.3 and
    checked against the source with Claude Opus 5.5. I reviewed the patch
    and take responsibility for it.
    
    Testing: builds without new warnings with W=1 (arm multi_v7_defconfig),
    clang 23. checkpatch.pl is clean. Not runtime-tested, and there is no
    reproducer. I do not have this hardware.

 arch/arm/mm/dma-mapping.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c
index fb2eb0ed7bb8..d46da5e6d988 100644
--- a/arch/arm/mm/dma-mapping.c
+++ b/arch/arm/mm/dma-mapping.c
@@ -207,6 +207,13 @@ static int __init atomic_pool_init(void)
 	atomic_pool = gen_pool_create(PAGE_SHIFT, -1);
 	if (!atomic_pool)
 		goto out;
+
+	/*
+	 * The pool is backed by whole pages, and __dma_alloc_buffer()
+	 * requires a page aligned size.
+	 */
+	atomic_pool_size = PAGE_ALIGN(atomic_pool_size);
+
 	/*
 	 * The atomic pool is only used for non-coherent allocations
 	 * so we must pass NORMAL for coherent_flag.

base-commit: 29beb21c21ada7207692b2d69fc58dcd15dab6e9
-- 
2.25.1



^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-12-05  6:39 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-05  6:38 [PATCH] ARM: dma-mapping: Align atomic pool size to PAGE_SIZE Praneeth Balasubramanian

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox