From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.171 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796452740; b=tgDiO+dkB/wGCDsbmODr1q3R0uvC0omm9quRqo8kocU9VoyLJ2ZR7zZxH3JE5DlhemCJ ZpBGUcT46PbSzHknTid6aaozl5KJc6TYm7/ZRKsYmIsM0XypJPGUFXWnqzHcGIJZMsPNO XSkTnPeqfgiSRq6RMJ/MrjdcEMdgyTz5nahU8tVe6vIygr684abM7caNsXyfp0H47//QT YW2W5admWLMbYeJptptcJFH3RebnANKlOuvm+SkFMVGUC69M05zGmW+0Qbc/8RAoqpUS+ 2LHO8UWY2iJtOjH2HnExFM+ad8u/x3AeT3J3gkIBWX5rMBXpzM208XuJfOz2qr3wIUg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796452740; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-Id:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=PBlLGInyCqP7WQBpNNUB72sEYmt5J8Df/XwA6/WWVho=; b=JJTulGDH8AH496gO3EMzlhLZjCB7OyGcpn3+jVB8Q5frRvZwJS6jdl6EWbKmde2os5J8 jXgCUu+Ofatw66z3lzjPkFI42TZtaD9FA0w55VRH5xYZvzPaNbJRufNiyazZLMlZWOIH2 6kKMxg9KXjG+S4RbibCfz+mo6t5Dy9BOV4sRpK5WUJmG9cHQG2YUCTZU5e3q7+78Gsi03 5+F7uxE3DScJKXPAKTXpuurxXzQ1jDitEJX6Hcu78wuaZbatCsfCWGsh1QICvo+3BBHlv WblHtlaWUxh6JKITCbERNWOdBph4gqcbzTV6JBSH2HrVqy0KsICwNIsz+Y1RKh0BY7g== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b="l6tu/vy1"; arc=none smtp.remote-ip=74.125.82.171 Received: from mail-dy1-f171.google.com (mail-dy1-f171.google.com [74.125.82.171]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 88376606A322 for ; Sat, 5 Dec 2026 06:39:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 88376606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=l6tu/vy1 Received: by mail-dy1-f171.google.com with SMTP id 5a478bee46e88-33bf40b0c8bso3780552eec.0 for ; Fri, 04 Dec 2026 22:39:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796452740; x=1797057540; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=PBlLGInyCqP7WQBpNNUB72sEYmt5J8Df/XwA6/WWVho=; b=l6tu/vy1hbfOcMZjnY28KlWmnnRlxZoEiVoWZa1H0G5uWcD551LbgihjBURAXczwRF A97j9hkitPVTVyeYuJjvWgicGZYYrP6RLLXZeTEVHuZAaeC1rzpnxnlFhqd9iGfWXjV6 g3PGInpK5WcZgGIF7WCXQU+LAHyOMScjypw+iPwKscldangHOBVNlGZPPChro14Dq6G0 mF5G4F9anNtFdpe8NDSBmAmkIFiahTwxJlbYB4b6pqoQWcD0/n1UtuJQJkxABP52FXdn 2Myoo4DIg6vRHJ0q/WwMBpP/PKD3DBgcdea33iLzmnwzkdVAtXHr8NLDjRYpUiLFJdmH 4FvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796452740; x=1797057540; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=PBlLGInyCqP7WQBpNNUB72sEYmt5J8Df/XwA6/WWVho=; b=vjJ2bAvjGT9wYAzVLHxCJgqc+nYKMRRndrXx9ZHAlWHgl9DFsDbT7IDa3ype4r9g+V wXFC5me9CAbRhE9LjV/HxvxvCX4GQ2Jz+myitshUpYyPtw5qwcQzSrsoOOaCSQk8q89A dE2jz7cOP6ga+2BYCExiL4pKEbR29sYXYS14/u3ixYYovILyw4d38y5bnSV4Zne45bLL qCehgGB4GfqvfbIglLFDeT5pK/i3N+Y4IfA6SS11zF+SqhIJ+SyhIo8rGORevwazVVlw rW9xjXFP2TZU6ybjyup2hoBXbRuZFsiJwWpjvzCt0D9Ya/KAYR/c7JL5a+DaEQymm4Wu N/Ig== X-Forwarded-Encrypted: i=1; AL+hErFcM+4kz6otCd1S1Y/aGCzlCJsgBnVEpgDBLSvKApa8lXNTG52PkFnFJxcQWSfmEtrtHkh0zwGq+T2c5f4=@vger.kernel.org X-Gm-Message-State: AB4q+uEhnJXH6wB4qBELOV+HMuZhr1ZEb9ElwQ6RdFwOToAokiUVsnvv LC4dsbuh5cwv4Cj4/9SSXHQcSqh1HZRTEuKODiQpy4nUyA0OE22a/OTt X-Gm-Gg: AZFdTZeL+n/Add8o8uoX/EW6aiNol0uzYPsFkEBbVqL7qOuSu8iV183hf1YkNdAn6Ly Ut6uyFFG6ikU6SrFOa3uoD3OU8MFAO85PP/CP3YYu8bfG0uUl88uVWFQPXzCYCQjQIQ69wyfs8d jHsotrS2zbbcZUiqPKJwovvRJexQWmOC3KHhl0wGsM9EgayfFA6uoHorK+gFI2UukIEUd3TIJ4D v319rR2bpT6wBPxvzukf9vjw5En0Ie8cbJIbH8X81FsavefvOaYFPcrO521FsQjD0LNBs0Zce/8 qfNCc+Vl8jas8tZiPsY4sgA4slR4M8u43ruQjLEf0iqC60ySi9hWd1/MCgYL17rG67uUpivn+oA WWAicLyw4u6ifUvnFSqk4CkOqGu/nEubYghcNPCV6Awc5C3iQGAxAAVHa124P3aExhPSo62PCRz FV4DH4lBvgIqfxChqN1DUXEj0zIQQqk1bePcCMBrZd2sD8iQfrusNH9NevKZD7dC7AgJz8BYVSL F6E8oncU03bmY0I8pGt/3NHJYEXhc9s7ytQhdwzh5UFIT9Cv7NIN0Rs2i4wyNRJbtD+JWzc341Z wzfTdkhQLxP5BJD7FPlMjbz1jlaC0TfNr/jnnrDtPo2cj31kjBE7WCpoKdhuf/bHmlY= X-Received: by 2002:a05:7301:4717:b0:387:7d6:a91e with SMTP id 5a478bee46e88-387520d06e3mr3922828eec.6.1796452739670; Fri, 04 Dec 2026 22:38:59 -0800 (PST) Received: from localhost.localdomain (wood.seclab.cs.ucsb.edu. [128.111.49.37]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3875207adecsm16639448eec.3.2026.12.04.22.38.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2026 22:38:59 -0800 (PST) From: Praneeth Balasubramanian To: Russell King Cc: Praneeth Balasubramanian , 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 Message-Id: <20261205063849.2524585-1-praneethb2002@gmail.com> X-Mailer: git-send-email 2.25.1 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 --- 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