Skip to content

Commit 61ef8dd

Browse files
Ryan Robertswilldeacon
authored andcommitted
mm/vmalloc: Warn on improper use of vunmap_range()
A call to vmalloc_huge() may cause memory blocks to be mapped at pmd or pud level. But it is possible to subsequently call vunmap_range() on a sub-range of the mapped memory, which partially overlaps a pmd or pud. In this case, vmalloc unmaps the entire pmd or pud so that the no-overlapping portion is also unmapped. Clearly that would have a bad outcome, but it's not something that any callers do today as far as I can tell. So I guess it's just expected that callers will not do this. However, it would be useful to know if this happened in future; let's add a warning to cover the eventuality. Reviewed-by: Anshuman Khandual <[email protected]> Reviewed-by: Catalin Marinas <[email protected]> Reviewed-by: Uladzislau Rezki (Sony) <[email protected]> Signed-off-by: Ryan Roberts <[email protected]> Tested-by: Luiz Capitulino <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Will Deacon <[email protected]>
1 parent f89b399 commit 61ef8dd

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

mm/vmalloc.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,10 @@ static void vunmap_pmd_range(pud_t *pud, unsigned long addr, unsigned long end,
374374
if (cleared || pmd_bad(*pmd))
375375
*mask |= PGTBL_PMD_MODIFIED;
376376

377-
if (cleared)
377+
if (cleared) {
378+
WARN_ON(next - addr < PMD_SIZE);
378379
continue;
380+
}
379381
if (pmd_none_or_clear_bad(pmd))
380382
continue;
381383
vunmap_pte_range(pmd, addr, next, mask);
@@ -399,8 +401,10 @@ static void vunmap_pud_range(p4d_t *p4d, unsigned long addr, unsigned long end,
399401
if (cleared || pud_bad(*pud))
400402
*mask |= PGTBL_PUD_MODIFIED;
401403

402-
if (cleared)
404+
if (cleared) {
405+
WARN_ON(next - addr < PUD_SIZE);
403406
continue;
407+
}
404408
if (pud_none_or_clear_bad(pud))
405409
continue;
406410
vunmap_pmd_range(pud, addr, next, mask);

0 commit comments

Comments
 (0)