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 8AFC3C433FE for ; Fri, 18 Nov 2022 11:34:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F03AE6B0071; Fri, 18 Nov 2022 06:34:04 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E8CBC6B0072; Fri, 18 Nov 2022 06:34:04 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D2D6D8E0001; Fri, 18 Nov 2022 06:34:04 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id BFA6D6B0071 for ; Fri, 18 Nov 2022 06:34:04 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 88760C12E9 for ; Fri, 18 Nov 2022 11:34:04 +0000 (UTC) X-FDA: 80146354008.20.1848D5F Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by imf05.hostedemail.com (Postfix) with ESMTP id DED15100007 for ; Fri, 18 Nov 2022 11:34:03 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 4D5A11F924; Fri, 18 Nov 2022 11:34:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1668771242; 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; bh=vqSiCxu0crNnAzpBOtWKIOFuXwsDyaQFJ8B2fw8hztU=; b=xp48TrunWilM2VXMJbQPGTCbgKrJrgN3/aoAOejdXxVAGchLpF3F9uvn6FpEgI4NasjQk6 3WycA9Mc4kS/QqHoRbGZNk7C6mHpBWX6tl0lo3GZCDqb/c7wmgK15aQJwiCZhcOl1wtkwy N2dvm/1Uh/7JlElbffoX2que33AsF3M= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1668771242; 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; bh=vqSiCxu0crNnAzpBOtWKIOFuXwsDyaQFJ8B2fw8hztU=; b=CgCD0rV8e7C6NT95+K7bUFTcW0V980dqZtzu8vKcdLloVmCtk7emO2d9lT5afUd5q1K5Mf Wt3GVlDesgwQ/mDA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 231CB13A66; Fri, 18 Nov 2022 11:34:02 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id Q9jqB6ptd2P4aQAAMHmgww (envelope-from ); Fri, 18 Nov 2022 11:34:02 +0000 Message-ID: Date: Fri, 18 Nov 2022 12:34:01 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Subject: Re: [PATCH v2 2/2] slab: Remove special-casing of const 0 size allocations 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>, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org References: <20221118034713.gonna.754-kees@kernel.org> <20221118035200.1269184-2-keescook@chromium.org> From: Vlastimil Babka In-Reply-To: <20221118035200.1269184-2-keescook@chromium.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1668771244; a=rsa-sha256; cv=none; b=ovn5plPJ6bOGWlpXm0obXfjMkBQOX15uB+TxMq3NzF5P9xGkupSKiIxjab2ehc7HHaRH27 NvtaPYrbc+61qczhkFeHmspaneuaM+tl+PbU4PxrwwoQhgnAjHe6P+fwn5MGjNCSxBlhUO LnDMets7gyxSsg2N4jXjijQKtZ0y+ck= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=xp48Trun; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=CgCD0rV8; dmarc=none; spf=pass (imf05.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.29 as permitted sender) smtp.mailfrom=vbabka@suse.cz ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1668771244; 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=vqSiCxu0crNnAzpBOtWKIOFuXwsDyaQFJ8B2fw8hztU=; b=5sopP4JYEB9La0Ef2sp0HVx9WKAl+hTaXLh4IknoEDtas+1b/v3K8iM44uIbGfE3NjGtbF rzyiCxoCwQDT0RDMH+v8aRLKSePA+aBTbd5Rg0SfEL91oquQkQMw7Cw5FQ1lc45WRy80xP n5eXXcIYA4i07zd/x1YQa/lZXxUYfBk= X-Stat-Signature: rnt5t3c4bgbxjbt4hw89tquysrnz57pg X-Rspamd-Queue-Id: DED15100007 Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=xp48Trun; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=CgCD0rV8; dmarc=none; spf=pass (imf05.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.29 as permitted sender) smtp.mailfrom=vbabka@suse.cz X-Rspam-User: X-Rspamd-Server: rspam12 X-HE-Tag: 1668771243-423471 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: On 11/18/22 04:51, Kees Cook wrote: > Passing a constant-0 size allocation into kmalloc() or kmalloc_node() > does not need to be a fast-path operation, so the static return value > can be removed entirely. This is in preparation for making sure that > all paths through the inlines result in a full extern function call, So with the kmalloc_trace() already solved, we could now say it's not "in preparation", but simply "makes sure", right? I can correct that while picking this patch. > where __alloc_size() hints will actually be seen[1] by GCC. (A constant > return value of 0 means the "0" allocation size won't be propagated by > the inline.) > > [1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96503 > > 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: linux-mm@kvack.org > Signed-off-by: Kees Cook > --- > include/linux/slab.h | 12 ++---------- > 1 file changed, 2 insertions(+), 10 deletions(-) > > diff --git a/include/linux/slab.h b/include/linux/slab.h > index 9033937c758e..84be05208418 100644 > --- a/include/linux/slab.h > +++ b/include/linux/slab.h > @@ -561,17 +561,13 @@ void *kmalloc_large_node(size_t size, gfp_t flags, int node) __assume_page_align > #ifndef CONFIG_SLOB > static __always_inline __alloc_size(1) void *kmalloc(size_t size, gfp_t flags) > { > - if (__builtin_constant_p(size)) { > + if (__builtin_constant_p(size) && size) { > unsigned int index; > > if (size > KMALLOC_MAX_CACHE_SIZE) > return kmalloc_large(size, flags); > > index = kmalloc_index(size); > - > - if (!index) > - return ZERO_SIZE_PTR; > - > return kmalloc_trace( > kmalloc_caches[kmalloc_type(flags)][index], > flags, size); > @@ -591,17 +587,13 @@ static __always_inline __alloc_size(1) void *kmalloc(size_t size, gfp_t flags) > #ifndef CONFIG_SLOB > static __always_inline __alloc_size(1) void *kmalloc_node(size_t size, gfp_t flags, int node) > { > - if (__builtin_constant_p(size)) { > + if (__builtin_constant_p(size) && size) { > unsigned int index; > > if (size > KMALLOC_MAX_CACHE_SIZE) > return kmalloc_large_node(size, flags, node); > > index = kmalloc_index(size); > - > - if (!index) > - return ZERO_SIZE_PTR; > - > return kmalloc_node_trace( > kmalloc_caches[kmalloc_type(flags)][index], > flags, node, size);