[<prev] [next>] [day] [month] [year] [list]
Message-ID: <aFDIBBeYgRSx1ekO@kspp>
Date: Mon, 16 Jun 2025 19:42:28 -0600
From: "Gustavo A. R. Silva" <gustavoars@...nel.org>
To: Kees Cook <kees@...nel.org>
Cc: linux-kernel@...r.kernel.org,
"Gustavo A. R. Silva" <gustavoars@...nel.org>,
linux-hardening@...r.kernel.org
Subject: [PATCH][next] stddef: Introduce TRAILING_OVERLAP() helper macro
Add new TRAILING_OVERLAP() helper macro to create a union between
a flexible-array member (FAM) in a struct and a set of additional
members that would otherwise follow it.
Co-developed-by: Kees Cook <kees@...nel.org>
Signed-off-by: Kees Cook <kees@...nel.org>
Signed-off-by: Gustavo A. R. Silva <gustavoars@...nel.org>
---
include/linux/stddef.h | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/include/linux/stddef.h b/include/linux/stddef.h
index 929d67710cc5..635513ff2829 100644
--- a/include/linux/stddef.h
+++ b/include/linux/stddef.h
@@ -93,4 +93,24 @@ enum {
#define DECLARE_FLEX_ARRAY(TYPE, NAME) \
__DECLARE_FLEX_ARRAY(TYPE, NAME)
+/**
+ * TRAILING_OVERLAP() - Overlap a flexible-array member with trailing members.
+ *
+ * Creates a union between a flexible-array member (FAM) in a struct and a set
+ * of additional members that would otherwise follow it.
+ *
+ * @TYPE: Flexible structure type name, including "struct" keyword.
+ * @NAME: Name for a variable to define.
+ * @FAM: The flexible-array member within @TYPE
+ * @MEMBERS: Trailing overlapping members.
+ */
+#define TRAILING_OVERLAP(TYPE, NAME, FAM, MEMBERS) \
+ union { \
+ TYPE NAME; \
+ struct { \
+ unsigned char __offset_to_fam[offsetof(TYPE, FAM)]; \
+ MEMBERS \
+ }; \
+ }
+
#endif
--
2.43.0
Powered by blists - more mailing lists