From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B574231F1D for ; Wed, 17 May 2023 19:42:39 +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> Precedence: bulk X-Mailing-List: llvm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230517190841.gonna.796-kees@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 >