* [PATCH v2] mm/huge_memory: check VMA end bounds in insert_pmd() and insert_pud()
@ 2026-12-02 20:00 Elkin Cruz
2026-12-02 20:09 ` Zi Yan
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Elkin Cruz @ 2026-12-02 20:00 UTC (permalink / raw)
To: David Hildenbrand, Zi Yan, Andrew Morton
Cc: Baolin Wang, Liam R. Howlett, Nico Pache, Ryan Roberts, Dev Jain,
Barry Song, Lance Yang, Usama Arif, Kiryl Shutsemau, linux-mm,
linux-kernel, llvm, irogers, Elkin Cruz
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
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2] mm/huge_memory: check VMA end bounds in insert_pmd() and insert_pud()
2026-12-02 20:00 [PATCH v2] mm/huge_memory: check VMA end bounds in insert_pmd() and insert_pud() Elkin Cruz
@ 2026-12-02 20:09 ` Zi Yan
2026-12-02 20:29 ` David Hildenbrand (Arm)
2026-12-02 20:45 ` + mm-huge_memory-check-vma-end-bounds-in-insert_pmd-and-insert_pud.patch added to mm-new branch Andrew Morton
2 siblings, 0 replies; 4+ messages in thread
From: Zi Yan @ 2026-12-02 20:09 UTC (permalink / raw)
To: Elkin Cruz
Cc: David Hildenbrand, Andrew Morton, Baolin Wang, Liam R. Howlett,
Nico Pache, Ryan Roberts, Dev Jain, Barry Song, Lance Yang,
Usama Arif, Kiryl Shutsemau, linux-mm, linux-kernel, llvm,
irogers
On 2 Dec 2026, at 15:00, Elkin Cruz wrote:
> 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(-)
>
LGTM.
Reviewed-by: Zi Yan <ziy@nvidia.com>
Best Regards,
Yan, Zi
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] mm/huge_memory: check VMA end bounds in insert_pmd() and insert_pud()
2026-12-02 20:00 [PATCH v2] mm/huge_memory: check VMA end bounds in insert_pmd() and insert_pud() Elkin Cruz
2026-12-02 20:09 ` Zi Yan
@ 2026-12-02 20:29 ` David Hildenbrand (Arm)
2026-12-02 20:45 ` + mm-huge_memory-check-vma-end-bounds-in-insert_pmd-and-insert_pud.patch added to mm-new branch Andrew Morton
2 siblings, 0 replies; 4+ messages in thread
From: David Hildenbrand (Arm) @ 2026-12-02 20:29 UTC (permalink / raw)
To: Elkin Cruz, Zi Yan, Andrew Morton
Cc: Baolin Wang, Liam R. Howlett, Nico Pache, Ryan Roberts, Dev Jain,
Barry Song, Lance Yang, Usama Arif, Kiryl Shutsemau, linux-mm,
linux-kernel, llvm, irogers
On 12/2/26 21:00, Elkin Cruz wrote:
> 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>
> ---
Reviewed-by: David Hildenbrand (Arm) <david@kernel.org>
--
Cheers,
David
^ permalink raw reply [flat|nested] 4+ messages in thread
* + mm-huge_memory-check-vma-end-bounds-in-insert_pmd-and-insert_pud.patch added to mm-new branch
2026-12-02 20:00 [PATCH v2] mm/huge_memory: check VMA end bounds in insert_pmd() and insert_pud() Elkin Cruz
2026-12-02 20:09 ` Zi Yan
2026-12-02 20:29 ` David Hildenbrand (Arm)
@ 2026-12-02 20:45 ` Andrew Morton
2 siblings, 0 replies; 4+ messages in thread
From: Andrew Morton @ 2026-12-02 20:45 UTC (permalink / raw)
To: mm-commits, ziy, usama.arif, ryan.roberts, nico.pache, liam,
lance.yang, kas, irogers, dev.jain, david, baolin.wang, baohua,
elkin, akpm
The patch titled
Subject: mm/huge_memory: check VMA end bounds in insert_pmd() and insert_pud()
has been added to the -mm mm-new branch. Its filename is
mm-huge_memory-check-vma-end-bounds-in-insert_pmd-and-insert_pud.patch
This patch will shortly appear at
https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-huge_memory-check-vma-end-bounds-in-insert_pmd-and-insert_pud.patch
This patch will later appear in the mm-new branch at
git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
Note, mm-new is a provisional staging ground for work-in-progress
patches, and acceptance into mm-new is a notification for others take
notice and to finish up reviews. Please do not hesitate to respond to
review feedback and post updated versions to replace or incrementally
fixup patches in mm-new.
The mm-new branch of mm.git is not included in linux-next
If a few days of testing in mm-new is successful, the patch will me moved
into mm.git's mm-unstable branch, which is included in linux-next
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a
reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next via various
branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
and is updated there most days
------------------------------------------------------
From: Elkin Cruz <elkin@google.com>
Subject: mm/huge_memory: check VMA end bounds in insert_pmd() and insert_pud()
Date: Wed, 02 Dec 2026 20:00:56 +0000
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().
Link: https://patch.msgid.link/20261202200056.3555477-1-elkin@google.com
Signed-off-by: Elkin Cruz <elkin@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Reviewed-by: David Hildenbrand (Arm) <david@kernel.org>
Reviewed-by: Zi Yan <ziy@nvidia.com>
Cc: Baolin Wang <baolin.wang@linux.alibaba.com>
Cc: Liam R. Howlett <liam@infradead.org>
Cc: Nico Pache <nico.pache@linux.dev>
Cc: Ryan Roberts <ryan.roberts@arm.com>
Cc: Dev Jain <dev.jain@arm.com>
Cc: Barry Song <baohua@kernel.org>
Cc: Lance Yang <lance.yang@linux.dev>
Cc: Usama Arif <usama.arif@linux.dev>
Cc: Kiryl Shutsemau <kas@kernel.org>
Cc: Ian Rogers <irogers@google.com>
mm/huge_memory.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
--- a/mm/huge_memory.c~mm-huge_memory-check-vma-end-bounds-in-insert_pmd-and-insert_pud
+++ a/mm/huge_memory.c
@@ -1630,7 +1630,7 @@ static vm_fault_t insert_pmd(struct vm_a
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()) {
@@ -1768,7 +1768,7 @@ static vm_fault_t insert_pud(struct vm_a
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);
_
Patches currently in -mm which might be from elkin@google.com are
mm-huge_memory-check-vma-end-bounds-in-insert_pmd-and-insert_pud.patch
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-12-02 20:45 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02 20:00 [PATCH v2] mm/huge_memory: check VMA end bounds in insert_pmd() and insert_pud() Elkin Cruz
2026-12-02 20:09 ` Zi Yan
2026-12-02 20:29 ` David Hildenbrand (Arm)
2026-12-02 20:45 ` + mm-huge_memory-check-vma-end-bounds-in-insert_pmd-and-insert_pud.patch added to mm-new branch Andrew Morton
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.