Re: [PATCH] mm/huge_memory: check VMA end bounds in insert_pmd() and insert_pud()

From: Elkin Cruz

Date: Tue Dec 01 2026 - 20:53:17 EST


On Thu, Nov 26, 2026 at 3:23 AM David Hildenbrand (Arm)
<david@xxxxxxxxxx> wrote:
> For the code here, couldn't we do something like
>
> if (addr < vma->vm_start ||
> addr + HPAGE_PMD_SIZE >= vma->vm_end )
>
> ... not sure if we'd have to care about overflows.

Sorry for the belated reply.

I have checked with help of an AI agent and they argue that
vma->vm_end is exclusive
(addr + HPAGE_PMD_SIZE == vma->vm_end). Thus ">= would reject the
last PMD/PUD of every aligned VMA with VM_FAULT_SIGBUS", so it has
to be >.

I can send a new v2 if you want with:

if (addr < vma->vm_start ||
addr + HPAGE_PMD_SIZE > vma->vm_end )

Or "addr >= vma->vm_end || vma->vm_end - addr < HPAGE_PMD_SIZE"
if you prefer the defensive wraparound fix.

Thanks,
Elkin