mm/vmalloc: fix return value of vb_alloc if size is 0
authorHailong.Liu <hailong.liu@oppo.com>
Fri, 26 Apr 2024 02:41:49 +0000 (10:41 +0800)
committerAndrew Morton <akpm@linux-foundation.org>
Mon, 6 May 2024 00:28:06 +0000 (17:28 -0700)
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>
mm/vmalloc.c

index 68fa001648cc1cb766d8fa4111e88c3fbbf257e8..125427cbdb87bcc4bb30a076bcba91119490709c 100644 (file)
@@ -2710,7 +2710,7 @@ static void *vb_alloc(unsigned long size, gfp_t gfp_mask)
                 * get_order(0) returns funny result. Just warn and terminate
                 * early.
                 */
-               return NULL;
+               return ERR_PTR(-EINVAL);
        }
        order = get_order(size);