Re: [PATCH v5 03/11] mm/vmalloc: reject an unaligned range in vmap_page_range()

From: Suren Baghdasaryan

Date: Fri Nov 20 2026 - 17:06:36 EST


On Wed, Nov 18, 2026 at 7:10 PM Uladzislau Rezki <urezki@xxxxxxxxx> wrote:
>
> On Mon, Nov 16, 2026 at 03:13:17PM +0800, Hao Ge wrote:
> > commit a739e6b557af ("mm: vmalloc: WARN_ON if mapping size is not
> > PAGE_SIZE aligned") put the check in vmap_pte_range(), which is too
> > late, because the upper levels may already have installed page tables
> > for a range that is rejected anyway.
> >
> > The pte loop maps whole pages and stops only when addr lands exactly
> > on end. An unaligned end lets addr jump over it and the loop keeps
> > mapping past the range. An unaligned start maps the page below the
> > range and usually misses end too. Such a range is never a legitimate
> > request.
> >
> > vmap_range_noflush() has a single caller, vmap_page_range(). Warn on
> > addr and end there and bail out with -EINVAL before any page table is
> > installed, and drop the check from vmap_pte_range().
> >
> > Suggested-by: Suren Baghdasaryan <surenb@xxxxxxxxxx>
> > Suggested-by: Dev Jain <dev.jain@xxxxxxx>
> > Signed-off-by: Hao Ge <hao.ge@xxxxxxxxx>
> > ---
> > mm/vmalloc.c | 6 +++---
> > 1 file changed, 3 insertions(+), 3 deletions(-)
> >
> > diff --git a/mm/vmalloc.c b/mm/vmalloc.c
> > index 3c0d9e69b886..a168f6f20f4f 100644
> > --- a/mm/vmalloc.c
> > +++ b/mm/vmalloc.c
> > @@ -125,9 +125,6 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end,
> > unsigned long size;
> > unsigned int nr_pages;
> >
> > - if (WARN_ON_ONCE(!PAGE_ALIGNED(end - addr)))
> > - return -EINVAL;
> > -
> > pfn = phys_addr >> PAGE_SHIFT;
> > pte = pte_alloc_kernel_track(pmd, addr, mask);
> > if (!pte)
> > @@ -369,6 +366,9 @@ int vmap_page_range(unsigned long addr, unsigned long end,
> > {
> > int err;
> >
> > + if (WARN_ON_ONCE(!PAGE_ALIGNED(addr) || !PAGE_ALIGNED(end)))
> > + return -EINVAL;
> > +
> > err = vmap_range_noflush(addr, end, phys_addr, pgprot_nx(prot),
> > ioremap_max_page_shift);
> > flush_cache_vmap(addr, end);
> > --
> > 2.25.1
> >
> LGTM,
>
> Reviewed-by: Uladzislau Rezki (Sony) <urezki@xxxxxxxxx>

Reviewed-by: Suren Baghdasaryan <surenb@xxxxxxxxxx>

>
> --
> Uladzislau Rezki