From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 A3DF1437465 for ; Mon, 13 Jul 2026 14:29:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783952948; cv=none; b=p43C1NETwWrTlB3fx5LUuMeA+el+e+JRjMubr0I07nZZqxuM/gdHD18GKSyLoz9arHy9VtmWbG79MUuYZYItjmCevahLUgFREPcoV2NeMM4poWfPNetCYuImLLiFQeZy+jR5gFwXHNsRJvC7+f5O3Flfj1D8FOTJtDchXsEvPUI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783952948; c=relaxed/simple; bh=Z8zSIMD1uY7VwC3850XNWXHtV/DpyqyVEr6QdDaCjro=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=PcJZFoVRfoJVUyw55f9hpHH+uOFWoW02n7JMWGb8DEaqvb8nhlwCNdmhurAjk0UsS/cywq8nsIpcbBr6IsYxJjChskJ0WP0SgzcdWrDH6N9LIOz8Ix6XX5mstziCExgbHEKDSoqpHUnQzssLW8iu1JN7d9ls4jobNb96OevWLH4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=DndLLiB9; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="DndLLiB9" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6A7571F00A3A; Mon, 13 Jul 2026 14:29:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1783952947; bh=wtRyuqLxHec+AIEMCGWYLc5A5j22LJ1kSJp888lWRJ4=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=DndLLiB9yUJTEojiBiWraCz1r9jKwR36ryUJncr/4zWiv3MHsqiRNTmQNtKlVUEHV UykmOD2ijPBOjopIPvnikZR3gNLAPuc7Md7uSw3p1bwi1/cV+3iUZX1czCDY99aapU oZu6Eu+doMHnf/hi5CRIqnuZkDCHi1skwRclj9V75PxfK/MVMM5uHBmUxUoQJgsIW9 mEckIMBn9W8hQKX59fS/AGPrTF2FfqlhP2TyTjawPWf9pcqn/m1fvfZw+Wa64AXdON 1pAtAyfXoNMF1BhYwVrlJK4NM2vQvM0/Igszfjd8HmBp5Ms39oOx29keR4s+fP1HL7 J4p2nGb4R8Q6A== From: "Harry Yoo (Oracle)" Date: Mon, 13 Jul 2026 23:28:49 +0900 Subject: [PATCH slab/for-next-fixes v3 1/4] mm/slab: fix a memory leak due to bootstrapping sheaves twice 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="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260713-kmalloc-no-objext-v3-1-47c7bd138de7@kernel.org> References: <20260713-kmalloc-no-objext-v3-0-47c7bd138de7@kernel.org> In-Reply-To: <20260713-kmalloc-no-objext-v3-0-47c7bd138de7@kernel.org> To: Vlastimil Babka , Harry Yoo , Andrew Morton , Hao Li , Christoph Lameter , David Rientjes , Roman Gushchin , "Liam R. Howlett" , Suren Baghdasaryan , Hao Ge , Kees Cook , Pedro Falcato , Shakeel Butt , Danielle Constantino Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org X-Mailer: b4 0.14.3 When kmalloc caches are aliased, multiple cache pointers reference the same kmem_cache. As a result, iterating over kmalloc indices and bootstrapping sheaves can bootstrap the same cache more than once and leak memory. Currently, this could happen when the architecture specifies minimum alignment for slab caches that is larger than ARCH_KMALLOC_MINALIGN. Bootstrap sheaves only when the cache does not have them already. Add a warning when bootstrap_cache_sheaves() is called for a cache that already has sheaves enabled. Cc: stable@vger.kernel.org Fixes: 913ffd3a1bf5 ("slab: handle kmalloc sheaves bootstrap") Signed-off-by: Harry Yoo (Oracle) --- mm/slub.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/mm/slub.c b/mm/slub.c index 65febe957886..f9461a0c47d3 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -8497,6 +8497,8 @@ static void __init bootstrap_cache_sheaves(struct kmem_cache *s) bool failed = false; int node, cpu; + VM_WARN_ON_ONCE(cache_has_sheaves(s)); + capacity = calculate_sheaf_capacity(s, &empty_args); /* capacity can be 0 due to debugging or SLUB_TINY */ @@ -8548,8 +8550,11 @@ static void __init bootstrap_kmalloc_sheaves(void) for (type = KMALLOC_NORMAL; type <= KMALLOC_PARTITION_END; type++) { for (int idx = 0; idx < KMALLOC_SHIFT_HIGH + 1; idx++) { - if (kmalloc_caches[type][idx]) - bootstrap_cache_sheaves(kmalloc_caches[type][idx]); + struct kmem_cache *s = kmalloc_caches[type][idx]; + + /* Do not bootstrap twice when caches are aliased */ + if (s && !cache_has_sheaves(s)) + bootstrap_cache_sheaves(s); } } } -- 2.53.0