Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2670731rwd; Wed, 17 May 2023 12:45:38 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4h/4oyvkO3zs8qampzE06JnpGJkupB5bq1T73uix5FjiwRzBgCoE92iIe6zYBDH/v8fsQe X-Received: by 2002:a05:6a20:1584:b0:101:e4f3:5336 with SMTP id h4-20020a056a20158400b00101e4f35336mr38531397pzj.27.1684352737884; Wed, 17 May 2023 12:45:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684352737; cv=none; d=google.com; s=arc-20160816; b=LXjRJQxYWgFiEOHXg1v5BNHNrFlxLjgNV2fz448iAHlzg2S2OJDy3dEoANwO/QEbeh D05DplFC2J5ixKKzzIAw2ezmsC5HrOscOeQfIwm2ZAuPzgqv4htuBccgi/oXDVl2r8mW RnkYsAmiIzZFJf9brjkGuO1Fk3S/E+r62+dZ9SmbVvb0LivvxXQhg9R8Rdp8kxM5OIPY 7j6lzk5hBdBypvqoC/HOwurI/+vm8vp7X67sz7Jh8Ug13ZrjKEBAJcDDtjiNOnqGuMWW KZNjCM0TffbgfkZe+PDbB7t8AAMrgowc8tfjTjc1t6lCmq61bYIdfLBZmEl+xEU8UE3+ kwVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=ro4MFeYmls7u4z+A5TU6NmNeVFukxp8+WxRlKc+qKfw=; b=g2zK3LuWGCEP8JujKU1e/DvFi+LPTN1MyvmQ8brBuG6CFmlUJH5rQYDXzvljo6yVi8 7jPvGObblQ5JPhk25gUvJUGLRFNk1SMdDcTwyAdeFQDIPVQ31u/ec1ZKEf8sIT/LS/Ku xR9G1+2MYyligKZg/SaT0ofSnQv7UW4Nybpc1mF/cugiJ8vWilT5Zc6s7shs5KGfNEMb 6SRiAXqZ2ue3PVORreH/PfAH5H4KK6PCLccKLM7qsIF/VPc+0rfMasorI7BT+Vl6UTvJ wurQUlI/y4Nu07q0LkuGUyO+zgT08wbZjg66I5nEHedQmwxU0NsusMXZlzHJ//fR36Rl LcHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=YUk0CCY0; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d84-20020a621d57000000b00645e8c9e27esi288748pfd.386.2023.05.17.12.45.19; Wed, 17 May 2023 12:45:37 -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=@kernel.org header.s=k20201202 header.b=YUk0CCY0; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229556AbjEQTmr (ORCPT + 99 others); Wed, 17 May 2023 15:42:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60994 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229555AbjEQTmp (ORCPT ); Wed, 17 May 2023 15:42:45 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6EC87271B; Wed, 17 May 2023 12:42:40 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 04DA164AB5; Wed, 17 May 2023 19:42:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 32FC7C433EF; Wed, 17 May 2023 19:42:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1684352559; bh=afhI056VdXNOr9ugoqlRkd2TTFxvYYZ/gycL5eBOWXo=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=YUk0CCY0gbbYh1ILW9Y80BGNdCD8aVom443ZRnGmZp6gHYNPGY6nOHSGOpla7z3F9 FX9QzNm1UO338vsjPE3LzzQXej6dglBW2R84lzV4DTBxdQkz0Et7RCXC0qKiPYdPlf HfvPeqswFlXmM1yds8VtHBJ3N3Vn/a9k9D1Wli6O1Krl8QukSEk/G3ytVknfQePcE7 rtskS3VCbqX9mAtS68eeWWlCUldNzRclks28YB/JkBc2qdUqsVvfLhHjywQDTQPkOF YjjV5YA5oVefQJmQCS8/HqkJaA4lnWkRWJWCDlyQ28TbENhnLICK+oU13yd1ToTWfp Zv/FDKcHY6OOw== Date: Wed, 17 May 2023 13:43:28 -0600 From: "Gustavo A. R. Silva" To: Kees Cook Cc: Miguel Ojeda , Bill Wendling , Qing Zhao , Nick Desaulniers , Nathan Chancellor , Tom Rix , llvm@lists.linux.dev, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH v2] Compiler Attributes: Add __counted_by macro Message-ID: References: <20230517190841.gonna.796-kees@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230517190841.gonna.796-kees@kernel.org> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 Wed, May 17, 2023 at 12:08:44PM -0700, Kees Cook wrote: > In an effort to annotate all flexible array members with their run-time > size information, the "element_count" attribute is being introduced by > Clang[1] and GCC[2] in future releases. This annotation will provide > the CONFIG_UBSAN_BOUNDS and CONFIG_FORTIFY_SOURCE features the ability > to perform run-time bounds checking on otherwise unknown-size flexible > arrays. > > Even though the attribute is under development, we can start the > annotation process in the kernel. This requires defining a macro for > it, even if we have to change the name of the actual attribute later. > Since it is likely that this attribute may change its name to "counted_by" > in the future (to better align with a future total bytes "sized_by" > attribute), name the wrapper macro "__counted_by", which also reads more > clearly (and concisely) in structure definitions. > > [1] https://reviews.llvm.org/D148381 > [2] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108896 > > Cc: Miguel Ojeda > Cc: Bill Wendling > Cc: Qing Zhao > Cc: Gustavo A. R. Silva > Cc: Nick Desaulniers > Cc: Nathan Chancellor > Cc: Tom Rix > Cc: llvm@lists.linux.dev > Signed-off-by: Kees Cook Reviewed-by: Gustavo A. R. Silva Thanks -- Gustavo > --- > v2: - update "Optional" comments > v1: https://lore.kernel.org/all/20230504181636.never.222-kees@kernel.org/ > --- > include/linux/compiler_attributes.h | 13 +++++++++++++ > 1 file changed, 13 insertions(+) > > diff --git a/include/linux/compiler_attributes.h b/include/linux/compiler_attributes.h > index e659cb6fded3..a92d8887e8f0 100644 > --- a/include/linux/compiler_attributes.h > +++ b/include/linux/compiler_attributes.h > @@ -123,6 +123,19 @@ > # define __designated_init > #endif > > +/* > + * Optional: only supported since gcc >= 14 > + * Optional: only supported since clang >= 17 > + * > + * gcc: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108896 > + * clang: https://reviews.llvm.org/D148381 > + */ > +#if __has_attribute(__element_count__) > +# define __counted_by(member) __attribute__((__element_count__(member))) > +#else > +# define __counted_by(member) > +#endif > + > /* > * Optional: only supported since clang >= 14.0 > * > -- > 2.34.1 >