Received: by 2002:a05:6500:1b41:b0:1fb:d597:ff75 with SMTP id cz1csp402693lqb; Tue, 4 Jun 2024 15:14:33 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVG0FwMzFbaXJ8hkfoE6DN00bYVIaY6SnYnYvIN/Xz4p5cxfbvz4oVmmTFS2BYRz23gsDpEapgb1GjenxSrvM7A+YJrt5B9ma29/PKCjQ== X-Google-Smtp-Source: AGHT+IFyaJt77yn8KyMhKErT+J2kSXUrEWIQrGISyLQIlJCsjgv9z9pHQXaMi+AVZ0/+7h8Y1XJa X-Received: by 2002:a05:6a20:d80d:b0:1af:881c:e924 with SMTP id adf61e73a8af0-1b2b763736fmr977459637.62.1717539272928; Tue, 04 Jun 2024 15:14:32 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717539272; cv=pass; d=google.com; s=arc-20160816; b=knk8DktLDhTxwIUf04fRJaULprTs8JbZHRsBXdnhtIl5YUjOcfQMQUS2YHLYHrjvNE O0SF8tF3EuVRC/a1zDXD7NDBT4Wvy/37woz110NkFFO2FzVr9xQLk+J4tWTpJjD0Db1z MjG40ZKdVh348fBNvgyDfzlX2px+BAcYen5L5/cc/Ci2deUs4cwDkXFix2n3LemShVFi luOga/oB824mOjFlJ0LRIh7Qv4+4qtP9ue/Ual90yIY7iBBNHZAwcErvXM9Dt1fCEe3+ RWJ7p6xfudVoqMiFwwYLGNjI2FaWYKVIHxlpmZFWHMONndXdcHJHTzDp+Jq7381fflGe evhg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:feedback-id:dkim-signature:dkim-signature; bh=muU5qJkRVrc/WJXrwBT0sJpUEwClb+SER/+HMwaSXbE=; fh=Lq90cqq88eQp//Hjahq3tem5tyjWcH9OsdOy36OH4TA=; b=0W+hC/chhx92DScJQK28PszzdNTFv6v3CMY/vw9zAkz4Up7n7r9ZYKH55zxSEm3B2b 7i5KmjNeI5rmry/krh/nAZlVkaTP29vrIQgZtXgzelxkCqNdXyoUfYeptidB6iST3KIR PuipmGnPxTm5dtcRGqMRaH61IE2Jx3enwiiwAcyyka50n5rfregnTeAKEI1qV6qk1juK CKpBmCifkxZQCPMiIGZFwz0q06bcGHxTDbwxzFeOp/HD3do2Tb2+9WrPYu4ZF4PJs0GE kEPKqtM6U/dZHj/zNEjiFqLLkZZ3km04sbcdmZYG7/m1U5Kq3vsnkg64+k/Tnhf+uYiy ZEAQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@tycho.pizza header.s=fm3 header.b=IMrQfajn; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=MFeTNtxF; arc=pass (i=1 spf=pass spfdomain=tycho.pizza dkim=pass dkdomain=tycho.pizza dkim=pass dkdomain=messagingengine.com); spf=pass (google.com: domain of linux-kernel+bounces-201439-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-201439-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 41be03b00d2f7-6c359e0a28fsi847119a12.358.2024.06.04.15.14.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jun 2024 15:14:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-201439-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@tycho.pizza header.s=fm3 header.b=IMrQfajn; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=MFeTNtxF; arc=pass (i=1 spf=pass spfdomain=tycho.pizza dkim=pass dkdomain=tycho.pizza dkim=pass dkdomain=messagingengine.com); spf=pass (google.com: domain of linux-kernel+bounces-201439-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-201439-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 85CB2284F88 for ; Tue, 4 Jun 2024 22:14:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8DD5914D6ED; Tue, 4 Jun 2024 22:13:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tycho.pizza header.i=@tycho.pizza header.b="IMrQfajn"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="MFeTNtxF" Received: from flow1-smtp.messagingengine.com (flow1-smtp.messagingengine.com [103.168.172.136]) (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 5815E14D2BC; Tue, 4 Jun 2024 22:13:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.136 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717539222; cv=none; b=JyvPIeJgHId8IdRRshs7AxY17Gf9O98I1WmjHNwtRSB6Dg+o9nBxepOcwDHLdxVBHcMUkkE3pknRuIT0JySSOZu8D0dDutJB0bXRr1hHSoW4eZluA+cGxz1536soIovrSmzChg3aB1LhQb+h5CN1K/MryI9RsZZPdMQNkoA5FMw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717539222; c=relaxed/simple; bh=lYwlsFpXaffIux9v8UtowemAJ7x4EV5zC+20r626z6Q=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Kf52LgliuAkOFFvPdTXgKSBdsaFpEnsJCWBcCiHYqqHA5bwDRiCK5XGGqFjTMDExgrMQbaZTc751hZEi3hYvVi/1sP97zdFAbZjp9JpxLHBtVETGsiIVrr5zQ4PRdYy20BBUdp8I682mudKrYOI1HH+KjqS287kdZtZPzntHgSY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tycho.pizza; spf=pass smtp.mailfrom=tycho.pizza; dkim=pass (2048-bit key) header.d=tycho.pizza header.i=@tycho.pizza header.b=IMrQfajn; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=MFeTNtxF; arc=none smtp.client-ip=103.168.172.136 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tycho.pizza Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tycho.pizza Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailflow.nyi.internal (Postfix) with ESMTP id 33B85200178; Tue, 4 Jun 2024 18:13:39 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Tue, 04 Jun 2024 18:13:39 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tycho.pizza; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1717539219; x=1717546419; bh=muU5qJkRVr c/WJXrwBT0sJpUEwClb+SER/+HMwaSXbE=; b=IMrQfajnu+GoDRKlk7ICyJN2RB df07iUJTJhJdTdXsskFVN2YBYUA0ThPeeOJem8mlAf9L/GG0pOaXA/mfnqMtNioG Qg3eRDQefaetISlfIU3LvnYBFS+0WfChDyq/P0xWTWF51tbK50H/wqxB/DhcA16S ESVlf1iBwEBLJtPI18jyJFnVr5yiVI4at14G7PWsafABea8ghLtpKp3bfz8cO6/t O0WKTNLW57ZU36nkLt573ORKn1AUo/KT70eGo6mN4Y2LxhgmjlaNFtA0ZP9f2HmQ UxyyOOm10AqNUBs8MGdFCAnMfEjrdZfoimbLr5GfyIa537l6G6SLZuOKapuQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1717539219; x=1717546419; bh=muU5qJkRVrc/WJXrwBT0sJpUEwCl b+SER/+HMwaSXbE=; b=MFeTNtxFI2QMwDPKwN42XQzf9AsNmhYWklo3WTFDkq+5 O30Ex0pMTHobmgDJZPvk60WZp0Y9jCn6VNa9vEgyiOSzlNHUpOQDbOogCzi4Uu7Z LBpp7nP4M9ACiqmwIWUnhzCxldVtsnGoId+TKQAYhl3S+zgxq+Wuss+OlxQoEyI/ cLsXZYNpL/7MFJ6/vrwp+JsjJrekEHgVZ7hbSAwqRFbaVkDYbUkLvGIAYafIRftJ B6BtvThMJSEW4ZgPFzrmcDcEl36/UVQkZt1E0yaIPJO9pbgwusQ/npmm4pG/wEml ssfZc73DIRmqIheoviOdqsABd1gYrWz1kn1tRms8og== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdelhedgtdejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvdenucfhrhhomhepvfihtghh ohcutehnuggvrhhsvghnuceothihtghhohesthihtghhohdrphhiiiiirgeqnecuggftrf grthhtvghrnhepueettdetgfejfeffheffffekjeeuveeifeduleegjedutdefffetkeel hfelleetnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomh epthihtghhohesthihtghhohdrphhiiiiirg X-ME-Proxy: Feedback-ID: i21f147d5:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 4 Jun 2024 18:13:35 -0400 (EDT) Date: Tue, 4 Jun 2024 16:13:32 -0600 From: Tycho Andersen To: Simon Horman Cc: Kees Cook , Vlastimil Babka , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , jvoisin , Andrew Morton , Roman Gushchin , Hyeonggon Yoo <42.hyeyoo@gmail.com>, linux-mm@kvack.org, "GONG, Ruiqi" , Xiu Jianfeng , Suren Baghdasaryan , Kent Overstreet , Jann Horn , Matteo Rizzo , Thomas Graf , Herbert Xu , linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, netdev@vger.kernel.org Subject: Re: [PATCH v4 4/6] mm/slab: Introduce kmem_buckets_create() and family Message-ID: References: <20240531191304.it.853-kees@kernel.org> <20240531191458.987345-4-kees@kernel.org> <20240604150228.GS491852@kernel.org> 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: <20240604150228.GS491852@kernel.org> On Tue, Jun 04, 2024 at 04:02:28PM +0100, Simon Horman wrote: > On Fri, May 31, 2024 at 12:14:56PM -0700, Kees Cook wrote: > > + for (idx = 0; idx < ARRAY_SIZE(kmalloc_caches[KMALLOC_NORMAL]); idx++) { > > + char *short_size, *cache_name; > > + unsigned int cache_useroffset, cache_usersize; > > + unsigned int size; > > + > > + if (!kmalloc_caches[KMALLOC_NORMAL][idx]) > > + continue; > > + > > + size = kmalloc_caches[KMALLOC_NORMAL][idx]->object_size; > > + if (!size) > > + continue; > > + > > + short_size = strchr(kmalloc_caches[KMALLOC_NORMAL][idx]->name, '-'); > > + if (WARN_ON(!short_size)) > > + goto fail; > > + > > + cache_name = kasprintf(GFP_KERNEL, "%s-%s", name, short_size + 1); > > + if (WARN_ON(!cache_name)) > > + goto fail; > > + > > + if (useroffset >= size) { > > + cache_useroffset = 0; > > + cache_usersize = 0; > > + } else { > > + cache_useroffset = useroffset; > > + cache_usersize = min(size - cache_useroffset, usersize); > > + } > > + (*b)[idx] = kmem_cache_create_usercopy(cache_name, size, > > + align, flags, cache_useroffset, > > + cache_usersize, ctor); > > + kfree(cache_name); > > + if (WARN_ON(!(*b)[idx])) > > + goto fail; > > + } > > + > > + return b; > > + > > +fail: > > + for (idx = 0; idx < ARRAY_SIZE(kmalloc_caches[KMALLOC_NORMAL]); idx++) { > > + if ((*b)[idx]) > > + kmem_cache_destroy((*b)[idx]); > > nit: I don't think it is necessary to guard this with a check for NULL. Isn't it? What if a kasprintf() fails halfway through the loop? Tycho