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 1EDF1C3DA4A for ; Fri, 9 Aug 2024 09:00:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A433C6B0083; Fri, 9 Aug 2024 04:59:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9F2D26B0098; Fri, 9 Aug 2024 04:59:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 86CE46B009A; Fri, 9 Aug 2024 04:59:59 -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 68EA76B0083 for ; Fri, 9 Aug 2024 04:59:59 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 1E5FDC0BFC for ; Fri, 9 Aug 2024 08:59:59 +0000 (UTC) X-FDA: 82432109718.10.AF07CAF Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by imf27.hostedemail.com (Postfix) with ESMTP id 804074000E for ; Fri, 9 Aug 2024 08:59:55 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=hecFQTnj; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=KZgbGkEK; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=hecFQTnj; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=KZgbGkEK; spf=pass (imf27.hostedemail.com: domain of vbabka@suse.cz designates 195.135.223.131 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1723193929; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=qJDjhIoxUXDLGf1tiz/qcgoJ9zcTAnQZcgHgMroPuCA=; b=BF70lMA4JY+HJvLHjDCwWNvLemeSBU4sMCL1zL7AtC/l/pVt4getEOFntiZQweScjEmVqW D1D3ziOliUoLveBpaIGgSEtj7EzcK6KP/+Q62F66pjJDzwfk7C98rHODAwaEzDT7n2Rs5O wGg8xgdpBFrguDSP9xIki4gcGlPnIzM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723193929; a=rsa-sha256; cv=none; b=CzHPlLm6pXTZAvlicvQGYPppNjIqegJzzp8CzI6YF6GwpMm8JJwPf//u2YXFEz+maWI/tg S3aWvWPxTpWdulIoc4NJzuXslWjBErCZGd1ltRxbDuMnGgU1a9VR/6GCHR3r6Ovp+J5Xu8 8MfDbbYf5a78c33+h3/YXzz2DuhBl/s= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=hecFQTnj; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=KZgbGkEK; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=hecFQTnj; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=KZgbGkEK; spf=pass (imf27.hostedemail.com: domain of vbabka@suse.cz designates 195.135.223.131 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 953271FF2F; Fri, 9 Aug 2024 08:59:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1723193993; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:autocrypt:autocrypt; bh=qJDjhIoxUXDLGf1tiz/qcgoJ9zcTAnQZcgHgMroPuCA=; b=hecFQTnj4dlXZQBDKyFkZXK1KHRihuLmHA9kO1nBPTsQgGxn2v872Jus4rlY8wE9g/4Znd YrfwzhaObA1h/zOnOy3MCdOpnMtm+oshtlJxyp5uwz9WVV7tdaJjBav+nnbz92hDN2o7sg 46Ebumhj56azk1lcqsWtQnLkFGeampI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1723193993; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:autocrypt:autocrypt; bh=qJDjhIoxUXDLGf1tiz/qcgoJ9zcTAnQZcgHgMroPuCA=; b=KZgbGkEK608Fs+II5f0AjZyee9zRmn437pR7XFn+xvI4flIa3KJ2ZdzeLvl2pjO/rcq5iE KPN2wMYGd02IfoBw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1723193993; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:autocrypt:autocrypt; bh=qJDjhIoxUXDLGf1tiz/qcgoJ9zcTAnQZcgHgMroPuCA=; b=hecFQTnj4dlXZQBDKyFkZXK1KHRihuLmHA9kO1nBPTsQgGxn2v872Jus4rlY8wE9g/4Znd YrfwzhaObA1h/zOnOy3MCdOpnMtm+oshtlJxyp5uwz9WVV7tdaJjBav+nnbz92hDN2o7sg 46Ebumhj56azk1lcqsWtQnLkFGeampI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1723193993; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:autocrypt:autocrypt; bh=qJDjhIoxUXDLGf1tiz/qcgoJ9zcTAnQZcgHgMroPuCA=; b=KZgbGkEK608Fs+II5f0AjZyee9zRmn437pR7XFn+xvI4flIa3KJ2ZdzeLvl2pjO/rcq5iE KPN2wMYGd02IfoBw== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 6ADD413A7D; Fri, 9 Aug 2024 08:59:53 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id iEGdGYnatWb0LQAAD6G6ig (envelope-from ); Fri, 09 Aug 2024 08:59:53 +0000 Message-ID: Date: Fri, 9 Aug 2024 10:59:52 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] slab: Introduce kmalloc_obj() and family Content-Language: en-US To: Kees Cook 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 , linux-mm@kvack.org, Nathan Chancellor , Nick Desaulniers , linux-kernel@vger.kernel.org, llvm@lists.linux.dev, linux-hardening@vger.kernel.org References: <20240807235433.work.317-kees@kernel.org> From: Vlastimil Babka Autocrypt: addr=vbabka@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++veI6tXfpco/UiKEsDswL1WAr tEAZaruo7254TyH+gydURl2wJuzo/aZ7Y7PpqaODbYv727Dvm5eX64HCyyAH0s6sOCyGF5/p eIhrOn24oBf67KtdAN3H9JoFNUVTYJc1VJU3R1JtVdgwEdr+NEciEfYl0O19VpLE/PZxP4wX PWnhf5WjdoNI1Xec+RcJ5p/pSel0jnvBX8L2cmniYnmI883NhtGZsEWj++wyKiS4NranDFlA HdDM3b4lUth1pTtABKQ1YuTvehj7EfoWD3bv9kuGZGPrAeFNiHPdOT7DaXKeHpW9homgtBxj 8aX/UkSvEGJKUEbFL9cVa5tzyialGkSiZJNkWgeHe+jEcfRT6pJZOJidSCdzvJpbdJmm+eED w9XOLH1IIWh7RURU7G1iOfEfmImFeC3cbbS73LQEFGe1urxvIH5K/7vX+FkNcr9ujwWuPE9b 1C2o4i/yZPLXIVy387EjA6GZMqvQUFuSTs/GeBcv0NjIQi8867H3uLjz+mQy63fAitsDwLmR EP+ylKVEKb0Q2A== In-Reply-To: <20240807235433.work.317-kees@kernel.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spamd-Bar: / X-Rspamd-Action: no action X-Stat-Signature: wns6cj1ktai7s3i7umom8r1hm1zudnzq X-Rspamd-Queue-Id: 804074000E X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1723193995-594970 X-HE-Meta: U2FsdGVkX1+u80P1mH0xNgbpjj7gTBmkzTnIIalNgY+kqkNI5R8Wu+hry37xuOkvCezSSchEbJgqBLQW+rKmsTUQ9oIweCBsK8h8JHdGUA4wfGPqh8xdtglfuHr6+KFXYxT075lTlhoDnPY//eNiJtTfjEMwz9Uifqzq3rjDBXhTP6krYRWKVc0SU9vZ4yFMgea4IjYGXhzdgh/cqDl8cJdG4uriW4tk36NtNz010JpBSIboGuJaAaNb8Ar8mzKx5+RvH65rJ8QoUJSsmV235xjU52guv/xduc7eAI80dhSzxQzyYwkklS+w4O33TJwDQDuu802NNREwGYT9XNgP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y6Vi7c33kEq+6cBBQE4cDZ3Kum4XZvyY19vZddgXnqGAFmvZZF7Ed3ME2ITlYSScykzub0OgyXnOwzzHIzxhr5BaSRIOJSrw3HbadWMX3eePh6hIUu0jvIKKXLDuV8e5lrt01rcLNItXsCSmIk8uWRfn6qY9Lbx+NsqSMzLlWNTFptjf6R96HBh9EMrjewNMpMoXGe8WC4PX+6MluEyAI+/ETukCDNTeJDhjEqNEQztVb050gdv0s59O0ZpW8GQNBZGXKtJmHK0eDeXptVxaTmJfecJkNSsQCijRnI4IffQGlKPi9ybw03145rxm23zTu/teji5PBxZ7ukSjVvsOQ8oHMJzm17MXe6nugwnND0JI+CP2pyphrN5JvGfUSJPVQU587m29YyVpDATwIRYgVyUzJsg= 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 8/8/24 01:54, Kees Cook wrote: > Introduce type-aware kmalloc-family helpers to replace the common > idioms for single, array, and flexible object allocations: > > ptr = kmalloc(sizeof(*ptr), gfp); > ptr = kcalloc(count, sizeof(*ptr), gfp); > ptr = kmalloc_array(count, sizeof(*ptr), gfp); > ptr = kcalloc(count, sizeof(*ptr), gfp); > ptr = kmalloc(struct_size(ptr, flex_member, count), gfp); > > These become, respectively: > > kmalloc_obj(p, gfp); > kzalloc_obj(p, count, gfp); > kmalloc_obj(p, count, gfp); > kzalloc_obj(p, count, gfp); > kmalloc_obj(p, flex_member, count, gfp); So I'm not a huge fan in hiding the assignment, but I understand there's value in having guaranteed the target of the assignment is really the same thing as the one used for sizeof() etc. But returning size seems awkward, it would be IMHO less confusing if it still returned the object pointer, that could be then also assigned elsewhere if needed, tested for NULL and ZERO_SIZE_PTR (now it's both 0?). I'm also not sure that having it all called kmalloc_obj() with 3 variants of how many parameters it takes is such a win? e.g. kmalloc_obj(), kcalloc_obj() and kcalloc_obj_flex() would be more obvious? > These each return the size of the allocation, so that other common > idioms can be converted easily as well. For example: > > info->size = struct_size(ptr, flex_member, count); > ptr = kmalloc(info->size, gfp); > > becomes: > > info->size = kmalloc_obj(ptr, flex_member, count, gfp); How about instead taking an &info->size parameter that assigns size to it, so the ptr can be still returned but we also can record the size? Also the last time David asked for documentation, you say you would try, but there's nothing new here? Dunno if the kerneldocs are feasible but there's at least Documentation/core-api/memory-allocation.rst ... Thanks, Vlastimil > Internal introspection of allocated type also becomes possible, allowing > for alignment-aware choices and future hardening work. For example, > adding __alignof(*ptr) as an argument to the internal allocators so that > appropriate/efficient alignment choices can be made, or being able to > correctly choose per-allocation offset randomization within a bucket > that does not break alignment requirements. > > Additionally, once __builtin_get_counted_by() is added by GCC[1] and > Clang[2], it will be possible to automatically set the counted member of > a struct with a counted_by FAM, further eliminating open-coded redundant > initializations, and can internally check for "too large" allocations > based on the type size of the counter variable: > > if (count > type_max(ptr->flex_count)) > fail...; > info->size = struct_size(ptr, flex_member, count); > ptr = kmalloc(info->size, gfp); > ptr->flex_count = count; > > becomes (i.e. unchanged from earlier example): > > info->size = kmalloc_obj(ptr, flex_member, count, gfp); > > Replacing all existing simple code patterns found via Coccinelle[3] > shows what could be replaced immediately (saving roughly 1,500 lines): > > 7040 files changed, 14128 insertions(+), 15557 deletions(-) > > Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116016 [1] > Link: https://github.com/llvm/llvm-project/issues/99774 [2] > Link: https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/kmalloc_obj-assign-size.cocci [3] > Signed-off-by: Kees Cook > --- > Cc: Vlastimil Babka > Cc: Christoph Lameter > Cc: Pekka Enberg > Cc: David Rientjes > Cc: Joonsoo Kim > Cc: Andrew Morton > Cc: Roman Gushchin > Cc: Hyeonggon Yoo <42.hyeyoo@gmail.com> > Cc: Gustavo A. R. Silva > Cc: Bill Wendling > Cc: Justin Stitt > Cc: Jann Horn > Cc: Przemek Kitszel > Cc: Marco Elver > Cc: linux-mm@kvack.org > --- > include/linux/slab.h | 38 ++++++++++++++++++++++++++++++++++++++ > 1 file changed, 38 insertions(+) > > diff --git a/include/linux/slab.h b/include/linux/slab.h > index eb2bf4629157..46801c28908e 100644 > --- a/include/linux/slab.h > +++ b/include/linux/slab.h > @@ -686,6 +686,44 @@ static __always_inline __alloc_size(1) void *kmalloc_noprof(size_t size, gfp_t f > } > #define kmalloc(...) alloc_hooks(kmalloc_noprof(__VA_ARGS__)) > > +#define __alloc_obj3(ALLOC, P, COUNT, FLAGS) \ > +({ \ > + size_t __obj_size = size_mul(sizeof(*P), COUNT); \ > + void *__obj_ptr; \ > + (P) = __obj_ptr = ALLOC(__obj_size, FLAGS); \ > + if (!__obj_ptr) \ > + __obj_size = 0; \ > + __obj_size; \ > +}) > + > +#define __alloc_obj2(ALLOC, P, FLAGS) __alloc_obj3(ALLOC, P, 1, FLAGS) > + > +#define __alloc_obj4(ALLOC, P, FAM, COUNT, FLAGS) \ > +({ \ > + size_t __obj_size = struct_size(P, FAM, COUNT); \ > + void *__obj_ptr; \ > + (P) = __obj_ptr = ALLOC(__obj_size, FLAGS); \ > + if (!__obj_ptr) \ > + __obj_size = 0; \ > + __obj_size; \ > +}) > + > +#define kmalloc_obj(...) \ > + CONCATENATE(__alloc_obj, \ > + COUNT_ARGS(__VA_ARGS__))(kmalloc, __VA_ARGS__) > + > +#define kzalloc_obj(...) \ > + CONCATENATE(__alloc_obj, \ > + COUNT_ARGS(__VA_ARGS__))(kzalloc, __VA_ARGS__) > + > +#define kvmalloc_obj(...) \ > + CONCATENATE(__alloc_obj, \ > + COUNT_ARGS(__VA_ARGS__))(kvmalloc, __VA_ARGS__) > + > +#define kvzalloc_obj(...) \ > + CONCATENATE(__alloc_obj, \ > + COUNT_ARGS(__VA_ARGS__))(kvzalloc, __VA_ARGS__) > + > #define kmem_buckets_alloc(_b, _size, _flags) \ > alloc_hooks(__kmalloc_node_noprof(PASS_BUCKET_PARAMS(_size, _b), _flags, NUMA_NO_NODE)) >