linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3] mm/vmalloc: fix return value of vb_alloc if size is 0
@ 2024-04-26  2:41 hailong.liu
  2024-04-26  5:02 ` Christoph Hellwig
  0 siblings, 1 reply; 2+ messages in thread
From: hailong.liu @ 2024-04-26  2:41 UTC (permalink / raw)
  To: akpm
  Cc: urezki, hch, lstoakes, 21cnbao, linux-mm, linux-kernel,
	Hailong.Liu, Barry Song

From: "Hailong.Liu" <hailong.liu@oppo.com>

The function 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.

Reviewed-by: Barry Song <baohua@kernel.org>
Reviewed-by: Uladzislau Rezki (Sony) <urezki@gmail.com>
Signed-off-by: Hailong.Liu <hailong.liu@oppo.com>
---
Changes since v2 [2]:
- Remove RFC tag
- Modify commit msg, per Barry
Changes since v1 [1]:
- Return ERR_PTR(-EINVAL) or not check IS_ERR_OR_NULL

[1] https://lore.kernel.org/all/84d7cd03-1cf8-401a-8edf-2524db0bd6d5@oppo.com/
[2] https://lore.kernel.org/all/20240419101643.11534-1-hailong.liu@oppo.com/

 mm/vmalloc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index d12a17fc0c17..44be3edb3f42 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -2173,7 +2173,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);

--
2.34.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v3] mm/vmalloc: fix return value of vb_alloc if size is 0
  2024-04-26  2:41 [PATCH v3] mm/vmalloc: fix return value of vb_alloc if size is 0 hailong.liu
@ 2024-04-26  5:02 ` Christoph Hellwig
  0 siblings, 0 replies; 2+ messages in thread
From: Christoph Hellwig @ 2024-04-26  5:02 UTC (permalink / raw)
  To: hailong.liu
  Cc: akpm, urezki, hch, lstoakes, 21cnbao, linux-mm, linux-kernel, Barry Song

Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-04-26  5:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-26  2:41 [PATCH v3] mm/vmalloc: fix return value of vb_alloc if size is 0 hailong.liu
2024-04-26  5:02 ` Christoph Hellwig

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).