All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] overflow: Clarify expectations for getting DEFINE_FLEX variable sizes
@ 2025-04-16 17:29 Kees Cook
  2025-04-16 17:37 ` Gustavo A. R. Silva
  2025-04-16 19:29 ` Kees Cook
  0 siblings, 2 replies; 3+ messages in thread
From: Kees Cook @ 2025-04-16 17:29 UTC (permalink / raw)
  To: Gustavo A. R. Silva; +Cc: Kees Cook, linux-hardening, linux-kernel

Mention the use of __member_size() for DEFINE_FLEX variables as a hint
for getting at the compile-time size of the resulting flexible array
member.

Signed-off-by: Kees Cook <kees@kernel.org>
---
Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org>
Cc: linux-hardening@vger.kernel.org
---
 include/linux/overflow.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/include/linux/overflow.h b/include/linux/overflow.h
index 0c7e3dcfe867..6ee67c20b575 100644
--- a/include/linux/overflow.h
+++ b/include/linux/overflow.h
@@ -419,6 +419,7 @@ static inline size_t __must_check size_sub(size_t minuend, size_t subtrahend)
  * Define a zeroed, on-stack, instance of @type structure with a trailing
  * flexible array member.
  * Use __struct_size(@name) to get compile-time size of it afterwards.
+ * Use __member_size(@name->member) to get compile-time size of @name members.
  */
 #define DEFINE_RAW_FLEX(type, name, member, count)	\
 	_DEFINE_FLEX(type, name, member, count, = {})
@@ -436,6 +437,7 @@ static inline size_t __must_check size_sub(size_t minuend, size_t subtrahend)
  * Define a zeroed, on-stack, instance of @TYPE structure with a trailing
  * flexible array member.
  * Use __struct_size(@NAME) to get compile-time size of it afterwards.
+ * Use __member_size(@NAME->member) to get compile-time size of @NAME members.
  */
 #define DEFINE_FLEX(TYPE, NAME, MEMBER, COUNTER, COUNT)	\
 	_DEFINE_FLEX(TYPE, NAME, MEMBER, COUNT, = { .obj.COUNTER = COUNT, })
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-04-16 19:29 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-16 17:29 [PATCH] overflow: Clarify expectations for getting DEFINE_FLEX variable sizes Kees Cook
2025-04-16 17:37 ` Gustavo A. R. Silva
2025-04-16 19:29 ` Kees Cook

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.