* [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
2026-12-02 20:29 ` David Hildenbrand (Arm)
0 siblings, 2 replies; 3+ 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] 3+ 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)
1 sibling, 0 replies; 3+ 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] 3+ 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)
1 sibling, 0 replies; 3+ 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] 3+ messages in thread
end of thread, other threads:[~2026-12-02 20:29 UTC | newest]
Thread overview: 3+ 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)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox