From: "Shubhang Kaushik (Ampere)" <sh@gentwo.org>
To: Andrew Morton <akpm@linux-foundation.org>,
Uladzislau Rezki <urezki@gmail.com>,
Nicholas Piggin <npiggin@gmail.com>,
Shubhang Kaushik <shubhang@os.amperecomputing.com>,
"Christoph Lameter (Ampere)" <cl@gentwo.org>
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
"Shubhang Kaushik (Ampere)" <sh@gentwo.org>
Subject: [PATCH] mm/vmalloc: reject overflowing vm_map_ram page counts
Date: Thu, 22 Oct 2026 16:35:20 -0700 [thread overview]
Message-ID: <20261022-vmalloc-reject-overflow-v1-1-5fde0042ffb9@gentwo.org> (raw)
vm_map_ram() converts its unsigned int page count to an unsigned long
byte size without checking for overflow.
On 32-bit kernels, a count greater than ULONG_MAX >> PAGE_SHIFT wraps
the byte size. vm_map_ram() passes that size to both alloc_vmap_area()
and vmap_pages_range(), so it can allocate and map only the wrapped
number of pages while returning success for the original larger request.
For example, with 4 KiB pages, a count of 1048577 produces a
PAGE_SIZE byte size after wrapping, allowing a one-page mapping.
Reject page counts whose byte size cannot be represented.
Fixes: db64fe02258f ("mm: rewrite vmap layer")
Signed-off-by: Shubhang Kaushik (Ampere) <sh@gentwo.org>
---
mm/vmalloc.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index bea9f76ed7e74247d4ce919250c2f02dd5c36483..e98d3aa551fe205ebd9826daad9ad6bd578b91ea 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -3083,10 +3083,15 @@ EXPORT_SYMBOL(vm_unmap_ram);
*/
void *vm_map_ram(struct page **pages, unsigned int count, int node)
{
- unsigned long size = (unsigned long)count << PAGE_SHIFT;
+ unsigned long size;
unsigned long addr;
void *mem;
+ if (count > ULONG_MAX >> PAGE_SHIFT)
+ return NULL;
+
+ size = (unsigned long)count << PAGE_SHIFT;
+
if (likely(count <= VMAP_MAX_ALLOC)) {
mem = vb_alloc(size, GFP_KERNEL);
if (IS_ERR(mem))
---
base-commit: 7be4bc52fd9e0e55dc9a2e0232b89427d2c4b614
change-id: 20261022-vmalloc-reject-overflow-e532c556f3fa
Best regards,
--
Shubhang Kaushik (Ampere) <sh@gentwo.org>
next reply other threads:[~2026-10-22 23:35 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-22 23:35 Shubhang Kaushik (Ampere) [this message]
2026-10-23 3:19 ` Andrew Morton
2026-10-23 6:12 ` Shubhang
2026-10-23 6:54 ` Dev Jain
2026-10-23 7:37 ` Shubhang
2026-10-23 11:22 ` Anshuman Khandual
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=20261022-vmalloc-reject-overflow-v1-1-5fde0042ffb9@gentwo.org \
--to=sh@gentwo.org \
--cc=akpm@linux-foundation.org \
--cc=cl@gentwo.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=npiggin@gmail.com \
--cc=shubhang@os.amperecomputing.com \
--cc=urezki@gmail.com \
/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
all inboxes | Powered by JetHome®