* [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
` (3 more replies)
0 siblings, 4 replies; 5+ 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 [flat|nested] 5+ 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)
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ 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] 5+ 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-03 6:04 ` Barry Song
2026-12-03 8:29 ` David Hildenbrand
3 siblings, 0 replies; 5+ 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] 5+ 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-03 6:04 ` Barry Song
2026-12-03 8:29 ` David Hildenbrand
3 siblings, 0 replies; 5+ messages in thread
From: Barry Song @ 2026-12-03 6:04 UTC (permalink / raw)
To: Elkin Cruz
Cc: David Hildenbrand, Zi Yan, Andrew Morton, Baolin Wang,
Liam R. Howlett, Nico Pache, Ryan Roberts, Dev Jain, Lance Yang,
Usama Arif, Kiryl Shutsemau, linux-mm, linux-kernel, llvm,
irogers
On Thu, Dec 3, 2026 at 4:01 AM Elkin Cruz <elkin@google.com> 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: Barry Song <baohua@kernel.org>
^ permalink raw reply [flat|nested] 5+ 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
` (2 preceding siblings ...)
2026-12-03 6:04 ` Barry Song
@ 2026-12-03 8:29 ` David Hildenbrand
3 siblings, 0 replies; 5+ messages in thread
From: David Hildenbrand @ 2026-12-03 8:29 UTC (permalink / raw)
To: David Hildenbrand, Zi Yan, Andrew Morton, Elkin Cruz
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 Wed, 02 Dec 2026 20:00:56 +0000, 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().
>
> [...]
Applied, thanks!
tree: mm/core.git
branch: thp-7.5.misc
Applied patches will appear soon in mm-next, followed by linux-next.
Please report any outstanding bugs that were missed during review, so we
can either drop the patch series or decide how to fix it up.
It is encouraged to provide Acked-bys, Reviewed-bys, and Tested-bys even
though the patches have already been applied. If possible, patch trailers
will be updated.
Note that commit hashes shown below are subject to change due to rebase,
trailer updates or similar. Further, this is not a guarantee that the
patches will go upstream. If in doubt, please check the listed branch.
[1/1] mm/huge_memory: check VMA end bounds in insert_pmd() and insert_pud()
https://git.kernel.org/mm/core/c/814f1a29
--
Cheers,
David
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-12-03 8:29 UTC | newest]
Thread overview: 5+ 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-03 6:04 ` Barry Song
2026-12-03 8:29 ` David Hildenbrand
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®