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]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8CB3CC3DA42 for ; Tue, 9 Jul 2024 23:28:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1A8A86B0089; Tue, 9 Jul 2024 19:28:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 156DB6B008A; Tue, 9 Jul 2024 19:28:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 01EF06B008C; Tue, 9 Jul 2024 19:28:35 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id D6A2C6B0089 for ; Tue, 9 Jul 2024 19:28:35 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 5A61D1C3872 for ; Tue, 9 Jul 2024 23:28:35 +0000 (UTC) X-FDA: 82321805790.07.689C271 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf14.hostedemail.com (Postfix) with ESMTP id ADA9410000D for ; Tue, 9 Jul 2024 23:28:33 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=OTRsqPti; spf=pass (imf14.hostedemail.com: domain of kees@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=kees@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1720567683; 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=psw3diCmEKeqI+sO/4G11JFe2zaf+Wnnz1C5n/YhSsI=; b=1Wwt5hZnc6dKycMRicoHTpmIsiYhKINeG/PeEP2+eMMId7abNqIoiO5memLBM8UZe3dTln 9h0QtsWyg7v4YJXJ/vpSYUtLD51blXEmOoPLBDBWWgk3AThm90KHW3i0PURCqg2ZeLozcb rF16KBAV8Q7s0efhe9ExVMiWk9xiW2Y= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1720567683; a=rsa-sha256; cv=none; b=ICMJzyN81EI/I4am36YwBMLluWSsD7xedDtVNju/0QITqTOOOfi0+JqKn90vKtjhpUYGGJ iIcdvIz34r2t2fr0QukpqyIrRkjTCDWjOyrHmReUHkxXJMIG2J/5DNoOCIuKCrCreEnqzT NVNUeM2w8NtpPabFDo0RPpuW90aqGLg= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=OTRsqPti; spf=pass (imf14.hostedemail.com: domain of kees@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=kees@kernel.org; dmarc=pass (policy=none) header.from=kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id A7DDF617FE; Tue, 9 Jul 2024 23:28:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 50BC6C3277B; Tue, 9 Jul 2024 23:28:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1720567712; bh=lvesHLF81y/HFp8sC+rXLTKbkTd8gGQTxpQyVxDp8sU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=OTRsqPti+YtA2DeQOX8Xa/KK2okR99fS4Zz1Yu6Q+xNtJVce7zCU8ta0+hjhxo2X9 pLqAI8/8t9VolE9h/3Gff6W4/gJi5vpOwSzl9nHon+uBj8RVritGt3JZKdB3QKMkXq FGqr0Jhv/YG2hgQ5Al/UlU+TTPiazmL1gt8sy3TFbTR/2KTlFgLoMno4RMMIqMDH+c z1HlLoR8+GxO/ZEKqdSwHVzv0Agwqq0yUVHuUkVQXaEjsBOsaisYr1eM6oMFRqIfJi uK6+pNwt2JkZaoFofwOuECF0+Ih18fjfopA3ePmpQ5nFOAJ34CnyWBPcPiV8XsCULh 5HDMrdjTMRlcw== Date: Tue, 9 Jul 2024 16:28:31 -0700 From: Kees Cook To: Marco Elver Cc: "Christoph Lameter (Ampere)" , Vlastimil Babka , Jann Horn , Tony Luck , Nick Desaulniers , Miguel Ojeda , Nathan Chancellor , Hao Luo , Przemek Kitszel , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Roman Gushchin , Hyeonggon Yoo <42.hyeyoo@gmail.com>, "Guilherme G. Piccoli" , Mark Rutland , Jakub Kicinski , Petr Pavlu , Alexander Lobakin , Tony Ambardar , linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-hardening@vger.kernel.org Subject: Re: [RFC][PATCH 0/4] slab: Allow for type introspection during allocation Message-ID: <202407091626.055933E3@keescook> References: <20240708190924.work.846-kees@kernel.org> <202407091327.AEF6C020D@keescook> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Queue-Id: ADA9410000D X-Stat-Signature: w39hsgm6gimako5mke1xxez9ng3rsop3 X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1720567713-444373 X-HE-Meta: U2FsdGVkX1/3oG0Hcnq2OiGPZEwIzkFJPzgfeJktKBjb/SIx8Bi8kAf58lHjVIkIqqYzQVyNiCQzaiav3gt+ryyKrWV02YDYd/Rv5eMr9TneZTVdvWiU5nbH5rlPWh6e2Qyyl6riTF1Ah6qac/FM1oTy1k6qJ3y/HQ5+RciBz4TUvBR/wKXdOcFfTCsFCfVWvFH3QAwGlXldgmjDssKKHUaOXFrYpvOokFGHeHZOnB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jt1fMOg5qpF0LDwBcsm9QJuWcOfMM 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 Tue, Jul 09, 2024 at 11:02:55PM +0200, Marco Elver wrote: > On Tue, 9 Jul 2024 at 22:28, Kees Cook wrote: > > > > On Tue, Jul 09, 2024 at 10:26:32AM -0700, Christoph Lameter (Ampere) wrote: > > > On Mon, 8 Jul 2024, Kees Cook wrote: > > > > > > > > > > > obj = kmalloc(obj, gfp); > > > > > > Could we avoid repeating "obj" in this pattern? > > > > > > F.e. > > > > > > KMALLOC(obj, gfp); > > > > This appears to be the common feedback, which is good! :) And we can > > still have it return "obj" as well, so it could still be used in > > "return" statements, etc. I will work up a new RFC... > > More macros like this only obfuscate the code further. The name would > become something that makes it really clear there's an assignment. > > assign_kmalloc(obj, gfp) > > There may be better options. Also ALLCAPS could be avoided here, as we > have done with other language-like features (vs. pure constants). So, in looking a code patterns, it seems what we really want more than returning the object that was allocated is actually returning the size of the allocation size requested. i.e.: info->size = struct_size(ptr, flex_member, count); info->obj = kmalloc(info->size, gfp); would become: info->size = kmalloc(info->obj, flex_member, count, gfp); -Kees -- Kees Cook