From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from m16.mail.163.com (m16.mail.163.com [220.197.31.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 56876481FAB for ; Tue, 25 Aug 2026 13:47:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=220.197.31.2 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787665651; cv=none; b=ZWXBvvlMngJUKD5wKrnJW1vax6aqHdxMWhUsOnoZsY0d1fv6Z+mpk4PKOXhg2jWyPC1KIxyq2LahPYEv7ogUblUFb154rL0d9tfdfWJweFkiSjObsFPRMSYwZrSKOw3gcy/+DNKLqIt53on0HytP7iK5ZVohVaO2Gzz18LyGXpI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787665651; c=relaxed/simple; bh=/vB0sQ6OtkKolAcnLxjI00JKan3fU8IToNFY/ruBxBk=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=FrKE5QuVC7b1g0oe6vNAuZyiX+LVrlnqv4Z/UfKN7uKBmHdpqWeQj+c1/vTR+gasCMGC1XyqppaklfnustjDg513tjYpmeTTGzOEiUAA6uEG91dJNS0194DYVFwK/qXFghRvF2gP2eor8jSNff53glXlgHbriVM7ocIJa70F7hY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=OryRtCXC; arc=none smtp.client-ip=220.197.31.2 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="OryRtCXC" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=Message-ID:Date:MIME-Version:Subject:To:From: Content-Type; bh=hm2gUvfhpHXEbN+h51BDtN0eertigwioMYzJBWquQm0=; b=OryRtCXCW1dae7H9xpiFcrdPq5Ra6XujoD8TNELVCXKmF9MN3gc5NhwnyqfGd+ za5PXSNO9zYsR8DD3p7HdK3IpojkXYnqDFZgXyiSXCJZVsxofFwOWHTcjvPw4w+N 47XdRmgmUc7NwwTrlethsMUP7qqJ8XzZ/IqY0RIA9TEkk= Received: from [IPV6:2409:8d1e:e12:7fe:b7cb:e263:e9d9:f20f] (unknown []) by gzga-smtp-mtada-g1-1 (Coremail) with SMTP id _____wD3v4i0nI1qDr1BRA--.57630S2; Tue, 25 Aug 2026 21:46:30 +0800 (CST) Message-ID: <93d6e366-e7f2-4cd6-b8e7-96a9f79813d3@163.com> Date: Tue, 25 Aug 2026 21:46:29 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 1/1] mm/slab_common: reject zero object_size before calculate_alignment To: Hao Li Cc: vbabka@kernel.org, harry@kernel.org, akpm@linux-foundation.org, cl@gentwo.org, rientjes@google.com, roman.gushchin@linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, xialonglong@kylinos.cn References: <20260824092454.1693745-1-xialonglong2025@163.com> From: Longlong Xia In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-CM-TRANSID:_____wD3v4i0nI1qDr1BRA--.57630S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7ZFy5uFWkZryxCFW7JF1kXwb_yoW8uw1Upr W8Ka4DXFW0qr13WrZ2ya4DGFZ5t395tFy7CFWaya18Xr98uw1kJ398KryUWry3Gry5GayI vFZYg3Wv934UGaDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0zReuWXUUUUU= X-CM-SenderInfo: x0ldz0pqjo00rjsqjki6rwjhhfrp/xtbC2xZSS2qNnLbdBQAA3B 在 2026/8/25 20:59, Hao Li 写道: > On Mon, Aug 24, 2026 at 05:24:54PM +0800, Longlong Xia wrote: >> From: Longlong Xia >> >> 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, and the sanity check is compiled out without >> CONFIG_DEBUG_VM. Add a !object_size check in >> __kmem_cache_create_args(), which is always compiled, and add !size >> to the DEBUG_VM sanity check for diagnostics. >> >> Assisted-by: Codex:gpt-5.6-sol >> Signed-off-by: Longlong Xia >> --- >> mm/slab_common.c | 4 ++-- >> 1 file changed, 2 insertions(+), 2 deletions(-) >> >> diff --git a/mm/slab_common.c b/mm/slab_common.c >> index 657fd75776ea..209fe838fe71 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; >> } >> @@ -354,7 +354,7 @@ struct kmem_cache *__kmem_cache_create_args(const char *name, >> goto out_unlock; >> } >> >> - if (flags & ~SLAB_FLAGS_PERMITTED) { >> + if (!object_size || flags & ~SLAB_FLAGS_PERMITTED) { > under !CONFIG_DEBUG_VM, I think we ignore the sanity_check deliberately, so it > seems we don't need to add !object_size check here. right? Thanks for the review. Right, agreed. The !object_size check duplicates what kmem_cache_sanity_check() is for, and that one is intentionally debug-only. I'll drop the __kmem_cache_create_args() hunk in v2 and keep only the !size addition in kmem_cache_sanity_check(). Thanks, Longlong >> err = -EINVAL; >> goto out_unlock; >> } >> -- >> 2.43.0 >>