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

From: Zi Yan

Date: Wed Dec 02 2026 - 15:09:51 EST


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@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(-)
>
LGTM.

Reviewed-by: Zi Yan <ziy@xxxxxxxxxx>


Best Regards,
Yan, Zi