From: Elkin Cruz <elkin@google.com>
To: David Hildenbrand <david@kernel.org>, Zi Yan <ziy@nvidia.com>,
Andrew Morton <akpm@linux-foundation.org>
Cc: Baolin Wang <baolin.wang@linux.alibaba.com>,
"Liam R. Howlett" <liam@infradead.org>,
Nico Pache <nico.pache@linux.dev>,
Ryan Roberts <ryan.roberts@arm.com>, Dev Jain <dev.jain@arm.com>,
Barry Song <baohua@kernel.org>,
Lance Yang <lance.yang@linux.dev>,
Usama Arif <usama.arif@linux.dev>,
Kiryl Shutsemau <kas@kernel.org>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
llvm@lists.linux.dev, irogers@google.com,
Elkin Cruz <elkin@google.com>
Subject: [PATCH v2] mm/huge_memory: check VMA end bounds in insert_pmd() and insert_pud()
Date: Wed, 2 Dec 2026 20:00:56 +0000 [thread overview]
Message-ID: <20261202200056.3555477-1-elkin@google.com> (raw)
insert_pmd() and insert_pud() currently check only that addr lies within
[vma->vm_start, vma->vm_end), without verifying that the full PMD or PUD
mapping fits below vma->vm_end.
All current in-tree callers already validate VMA end alignment/bounds,
so no existing user triggers this. Harden both helpers defensively by
requiring addr + HPAGE_PMD_SIZE <= vma->vm_end in insert_pmd() and
addr + HPAGE_PUD_SIZE <= vma->vm_end in insert_pud().
Signed-off-by: Elkin Cruz <elkin@google.com>
---
Changes in v2:
- Simplify checks to addr + HPAGE_{PMD,PUD}_SIZE > vma->vm_end
(per David Hildenbrand).
v1: https://lore.kernel.org/r/20261125221911.1425213-1-elkin@google.com
This came up from a new Clang static analysis check for kernel bug
classes. The fix is entirely a hardenning change :).
Thanks,
Elkin
mm/huge_memory.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index e167c9ea4609..bea537e9c7c3 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -1630,7 +1630,7 @@ static vm_fault_t insert_pmd(struct vm_area_struct *vma, unsigned long addr,
spinlock_t *ptl;
pmd_t entry;
- if (addr < vma->vm_start || addr >= vma->vm_end)
+ if (addr < vma->vm_start || addr + HPAGE_PMD_SIZE > vma->vm_end)
return VM_FAULT_SIGBUS;
if (arch_needs_pgtable_deposit()) {
@@ -1771,7 +1771,7 @@ static vm_fault_t insert_pud(struct vm_area_struct *vma, unsigned long addr,
spinlock_t *ptl;
pud_t entry;
- if (addr < vma->vm_start || addr >= vma->vm_end)
+ if (addr < vma->vm_start || addr + HPAGE_PUD_SIZE > vma->vm_end)
return VM_FAULT_SIGBUS;
ptl = pud_lock(mm, pud);
--
2.56.1.911.g883d8bcb20-goog
next reply other threads:[~2026-12-02 20:01 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 20:00 Elkin Cruz [this message]
2026-12-02 20:09 ` [PATCH v2] mm/huge_memory: check VMA end bounds in insert_pmd() and insert_pud() Zi Yan
2026-12-02 20:29 ` David Hildenbrand (Arm)
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=20261202200056.3555477-1-elkin@google.com \
--to=elkin@google.com \
--cc=akpm@linux-foundation.org \
--cc=baohua@kernel.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=david@kernel.org \
--cc=dev.jain@arm.com \
--cc=irogers@google.com \
--cc=kas@kernel.org \
--cc=lance.yang@linux.dev \
--cc=liam@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=llvm@lists.linux.dev \
--cc=nico.pache@linux.dev \
--cc=ryan.roberts@arm.com \
--cc=usama.arif@linux.dev \
--cc=ziy@nvidia.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