From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 074A6D26D7B for ; Fri, 9 Jan 2026 17:31:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 69ECC6B008A; Fri, 9 Jan 2026 12:31:07 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 655456B0092; Fri, 9 Jan 2026 12:31:07 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 57EC46B0093; Fri, 9 Jan 2026 12:31:07 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 4815F6B008A for ; Fri, 9 Jan 2026 12:31:07 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id D60731A04E0 for ; Fri, 9 Jan 2026 17:31:06 +0000 (UTC) X-FDA: 84313116132.07.BF2059F Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by imf03.hostedemail.com (Postfix) with ESMTP id 255FE20008 for ; Fri, 9 Jan 2026 17:31:04 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Zb3uH6ZB; spf=pass (imf03.hostedemail.com: domain of kees@kernel.org designates 172.234.252.31 as permitted sender) smtp.mailfrom=kees@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1767979865; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=40Ey/3HPItE71dh6jwnm5qreFl/HUxRow6GBKJqmy5w=; b=x0OyoF0vVsuifR84kt4swTQZmvZYOfEWfDtPTesnwmDJSgHEKLv6buXI8hpi6L7vsXUBsU dGvRYkPX180euZEjif2M7BRE8JEC+7zJXVzkPYLmM2/kibnchNWwdoxzLl/ZawpUccK3F0 SJWf2uCijjvOJQfTzgE9xE+aA381enM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1767979865; a=rsa-sha256; cv=none; b=a+5+CKwIPXDCEmBXG7B+pDQ6Lbnwx9Qke48rjVwifLhNzCw68jMNfMB/kfvIDCBckFT7vJ N0unoYG58OBe4xlRxjQNNehNkpYmJZjbCGGclWYmpmDCoUqTjiC7dpdxZSYh5lpHnf1Bpm GS7zPyTzstWfP9+l6bBPcORP4fJBl8Q= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Zb3uH6ZB; spf=pass (imf03.hostedemail.com: domain of kees@kernel.org designates 172.234.252.31 as permitted sender) smtp.mailfrom=kees@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sea.source.kernel.org (Postfix) with ESMTP id F203943CB3; Fri, 9 Jan 2026 17:31:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C7A50C4CEF1; Fri, 9 Jan 2026 17:31:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1767979863; bh=YnLjCzKnQER3FuCe6ES9oXxik4owd0B4EMad2UIfiEw=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Zb3uH6ZBwZfeObknlMhLXz6y0O7Yd+lcbqIxtpbkgUGG6UavcGoHaRkBQvHZSNF2n pQStdXJI1VohLDeR1qpGF74WFMxDsP/uXeJR+ObR3RrmnJaCqkS95C+Hw0RpNuFcf5 GoPAEEt/X36hy1dO8AoxU3CZSoGH+q/jL1yiONf0HXzyNofTsQ2jvKOxGds4kh8Yhz XVSGdZy9JI1VUWHgjUrbt0jIjhucw841A0LBiPb8vTymFKMiKsqN6rHciHgyobsQQ3 nf6x6z0AGWB9ZAu1Tb/cMu8zbewvjfXfN+ipM7+VPadMwl1+2i0KkND8uJpI3Sk4hA Gw6D4gc9Kd9pQ== Date: Fri, 9 Jan 2026 09:31:03 -0800 From: Kees Cook To: Vlastimil Babka Cc: Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Roman Gushchin , Hyeonggon Yoo <42.hyeyoo@gmail.com>, "Gustavo A . R . Silva" , Bill Wendling , Justin Stitt , Jann Horn , Przemek Kitszel , Marco Elver , Linus Torvalds , Greg Kroah-Hartman , Sasha Levin , linux-mm@kvack.org, Randy Dunlap , Miguel Ojeda , Matthew Wilcox , John Hubbard , Joe Perches , Vegard Nossum , Harry Yoo , Nathan Chancellor , Peter Zijlstra , Nick Desaulniers , Jonathan Corbet , Jakub Kicinski , Yafang Shao , Tony Ambardar , Alexander Lobakin , Jan Hendrik Farr , Alexander Potapenko , linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, linux-doc@vger.kernel.org, llvm@lists.linux.dev Subject: Re: [PATCH v6 1/5] slab: Introduce kmalloc_obj() and family Message-ID: <202601090928.5CFF95F@keescook> References: <20251203233029.it.641-kees@kernel.org> <20251203233036.3212363-1-kees@kernel.org> <960729bb-0746-4709-a40c-2e254f963deb@suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <960729bb-0746-4709-a40c-2e254f963deb@suse.cz> X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: 255FE20008 X-Rspam-User: X-Stat-Signature: 9w3zzf1xmau7iwtjgdgp5kh9r8q8jeo3 X-HE-T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PbxkInUBqY1geJvJk4LBdzmmEjE4Ew/kROt9yO+c1yLfAZyq7S1cA5Lv/5o7eExXOjj0fOn7o9TXaiXG9Kfe49+L2u7rdPeBeN6vpqfHusDL28sHPknBWikQOmUu9uTyBrk+UdkC6g1zW238N9vrunCEUnoUvx3Opep0m34hWfv+QqbnlzZBKqzU+XIBhCenexIpeL3wOHZbePn9FVDmWss6KhiOHPRVlC7+cbqvWC1klIjXXO86Xe4Eii4pyO8KRx2IfuvyGFRfXxg3wwnFa0i269c81k1AZdMD6VjPmuEAyUopTnC8 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Thu, Jan 08, 2026 at 03:01:00PM +0100, Vlastimil Babka wrote: > On 12/4/25 00:30, Kees Cook wrote: > > [...] > > +/** > > + * __alloc_objs - Allocate objects of a given type using > > + * @KMALLOC: which size-based kmalloc wrapper to allocate with. > > + * @GFP: GFP flags for the allocation. > > + * @TYPE: type to allocate space for. > > + * @COUNT: how many @TYPE objects to allocate. > > + * > > + * Returns: Newly allocated pointer to (first) @TYPE of @COUNT-many > > + * allocated @TYPE objects, or NULL on failure. > > + */ > > +#define __alloc_objs(KMALLOC, GFP, TYPE, COUNT) \ > > +({ \ > > + const size_t __obj_size = size_mul(sizeof(TYPE), COUNT); \ > > I assume with the hardcoded 1 for COUNT, this size_mul() will be eliminated > by the compiler and not add unnecessary runtime overhead? Otherwise we > should have two core #define variants. You're correct: the compiler completely collapses it with 0 runtime overhead; a variant is not needed. > I also noted that the existing kmalloc_array() and kvmalloc_array() do > check_mul_overflow() and return NULL silently on overflow. This AFAIU will > make SIZE_MAX passed to the underlying kmalloc/kvmalloc and thus will cause > a warning. That's IMHO a good thing. Right -- I prefer seeing the SIZE_MAX yelling from the allocator. Should we change how k*malloc_array() behaves? -Kees -- Kees Cook