[PATCH] kmsan: test: check vmalloc return value before use
From: Liu Jing
Date: Wed Sep 02 2026 - 05:13:19 EST
In test_init_vmalloc(), the return value of vmalloc() is used directly
without a NULL check. If vmalloc() fails under memory pressure, the
subsequent buf[0] = 1 and memset() calls will dereference a NULL
pointer and cause a kernel panic.
Add a NULL check immediately after vmalloc() and skip the test if
allocation fails.
Signed-off-by: Liu Jing <liujing@xxxxxxxxxxxxxxxxxxxx>
---
mm/kmsan/kmsan_test.c | 6 ++++++
1 file changed, 6 insertion(+), 0 deletion(-)
--- a/mm/kmsan/kmsan_test.c
+++ b/mm/kmsan/kmsan_test.c
@@ -352,6 +352,12 @@
kunit_info(test, "vmalloc buffer can be initialized (no reports)\n");
buf = vmalloc(PAGE_SIZE * npages);
+
+ if (!buf) {
+ kunit_skip(test, "vmalloc failed, skipping test\n");
+ return;
+ }
+
buf[0] = 1;
memset(buf, 0xfe, PAGE_SIZE * npages);
USE(buf[0]);
--
2.43.0