Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Praneeth Balasubramanian <praneethb2002@gmail.com>
To: Russell King <linux@armlinux.org.uk>
Cc: Praneeth Balasubramanian <praneethb2002@gmail.com>,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH] ARM: dma-mapping: Align atomic pool size to PAGE_SIZE
Date: Fri,  4 Dec 2026 22:38:49 -0800	[thread overview]
Message-ID: <20261205063849.2524585-1-praneethb2002@gmail.com> (raw)

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



                 reply	other threads:[~2026-12-05  6:39 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261205063849.2524585-1-praneethb2002@gmail.com \
    --to=praneethb2002@gmail.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox