[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <7AB970A3-883F-49A4-BBCD-23E2CD1E869C@kernel.org>
Date: Mon, 04 Sep 2023 20:55:29 -0700
From: Kees Cook <kees@...nel.org>
To: Przemek Kitszel <przemyslaw.kitszel@...el.com>,
netdev@...r.kernel.org
CC: Kees Cook <keescook@...omium.org>,
Jacob Keller <jacob.e.keller@...el.com>,
intel-wired-lan@...ts.osuosl.org,
Alexander Lobakin <aleksander.lobakin@...el.com>,
linux-hardening@...r.kernel.org, Steven Zou <steven.zou@...el.com>,
Jakub Kicinski <kuba@...nel.org>,
Anthony Nguyen <anthony.l.nguyen@...el.com>,
David Laight <David.Laight@...LAB.COM>
Subject: Re: [RFC net-next v4 1/7] overflow: add DEFINE_FLEX() for on-stack allocs
On September 4, 2023 5:31:01 AM PDT, Przemek Kitszel <przemyslaw.kitszel@...el.com> wrote:
> [...]
>+/**
>+ * _DEFINE_FLEX() - helper macro for DEFINE_FLEX() family.
>+ * Enables caller macro to pass (different) initializer.
>+ *
>+ * @type: structure type name, including "struct" keyword.
>+ * @name: Name for a variable to define.
>+ * @member: Name of the array member.
>+ * @count: Number of elements in the array; must be compile-time const.
>+ * @initializer: initializer expression (could be empty for no init).
>+ */
>+#define _DEFINE_FLEX(type, name, member, count, initializer) \
>+ _Static_assert(__builtin_constant_p(count), \
>+ "onstack flex array members require compile-time const count"); \
>+ union { \
>+ u8 bytes[struct_size_t(type, member, count)]; \
>+ type obj; \
>+ } name##_u initializer; \
>+ type *name = (type *)&name##_u
Yeah, I like this! This will make it easy to add __counted_by initializers when we have the need in the future.
--
Kees Cook
Powered by blists - more mailing lists