From: "Gustavo A. R. Silva" <gustavo@embeddedor.com>
To: Kees Cook <keescook@chromium.org>, Jakub Kicinski <kuba@kernel.org>
Cc: "Gustavo A . R . Silva" <gustavoars@kernel.org>,
Rasmus Villemoes <linux@rasmusvillemoes.dk>,
Dan Williams <dan.j.williams@intel.com>,
Keith Packard <keithp@keithp.com>,
Miguel Ojeda <ojeda@kernel.org>,
Alexey Dobriyan <adobriyan@gmail.com>,
Dmitry Antipov <dmantipov@yandex.ru>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Paolo Abeni <pabeni@redhat.com>,
Nathan Chancellor <nathan@kernel.org>,
kernel test robot <lkp@intel.com>,
linux-kernel@vger.kernel.org, netdev@vger.kernel.org,
linux-hardening@vger.kernel.org
Subject: Re: [PATCH 1/2] stddef: Allow attributes to be used when creating flex arrays
Date: Fri, 9 Feb 2024 21:47:44 -0600 [thread overview]
Message-ID: <bb815cbf-c019-4328-9857-b53cba2dbdd4@embeddedor.com> (raw)
In-Reply-To: <20240210011643.1706285-1-keescook@chromium.org>
On 2/9/24 19:16, Kees Cook wrote:
> With the coming support for the __counted_by struct member attribute, we
> will need a way to add such annotations to the places where
> DECLARE_FLEX_ARRAY() is used. Introduce DECLARE_FLEX_ARRAY_ATTR() which
> takes a third argument: the attributes to apply to the flexible array.
>
> Cc: Gustavo A. R. Silva <gustavoars@kernel.org>
> Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
> Cc: Dan Williams <dan.j.williams@intel.com>
> Cc: Keith Packard <keithp@keithp.com>
> Cc: Miguel Ojeda <ojeda@kernel.org>
> Cc: Alexey Dobriyan <adobriyan@gmail.com>
> Cc: Dmitry Antipov <dmantipov@yandex.ru>
> Signed-off-by: Kees Cook <keescook@chromium.org>
Nice!
Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Thanks
--
Gustavo
> ---
> include/linux/stddef.h | 16 ++++++++++++++--
> include/uapi/linux/stddef.h | 25 +++++++++++++++++++------
> 2 files changed, 33 insertions(+), 8 deletions(-)
>
> diff --git a/include/linux/stddef.h b/include/linux/stddef.h
> index 929d67710cc5..eb51f6727ecf 100644
> --- a/include/linux/stddef.h
> +++ b/include/linux/stddef.h
> @@ -81,8 +81,20 @@ enum {
> __struct_group(TAG, NAME, /* no attrs */, MEMBERS)
>
> /**
> - * DECLARE_FLEX_ARRAY() - Declare a flexible array usable in a union
> + * DECLARE_FLEX_ARRAY_ATTR() - Declare a flexible array usable in a union
> + * @TYPE: The type of each flexible array element
> + * @NAME: The name of the flexible array member
> + * @ATTRS: The list of member attributes to apply
> *
> + * In order to have a flexible array member in a union or alone in a
> + * struct, it needs to be wrapped in an anonymous struct with at least 1
> + * named member, but that member can be empty.
> + */
> +#define DECLARE_FLEX_ARRAY_ATTR(TYPE, NAME, ATTRS) \
> + __DECLARE_FLEX_ARRAY_ATTR(TYPE, NAME, ATTRS)
> +
> +/**
> + * DECLARE_FLEX_ARRAY() - Declare a flexible array usable in a union
> * @TYPE: The type of each flexible array element
> * @NAME: The name of the flexible array member
> *
> @@ -91,6 +103,6 @@ enum {
> * named member, but that member can be empty.
> */
> #define DECLARE_FLEX_ARRAY(TYPE, NAME) \
> - __DECLARE_FLEX_ARRAY(TYPE, NAME)
> + DECLARE_FLEX_ARRAY_ATTR(TYPE, NAME, /* no attributes */)
>
> #endif
> diff --git a/include/uapi/linux/stddef.h b/include/uapi/linux/stddef.h
> index 2ec6f35cda32..5499c08ad011 100644
> --- a/include/uapi/linux/stddef.h
> +++ b/include/uapi/linux/stddef.h
> @@ -31,24 +31,37 @@
>
> #ifdef __cplusplus
> /* sizeof(struct{}) is 1 in C++, not 0, can't use C version of the macro. */
> -#define __DECLARE_FLEX_ARRAY(T, member) \
> - T member[0]
> +#define __DECLARE_FLEX_ARRAY_ATTR(TYPE, NAME, ATTRS) \
> + TYPE NAME[0] ATTRS
> +#define __DECLARE_FLEX_ARRAY(TYPE, NAME) \
> + __DECLARE_FLEX_ARRAY_ATTR(TYPE, NAME, /* no attributes */)
> #else
> /**
> - * __DECLARE_FLEX_ARRAY() - Declare a flexible array usable in a union
> - *
> + * __DECLARE_FLEX_ARRAY_ATTR() - Declare a flexible array usable in a union
> * @TYPE: The type of each flexible array element
> * @NAME: The name of the flexible array member
> + * @ATTRS: The list of member attributes to apply
> *
> * In order to have a flexible array member in a union or alone in a
> * struct, it needs to be wrapped in an anonymous struct with at least 1
> * named member, but that member can be empty.
> */
> -#define __DECLARE_FLEX_ARRAY(TYPE, NAME) \
> +#define __DECLARE_FLEX_ARRAY_ATTR(TYPE, NAME, ATTRS) \
> struct { \
> struct { } __empty_ ## NAME; \
> - TYPE NAME[]; \
> + TYPE NAME[] ATTRS; \
> }
> +/**
> + * __DECLARE_FLEX_ARRAY() - Declare a flexible array usable in a union
> + * @TYPE: The type of each flexible array element
> + * @NAME: The name of the flexible array member
> + *
> + * In order to have a flexible array member in a union or alone in a
> + * struct, it needs to be wrapped in an anonymous struct with at least 1
> + * named member, but that member can be empty.
> + */
> +#define __DECLARE_FLEX_ARRAY(TYPE, NAME) \
> + __DECLARE_FLEX_ARRAY_ATTR(TYPE, NAME, /* no attributes */)
> #endif
>
> #ifndef __counted_by
next prev parent reply other threads:[~2024-02-10 3:47 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-10 1:16 [PATCH 0/2] stddef: Allow attributes to be used when creating flex arrays Kees Cook
2024-02-10 1:16 ` [PATCH 1/2] " Kees Cook
2024-02-10 3:47 ` Gustavo A. R. Silva [this message]
2024-02-13 7:22 ` Rasmus Villemoes
2024-02-13 23:20 ` Kees Cook
2024-02-10 1:16 ` [PATCH 2/2] net/ipv4: Annotate imsf_slist_flex with __counted_by(imsf_numsrc) Kees Cook
2024-02-10 3:48 ` Gustavo A. R. Silva
2024-02-13 1:35 ` Jakub Kicinski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=bb815cbf-c019-4328-9857-b53cba2dbdd4@embeddedor.com \
--to=gustavo@embeddedor.com \
--cc=adobriyan@gmail.com \
--cc=dan.j.williams@intel.com \
--cc=davem@davemloft.net \
--cc=dmantipov@yandex.ru \
--cc=edumazet@google.com \
--cc=gustavoars@kernel.org \
--cc=keescook@chromium.org \
--cc=keithp@keithp.com \
--cc=kuba@kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@rasmusvillemoes.dk \
--cc=lkp@intel.com \
--cc=nathan@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=ojeda@kernel.org \
--cc=pabeni@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox