From 208854282dab2100a33c5eb8859407b5d36b7723 Mon Sep 17 00:00:00 2001 From: Longlong Xia Date: Wed, 26 Aug 2026 09:55:06 +0800 Subject: [PATCH] mm/slab_common: reject zero object_size before calculate_alignment calculate_alignment() with SLAB_HWCACHE_ALIGN halves ralign in a while (size <= ralign / 2) loop. When size is 0, ralign eventually reaches 0 and the condition stays true indefinitely, hanging the kernel. kmem_cache_sanity_check() rejected size > KMALLOC_MAX_SIZE but not size == 0. Add !size to the check so a 0-size kmem_cache_create() is caught on CONFIG_DEBUG_VM builds, where it can be diagnosed when it surfaces. Suggested-by: Hao Li Assisted-by: Codex:gpt-5.6-sol Signed-off-by: Longlong Xia Reviewed-by: Hao Li Reviewed-by: Harry Yoo (Meta) Link: https://patch.msgid.link/20260826015506.3178758-1-xialonglong2025@163.com Signed-off-by: Vlastimil Babka (SUSE) --- mm/slab_common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/slab_common.c b/mm/slab_common.c index b19ba1b31484..2a66725a4d17 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c @@ -102,7 +102,7 @@ static bool kmem_cache_is_duplicate_name(const char *name) static int kmem_cache_sanity_check(const char *name, unsigned int size) { - if (!name || in_interrupt() || size > KMALLOC_MAX_SIZE) { + if (!name || in_interrupt() || !size || size > KMALLOC_MAX_SIZE) { pr_err("kmem_cache_create(%s) integrity check failed\n", name); return -EINVAL; }