Skip to content

Commit aa91c4d

Browse files
jankaratorvalds
authored andcommitted
mm: make vb_alloc() more foolproof
If someone calls vb_alloc() (or vm_map_ram() for that matter) to allocate 0 bytes (0 pages), get_order() returns BITS_PER_LONG - PAGE_CACHE_SHIFT and interesting stuff happens. So make debugging such problems easier and warn about 0-size allocation. [akpm@linux-foundation.org: use WARN_ON-return-value feature] Signed-off-by: Jan Kara <jack@suse.cz> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 92ca922 commit aa91c4d

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

mm/vmalloc.c

+8
Original file line numberDiff line numberDiff line change
@@ -904,6 +904,14 @@ static void *vb_alloc(unsigned long size, gfp_t gfp_mask)
904904

905905
BUG_ON(size & ~PAGE_MASK);
906906
BUG_ON(size > PAGE_SIZE*VMAP_MAX_ALLOC);
907+
if (WARN_ON(size == 0)) {
908+
/*
909+
* Allocating 0 bytes isn't what caller wants since
910+
* get_order(0) returns funny result. Just warn and terminate
911+
* early.
912+
*/
913+
return NULL;
914+
}
907915
order = get_order(size);
908916

909917
again:

0 commit comments

Comments
 (0)