Skip to content

Commit f982f91

Browse files
cladischtorvalds
authored andcommitted
mm: fix wrong vmap address calculations with odd NR_CPUS values
Commit db64fe0 ("mm: rewrite vmap layer") introduced code that does address calculations under the assumption that VMAP_BLOCK_SIZE is a power of two. However, this might not be true if CONFIG_NR_CPUS is not set to a power of two. Wrong vmap_block index/offset values could lead to memory corruption. However, this has never been observed in practice (or never been diagnosed correctly); what caught this was the BUG_ON in vb_alloc() that checks for inconsistent vmap_block indices. To fix this, ensure that VMAP_BLOCK_SIZE always is a power of two. BugLink: https://bugzilla.kernel.org/show_bug.cgi?id=31572 Reported-by: Pavel Kysilka <[email protected]> Reported-by: Matias A. Fonzo <[email protected]> Signed-off-by: Clemens Ladisch <[email protected]> Signed-off-by: Stefan Richter <[email protected]> Cc: Nick Piggin <[email protected]> Cc: Jeremy Fitzhardinge <[email protected]> Cc: Krzysztof Helt <[email protected]> Cc: Andrew Morton <[email protected]> Cc: 2.6.28+ <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 97c24d1 commit f982f91

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

mm/vmalloc.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -725,9 +725,10 @@ static void free_unmap_vmap_area_addr(unsigned long addr)
725725
#define VMAP_BBMAP_BITS_MIN (VMAP_MAX_ALLOC*2)
726726
#define VMAP_MIN(x, y) ((x) < (y) ? (x) : (y)) /* can't use min() */
727727
#define VMAP_MAX(x, y) ((x) > (y) ? (x) : (y)) /* can't use max() */
728-
#define VMAP_BBMAP_BITS VMAP_MIN(VMAP_BBMAP_BITS_MAX, \
729-
VMAP_MAX(VMAP_BBMAP_BITS_MIN, \
730-
VMALLOC_PAGES / NR_CPUS / 16))
728+
#define VMAP_BBMAP_BITS \
729+
VMAP_MIN(VMAP_BBMAP_BITS_MAX, \
730+
VMAP_MAX(VMAP_BBMAP_BITS_MIN, \
731+
VMALLOC_PAGES / roundup_pow_of_two(NR_CPUS) / 16))
731732

732733
#define VMAP_BLOCK_SIZE (VMAP_BBMAP_BITS * PAGE_SIZE)
733734

0 commit comments

Comments
 (0)