[PATCH v2] mm/huge_memory: check VMA end bounds in insert_pmd() and insert_pud()
From: Elkin Cruz
Date: Wed Dec 02 2026 - 15:01:10 EST
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@xxxxxxxxxx>
---
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@xxxxxxxxxx
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