From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mta0.migadu.com (out-48.mta0.migadu.com [91.218.175.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 06DA323C4F3 for ; Wed, 26 Aug 2026 02:58:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.48 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787713115; cv=none; b=BjDK5qpLGHJxsXSSvt90Ypr0cXNl/kcKBcQ45M4LpvmgFjfdhsTQCdgBPjkTmJAhhXJ+XBDduuaN4SIayD5l8eASNIePX2fq0pGf08OCMDUms7nQR6VZ4ZXZpEnAaRKRMDGwMz0rYlFURCLhfIW3sO6y++zVTmA4dcWJT1Ivn6U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787713115; c=relaxed/simple; bh=fF9gyDjEs6+vYJh1yDRz0c7p09qLbkugpjcJbmk8Xxo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=qw8oG3psobyeP4krJIm9mmxJ2SYHIl6ORSsWhBFkg0WuRykiOvITLqKh1IYkd+3CjCKyfAAgz8RMc84rrR12lM4Czn0NhBuASQ38CZgjPCj49JhEppqgoQBvykkBebpfuMUFC3Vk6K6M7vCMZ+69JNnkh3HAF6jsTPalM/csSXU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=AB8vY8u2; arc=none smtp.client-ip=91.218.175.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="AB8vY8u2" X-Envelope-To: linux-kernel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=fF9gyDjEs6+vYJh1yDRz0c7p09qLbkugpjcJbmk8Xxo=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1787713111; v=1; x=1788317911; b=AB8vY8u2Y1krS3d4WbUP0O2AxFkvf6xT0K55C17dENL5YVys3Dn3HMG/S787ABbjwImrXpNI ZHxZioRbBMl/0cauQCL4d5mH70IzF0dWczB2F5eOSa3w9RcVCAOfQCD4qgXOoOmPQuYY3PbE7ZB oMbGHs4OtQlwrDDaWPov7xw8= X-Envelope-To: linux-kernel@vger.kernel.org Received: from fedora (117.129.78.49) by smtp.migadu.com with ESMTPS id 61c7a6b2cb34e485; Wed, 26 Aug 2026 02:58:31 +0000 X-Mizu-Trace-ID: 61c7a6b2cb34e485 X-Migadu-Flow: FLOW_OUT Date: Wed, 26 Aug 2026 10:58:26 +0800 From: Hao Li To: Longlong Xia 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, Longlong Xia Subject: Re: [PATCH v2 1/1] mm/slab_common: reject zero object_size before calculate_alignment Message-ID: References: <20260826015506.3178758-1-xialonglong2025@163.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260826015506.3178758-1-xialonglong2025@163.com> On Wed, Aug 26, 2026 at 09:55:06AM +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. 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 > --- > Changes in v2: > - Drop the !object_size check in __kmem_cache_create_args() that v1 > added to the always-compiled path, and keep the guard only in the > debug-only kmem_cache_sanity_check(), as suggested by Hao Li. > > Link: https://lore.kernel.org/all/20260824092454.1693745-1-xialonglong2025@163.com/ > --- > 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 95ddbab290d4..e205a99d85cf 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) { Looks good to me. thanks. Reviewed-by: Hao Li > pr_err("kmem_cache_create(%s) integrity check failed\n", name); > return -EINVAL; > } > -- > 2.43.0 >