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 Suggested-by: Dev Jain Signed-off-by: Hao Ge --- 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