# \[PATCH v6 06/10\] mm/vmalloc: reject an unaligned range in \_\_vunmap\_range\_noflush()

- From: Hao Ge \<hao.ge@linux.dev\>
- Date: 2026-12-03 09:28:38 
- List: linuxppc-dev
- Page: https://ratatoskr.run/linuxppc-dev/2026/12/18074862
- Thread: https://ratatoskr.run/linuxppc-dev/2026/12/18074856/t.md

```text
The PTE loop stops only at addr == end. An unaligned end is never
reached, so the loop keeps clearing past the range. An unaligned
start clears the page below the range first. Both are caller bugs,
and the damage is hard to attribute afterwards.

vmap only installs page aligned mappings, so an unaligned unmap
request is never a legitimate teardown. Warn and bail out at the
entry of __vunmap_range_noflush(), before any PTE is cleared.

The adjacent BUG_ON(addr >= end) is converted to the same
WARN_ON_ONCE() + return, since an empty range is a caller bug too.

Reported-by: Sashiko <sashiko-bot@kernel.org>
Closes: https://lore.kernel.org/all/sashiko-outbox-178439@kernel.org/
Reviewed-by: Dev Jain <dev.jain@arm.com>
Reviewed-by: Suren Baghdasaryan <surenb@google.com>
Reviewed-by: Uladzislau Rezki (Sony) <urezki@gmail.com>
Signed-off-by: Hao Ge <hao.ge@linux.dev>
---
 mm/vmalloc.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index 081c672f63ee..dcf3ddc0c6c0 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -524,7 +524,13 @@ void __vunmap_range_noflush(unsigned long start, unsigned long end,
 	unsigned long addr = start;
 	pgtbl_mod_mask mask = 0;
 
-	BUG_ON(addr >= end);
+	if (WARN_ON_ONCE(addr >= end))
+		return;
+	if (WARN_ON_ONCE(!PAGE_ALIGNED(addr)))
+		return;
+	if (WARN_ON_ONCE(!PAGE_ALIGNED(end)))
+		return;
+
 	pgd = pgd_offset_k(addr);
 	do {
 		next = pgd_addr_end(addr, end);
-- 
2.25.1


```
