Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp1811932rwb; Thu, 29 Sep 2022 02:33:47 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7F07aJ0PFQArJyZDEsjqNO02fhS4ojdc3DCrqHoCrSlkpqyMbUlJlJqlPTq5m8gj5YUcYI X-Received: by 2002:a17:907:608f:b0:787:a1ae:1d3b with SMTP id ht15-20020a170907608f00b00787a1ae1d3bmr1921180ejc.431.1664444027073; Thu, 29 Sep 2022 02:33:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664444027; cv=none; d=google.com; s=arc-20160816; b=aFvgF0pHcyB84+UFpsnWjrXLoXBpnh8ptLQW+8772PjFVztRdtV8Xlj10lgVJPrLOE AmCVGWYdZQ55RsB0DWq0r3YyMpVlrYhJ//8GQCVTkpR00rDdYisfJxldpWSWsHf4/dpi P7TiYT14ErrI+25Q7Z05+NyXxNa8AyBIma4d8AXmfYak0XXVSOvfGbdHaTt/zummtGsG DyRrCQVV8BKkWnsPm4QLTv40XU2CaDO4hM0nFIRYLEScPrvlx9JDUmnfzq6nrAWJWpQ/ lPCGQkMngH20CKiTwMrh9QmPxK01kB52h/GglwCiU6PF8U0LJ2LNhsruYXeWZ/12cT/+ WnSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:dkim-signature:dkim-signature; bh=i1u8z4WmR9zvDM9UGZ0h0jsxTnAaUNDEIhFM4nyq/PM=; b=dbr9p5ATCQSOO9GSoh5vrFt7L6VFR6qQO72Be3J9o0MbxX7gzOq8jcGTP4dvUtmccH LffoEsKSKPPrj/fj3w0aU6Um4ijM5Of1/UN3oAVEb8IPOdNt2JPAihmAMS402jCz7hKj TpZCvqgC/YfwhRDNi3H3fXRqd1UACH4KRovYePU/XS86Kye1rX4zVBouh+B2wYdYMeAM bzR09u7getMffkQOjPxYwJUUYcEQC3f9AHtvwDO0qUHoV8oPqoXKFWi06ha7W4qQnumW bSQZogK/4nTg7ybrKwa9q2FukIk/3WgPQ0At3SOF6l9zAqOCUNbD+a3IOZ9E1Sw+ctP3 Evyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=pSTH0nuX; dkim=neutral (no key) header.i=@suse.cz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id mp14-20020a1709071b0e00b007879f5efba7si3696695ejc.872.2022.09.29.02.33.21; Thu, 29 Sep 2022 02:33:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=pSTH0nuX; dkim=neutral (no key) header.i=@suse.cz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235683AbiI2JPC (ORCPT + 99 others); Thu, 29 Sep 2022 05:15:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43924 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235197AbiI2JOw (ORCPT ); Thu, 29 Sep 2022 05:14:52 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E2043B85D; Thu, 29 Sep 2022 02:14:49 -0700 (PDT) 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-out1.suse.de (Postfix) with ESMTPS id 5E51421CB1; Thu, 29 Sep 2022 09:14:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1664442888; 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=i1u8z4WmR9zvDM9UGZ0h0jsxTnAaUNDEIhFM4nyq/PM=; b=pSTH0nuXGokqjtwOc1Njlcdjqhl3KZN82uo0aaMtdAnQh9KDLOmHiHAMvFBOLV4PYjbuRO aL16iAi4Oc3JoQkx7iay2MszmfEjL9ZHcesPa/FCL8X/pZBlLC2riFRgV9XH/shGsSOT6O 2362irwz5VzSGBz2DCZ73j+c+pWIAvI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1664442888; 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=i1u8z4WmR9zvDM9UGZ0h0jsxTnAaUNDEIhFM4nyq/PM=; b=6BtohXscIn2X7OHJ3UG1L7/Pz/2sL4WtXKuVPUfV03r1kEuJZnKjhOIxIVOSPC5oSsvxFM LTlIDKMHwrMXJVDA== 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 1996A1348E; Thu, 29 Sep 2022 09:14:48 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id Aq94BQhiNWOpMAAAMHmgww (envelope-from ); Thu, 29 Sep 2022 09:14:48 +0000 Message-ID: <0eb638e3-b9ac-6dec-6881-b885c7874b45@suse.cz> Date: Thu, 29 Sep 2022 11:14:47 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.3.0 Subject: Re: [PATCH] compiler_types.h: Test for __alloc_size__ again To: Kees Cook Cc: Miguel Ojeda , Nick Desaulniers , Andrew Morton , Yonghong Song , Hao Luo , Marco Elver , Geert Uytterhoeven , Alexei Starovoitov , Kumar Kartikeya Dwivedi , Rasmus Villemoes , linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org References: <20220929081642.1932200-1-keescook@chromium.org> Content-Language: en-US From: Vlastimil Babka In-Reply-To: <20220929081642.1932200-1-keescook@chromium.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-8.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 9/29/22 10:16, Kees Cook wrote: > While the "alloc_size" attribute is available on all GCC versions, I > forgot that it gets disabled explicitly by the kernel in GCC < 9.1 due > to misbehaviors. Add a note to the compiler_attributes.h entry for it, > and restore the #ifdef in compiler_types.h. > > Cc: Vlastimil Babka > Cc: Miguel Ojeda > Cc: Nick Desaulniers > Cc: Andrew Morton > Cc: Yonghong Song > Cc: Hao Luo > Cc: Marco Elver > Reported-by: Geert Uytterhoeven > Link: https://lore.kernel.org/lkml/CAMuHMdXK+UN1YVZm9DenuXAM8hZRUZJwp=SXsueP7sWiVU3a9A@mail.gmail.com > Fixes: 63caa04ec60583b1 ("slab: Remove __malloc attribute from realloc functions") > Signed-off-by: Kees Cook Thanks, I decided to late squash it so we don't needlessly cause issues for people doing bisections with gcc-8 later. > --- > I swear I sent this earlier today, but I don't see it on lore still. Resending, > so apologies if this is a duplicate. > --- > include/linux/compiler_attributes.h | 3 ++- > include/linux/compiler_types.h | 9 +++++++-- > 2 files changed, 9 insertions(+), 3 deletions(-) > > diff --git a/include/linux/compiler_attributes.h b/include/linux/compiler_attributes.h > index 465be5f072ff..55fbb6091ecf 100644 > --- a/include/linux/compiler_attributes.h > +++ b/include/linux/compiler_attributes.h > @@ -65,7 +65,8 @@ > > /* > * Note: do not use this directly. Instead, use __alloc_size() since it is conditionally > - * available and includes other attributes. > + * available and includes other attributes. For GCC < 9.1, __alloc_size__ gets undefined > + * in compiler-gcc.h, due to misbehaviors. > * > * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-alloc_005fsize-function-attribute > * clang: https://clang.llvm.org/docs/AttributeReference.html#alloc-size > diff --git a/include/linux/compiler_types.h b/include/linux/compiler_types.h > index f141a6f6b9f6..0717534f8364 100644 > --- a/include/linux/compiler_types.h > +++ b/include/linux/compiler_types.h > @@ -275,8 +275,13 @@ struct ftrace_likely_data { > * be performing a _reallocation_, as that may alias the existing pointer. > * For these, use __realloc_size(). > */ > -#define __alloc_size(x, ...) __alloc_size__(x, ## __VA_ARGS__) __malloc > -#define __realloc_size(x, ...) __alloc_size__(x, ## __VA_ARGS__) > +#ifdef __alloc_size__ > +# define __alloc_size(x, ...) __alloc_size__(x, ## __VA_ARGS__) __malloc > +# define __realloc_size(x, ...) __alloc_size__(x, ## __VA_ARGS__) > +#else > +# define __alloc_size(x, ...) __malloc > +# define __realloc_size(x, ...) > +#endif > > #ifndef asm_volatile_goto > #define asm_volatile_goto(x...) asm goto(x)