All of lore.kernel.org
 help / color / mirror / Atom feed
* [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

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.