From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mta0.migadu.com (out-236.mta0.migadu.com [91.218.175.236]) (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 A4F3F449988 for ; Tue, 25 Aug 2026 12:59:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.236 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787662761; cv=none; b=lQ7CdK90/4WP/kvsHObnlBwIF+o8d3obD1eJDmXOmCFzN4Pa1RAo7MaeZ42NNZzySxyRfYq0qEU7YSYPxw1HENSoUuOsD9pUNFPvgOlGbuv9ugPTi+FZxMpz+aVHintB3LaLggRTobj1BU0P19SurK9v3dD4JeXWURvH/Fa/V0I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787662761; c=relaxed/simple; bh=vPycpKER/JF8kLZX9oLztJNJWeKo4SFsQwqcjLqYHsY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ZR3roWtg5YKHP/cJx5x00pLwV1RKHZzTlSBJM631bZ7nNNVjX52UrwPFEeYoQaahsMfiHr8UZLJhBe470y5ZXjgCm0w6ikNB/BwFHwkVH/kuVdWHoXwqUub1qFC1o3Bh4j2ioK+3Siyjonlzy+YqVlBAFFJAz/LgUBMJP6mNbV4= 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=mHcZVZ44; arc=none smtp.client-ip=91.218.175.236 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="mHcZVZ44" X-Envelope-To: linux-kernel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=vPycpKER/JF8kLZX9oLztJNJWeKo4SFsQwqcjLqYHsY=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1787662756; v=1; x=1788267556; b=mHcZVZ44HgphCjleFFgUINq9OIsPmkAba+7UrqZi1e5RU05SvUglQ786mM7BrQavFvj8VFcw rkoY+gwjxhu1/7yJoERYB1hehA3GkeDuCr0RUQwZOSHnuCPqjxWltvrxo2N03MqB3uD9VlO+vSP OyBV+Xix3aPSwQ0QI+JHGAc4= X-Envelope-To: linux-kernel@vger.kernel.org Received: from fedora (117.129.78.49) by smtp.migadu.com with ESMTPS id 059bbcde781145e8; Tue, 25 Aug 2026 12:59:16 +0000 X-Mizu-Trace-ID: 059bbcde781145e8 X-Migadu-Flow: FLOW_OUT Date: Tue, 25 Aug 2026 20:59:08 +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, xialonglong@kylinos.cn Subject: Re: [PATCH 1/1] mm/slab_common: reject zero object_size before calculate_alignment Message-ID: References: <20260824092454.1693745-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: <20260824092454.1693745-1-xialonglong2025@163.com> 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? > err = -EINVAL; > goto out_unlock; > } > -- > 2.43.0 >