Skip to content

Commit ac0476e

Browse files
hailong-liuakpm00
authored andcommitted
mm/vmalloc: fix return value of vb_alloc if size is 0
vm_map_ram() uses IS_ERR() to validate the return value of vb_alloc(). If vm_map_ram(page, 0, 0) is executed, vb_alloc(0, GFP_KERNEL) would return NULL. In such a case, IS_ERR() cannot handle the return value and lead to kernel panic by vmap_pages_range_noflush() at last. To resolve this issue, return ERR_PTR(-EINVAL) if the size is 0. Link: https://lkml.kernel.org/r/20240426024149.21176-1-hailong.liu@oppo.com Reviewed-by: Barry Song <baohua@kernel.org> Reviewed-by: Uladzislau Rezki (Sony) <urezki@gmail.com> Signed-off-by: Hailong.Liu <hailong.liu@oppo.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Cc: Lorenzo Stoakes <lstoakes@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 30153e4 commit ac0476e

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

mm/vmalloc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2710,7 +2710,7 @@ static void *vb_alloc(unsigned long size, gfp_t gfp_mask)
27102710
* get_order(0) returns funny result. Just warn and terminate
27112711
* early.
27122712
*/
2713-
return NULL;
2713+
return ERR_PTR(-EINVAL);
27142714
}
27152715
order = get_order(size);
27162716

0 commit comments

Comments
 (0)