Received: by 2002:ab2:6d45:0:b0:1fb:d597:ff75 with SMTP id d5csp527119lqr; Wed, 5 Jun 2024 12:55:01 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV/f739wdiFfzHyti8JrT8g3RUxejI9k4Ri4tzQTshbOUN9XvtrhKQB+5l0Px8svfmPhX5x1tGz8e1/qxPAoAGXRuiIBJQbTi5KDmqnAQ== X-Google-Smtp-Source: AGHT+IG5t3AFD3idqrhtbWSFXnbqrHzkdozBfBCgHjivC//WvzxcvqdKh5ZNWl6j2+DNtBiNzMvK X-Received: by 2002:a05:600c:138f:b0:421:5604:d1c1 with SMTP id 5b1f17b1804b1-421563503fdmr37790595e9.35.1717617301596; Wed, 05 Jun 2024 12:55:01 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717617301; cv=pass; d=google.com; s=arc-20160816; b=hIUQklTKRvAERucNj5NFFn70xmes6oEsboEUH18HDYyhLo5z9a6Te3SA4f7UU635ik /1u4PwZ8zclXcGw/ed3ikxJP4stnRWRdMhoGTUAFu0KydPjL0LT+YWTDL1WAgpAWzp17 8Ik4L1pxOqMagnJFKVo7hgZZgqK0+Pu9FEVNaNE/XkqhA8j/HaSmolcsgJstLZc284R6 3k4OQ2Ha+VT/L9g1CQP6o2cxUoZHAV0dy8lL/uFHBmp6ssqk/ihz2FuLsRjvdjF861v4 s/19heqs+RnQtuxMdU6Q/Wr1uyu7I2GHltamOIxNUIYbTJi1vBburs2p6YYoEVGrYRCq nq8w== 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:dkim-signature; bh=snYvmDiZ7+0x4/UCBsY4VeXGD6oP53aa7uz+GO0dYRM=; fh=DkcINGlHCABkfGsKgIx7iOQbdcESCVLuK1KhiIBEy6A=; b=s+LcR8wcnE0yKKMR640sUtkLbMVLaGZsVzkRFpHwlgn1UFtoCoN/sl98uH4glu2ww4 uwb8YjaFHS83YquXmwBcNhW1EDg4fLqJo63uO6BaOVozOK5g54l6wrBO+SGkS8nyxke+ jww0TLdpD32czi+HnDn9wh6tFK4wlvdFSoRNW1xvuRnJq/MXvQ7y6rSFxOnmjmxNpHy4 uaoh2CQqy29hlV3K7q/uRmzcOiuMxNw+DXrRIubMkFAsm5f1QdN+EBgHsoYasWOJqZc2 CuUNyj3I9PwMclzm3UFNoOyByvbzrQUU779fK+Z3G8UZI2PIYKo4yjXdZpMfJpkZbXlX U0uQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=bo+Tymvp; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-203128-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-203128-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id a640c23a62f3a-a690e8538f5si345539566b.1026.2024.06.05.12.55.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jun 2024 12:55:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-203128-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=bo+Tymvp; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-203128-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-203128-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=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 am.mirrors.kernel.org (Postfix) with ESMTPS id 4F3E51F23938 for ; Wed, 5 Jun 2024 19:55:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4B40D154437; Wed, 5 Jun 2024 19:54:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="bo+Tymvp" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 6878C154BF9; Wed, 5 Jun 2024 19:54:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717617281; cv=none; b=Kfl1syNWNudVCil5nKZiG8t6HS5+9fKCuPoZIgVXmFLb1nEz72rjzWp7JoaueDn3lv6Sf7aNWRpqOCcuRaPpAiw19S9V/59awVIDBAbEI5XwQyy3fwec5lLXjp96PAbSuk5yfe7ZNbqF4FGitk4OKeeaLcvRRMbglpdDKcBmkE0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717617281; c=relaxed/simple; bh=C/d+QzzEEXD3nP3fLH1CEjnoNOPR1mWYBBp0rsQc8ZA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=QdVqB52L53dKHW8jBUVx8VCkkNXo2uDoG/VKW/Rb7Z/W4IY8Oi9oVm5kqNxdfwBbjXqAnPcQ0VOUjgRI5qm5kylNcKN/zCzwazS8Ua8mNkV7LA3q271T7VNqWqSgK8wB/vrUOSQEEiCkxv6ytsLl62QIxFaKfMBaINDtuFTRy9E= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=bo+Tymvp; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 46803C2BD11; Wed, 5 Jun 2024 19:54:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717617281; bh=C/d+QzzEEXD3nP3fLH1CEjnoNOPR1mWYBBp0rsQc8ZA=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=bo+TymvpxxRc2c3hAxES9XbNbQqulQYx1SsCVi28ZwWJLt7AFPjcGIX9mbNoBkJ65 jDahOBbTgwf17xQ4MB/Paf0qi84pSEdTOsZU03OVY+Mo76vLIlYJzMofh0I4bQF2h3 LTFJ6sQzuBR5IuaobyoHBIQLudhDWvyRUaxN783YjdX7bWIUmjqAcw+UloBJNWpprc t/6aZNUqUZTX7TsETyB5gt4XVB3sUmwOsaaNu/kOtJ8waFsyKw0wgl2Hm0ER40ncaG GGVUd//wgrYXjnuHbZx1++O21swJtbbqoEcau3lj8WW9wCEFFQ2EZUSKuNbTLgofRW O7u+xQN4j/MLg== Date: Wed, 5 Jun 2024 20:54:33 +0100 From: Simon Horman To: Kees Cook Cc: Tycho Andersen , 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: <20240605195433.GA791188@kernel.org> References: <20240531191304.it.853-kees@kernel.org> <20240531191458.987345-4-kees@kernel.org> <20240604150228.GS491852@kernel.org> <202406041749.27CAE270@keescook> 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: <202406041749.27CAE270@keescook> On Tue, Jun 04, 2024 at 05:49:20PM -0700, Kees Cook wrote: > On Tue, Jun 04, 2024 at 04:13:32PM -0600, Tycho Andersen wrote: > > 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? > > He means that kmem_cache_destroy() already checks for NULL. Quite right! > > void kmem_cache_destroy(struct kmem_cache *s) > { > int err = -EBUSY; > bool rcu_set; > > if (unlikely(!s) || !kasan_check_byte(s)) > return; Yes, thanks. That is what I was referring to.