* [PATCH] mm/huge_memory: check VMA end bounds in insert_pmd() and insert_pud()
@ 2026-11-25 22:19 Elkin Cruz
2026-11-25 22:40 ` David Hildenbrand (Arm)
0 siblings, 1 reply; 3+ messages in thread
From: Elkin Cruz @ 2026-11-25 22:19 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, stable
insert_pmd() and insert_pud() only check that addr lies within
[vma->vm_start, vma->vm_end) without verifying that the full PMD or PUD
mapping fits below vma->vm_end. On a VMA whose end is not PMD- or
PUD-aligned, inserting a huge mapping at the tail straddles past
vma->vm_end.
Require vma->vm_end - addr >= HPAGE_PMD_SIZE in insert_pmd() and
vma->vm_end - addr >= HPAGE_PUD_SIZE in insert_pud().
Fixes: 5cad465d7fa6 ("mm: add vmf_insert_pfn_pmd()")
Fixes: a00cc7d9dd93 ("mm, x86: add support for PUD-sized transparent hugepages")
Cc: stable@vger.kernel.org
Signed-off-by: Elkin Cruz <elkin@google.com>
---
I am trying out new Clang static analysis checks for kernel bug
classes, and they flagged this code as possibly buggy. The findings
were triaged/fixed and commit descriptions were drafted with help of AI,
then checked against linux-next (not runtime-tested on hardware).
Thanks,
Elkin
mm/huge_memory.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index e167c9ea4609..683f0c68d6b2 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -1630,7 +1630,8 @@ 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 >= vma->vm_end ||
+ vma->vm_end - addr < HPAGE_PMD_SIZE)
return VM_FAULT_SIGBUS;
if (arch_needs_pgtable_deposit()) {
@@ -1771,7 +1772,8 @@ 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 >= vma->vm_end ||
+ vma->vm_end - addr < HPAGE_PUD_SIZE)
return VM_FAULT_SIGBUS;
ptl = pud_lock(mm, pud);
--
2.56.1.839.g22a8290db9-goog
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] mm/huge_memory: check VMA end bounds in insert_pmd() and insert_pud()
2026-11-25 22:19 [PATCH] mm/huge_memory: check VMA end bounds in insert_pmd() and insert_pud() Elkin Cruz
@ 2026-11-25 22:40 ` David Hildenbrand (Arm)
2026-11-25 22:57 ` Elkin Cruz
0 siblings, 1 reply; 3+ messages in thread
From: David Hildenbrand (Arm) @ 2026-11-25 22:40 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, stable
On 11/25/26 23:19, Elkin Cruz wrote:
> insert_pmd() and insert_pud() only check that addr lies within
> [vma->vm_start, vma->vm_end) without verifying that the full PMD or PUD
> mapping fits below vma->vm_end. On a VMA whose end is not PMD- or
> PUD-aligned, inserting a huge mapping at the tail straddles past
> vma->vm_end.
>
> Require vma->vm_end - addr >= HPAGE_PMD_SIZE in insert_pmd() and
> vma->vm_end - addr >= HPAGE_PUD_SIZE in insert_pud().
>
> Fixes: 5cad465d7fa6 ("mm: add vmf_insert_pfn_pmd()")
> Fixes: a00cc7d9dd93 ("mm, x86: add support for PUD-sized transparent hugepages")
Which users in the tree trigger this?
--
Cheers,
David
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] mm/huge_memory: check VMA end bounds in insert_pmd() and insert_pud()
2026-11-25 22:40 ` David Hildenbrand (Arm)
@ 2026-11-25 22:57 ` Elkin Cruz
0 siblings, 0 replies; 3+ messages in thread
From: Elkin Cruz @ 2026-11-25 22:57 UTC (permalink / raw)
To: David Hildenbrand (Arm)
Cc: Zi Yan, 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, stable
On Wed, Nov 25, 2026 at 2:40 PM David Hildenbrand (Arm)
<david@kernel.org> wrote:
> Which users in the tree trigger this?
Very fair point. After a quick check, there are indeed no users in the
tree that can trigger this.
Back to the whiteboard. The linter is still too noisy. I will hold off
sending any more patches :).
Please ignore/drop this patch.
Thank you so much for your very quick reply!
Elkin
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-25 22:57 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-25 22:19 [PATCH] mm/huge_memory: check VMA end bounds in insert_pmd() and insert_pud() Elkin Cruz
2026-11-25 22:40 ` David Hildenbrand (Arm)
2026-11-25 22:57 ` Elkin Cruz
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®