summaryrefslogtreecommitdiff
path: root/include/linux
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2026-06-16 09:21:01 +0530
committerLinus Torvalds <torvalds@linux-foundation.org>2026-06-16 09:21:01 +0530
commit481329ec5b31d2c48ac6b8b703c8008133884c7e (patch)
tree406bb78e41609a198710f5e3d4880a5734a00aba /include/linux
parent673f72944dde6614a56b37a61c6097f584c90ce6 (diff)
parent122b52f0bab007ebeb414c8280c1def17b9ed1f4 (diff)
downloadlinux-481329ec5b31d2c48ac6b8b703c8008133884c7e.tar.gz
linux-481329ec5b31d2c48ac6b8b703c8008133884c7e.zip
Merge tag 'hardening-v7.2-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux
Pull hardening updates from Kees Cook: - lkdtm: - Add case to provoke a crash in EFI runtime services (Ard Biesheuvel) - add PPC_RADIX_TLBIEL test and missed isync (Sayali Patil) - stddef: Document designated initializer semantics for __TRAILING_OVERLAP() (Gustavo A. R. Silva) - strarray: drop redundant allocation, add __counted_by_ptr (Thorsten Blum) * tag 'hardening-v7.2-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux: lkdtm/powerpc: add PPC_RADIX_TLBIEL test for radix MCE validation lkdtm/powerpc: add isync after slbmte to enforce SLB update ordering lkdtm: Add case to provoke a crash in EFI runtime services lib/string_helpers: annotate struct strarray with __counted_by_ptr lib/string_helpers: drop redundant allocation in kasprintf_strarray MAINTAINERS: add kernel hardening keyword __counted_by_ptr stddef: Document designated initializer semantics for __TRAILING_OVERLAP()
Diffstat (limited to 'include/linux')
-rw-r--r--include/linux/stddef.h65
1 files changed, 65 insertions, 0 deletions
diff --git a/include/linux/stddef.h b/include/linux/stddef.h
index 80b6bfb944f0..e1851c50c89b 100644
--- a/include/linux/stddef.h
+++ b/include/linux/stddef.h
@@ -100,6 +100,71 @@ enum {
* Creates a union between a flexible-array member (FAM) in a struct and a set
* of additional members that would otherwise follow it.
*
+ * Beware that, as this helper encloses TYPE NAME and MEMBERS in the same
+ * union, designated initializers for MEMBERS may overwrite portions
+ * previously initialized through NAME.
+ *
+ * For example::
+ *
+ * struct flex {
+ * size_t count;
+ * u8 fam[];
+ * };
+ *
+ * struct composite {
+ * ...
+ * __TRAILING_OVERLAP(struct flex, flex, fam, __packed,
+ * u8 data;
+ * );
+ * } __packed;
+ *
+ * static struct composite comp = {
+ * .flex = {
+ * .count = 1,
+ * },
+ * .data = 2,
+ * };
+ *
+ * In the example above, .flex and .data initialize different views of the same
+ * union storage. Since .data is initialized last, it _may_ overwrite portions
+ * previously initialized through .flex, leading to .flex.count being zeroed
+ * out.
+ *
+ * A couple of alternatives are shown below.
+ *
+ * a) Initialize only one view of the overlapped storage and assign the rest
+ * at runtime::
+ *
+ * static struct composite comp = {
+ * .flex = {
+ * .count = 1,
+ * },
+ * };
+ *
+ * static void foo(void)
+ * {
+ * comp.data = 2;
+ * ...
+ * }
+ *
+ * b) Alternatively, replace designated initializers with runtime assignments::
+ *
+ * static void foo(void)
+ * {
+ * struct composite comp;
+ *
+ * comp.flex.count = 1;
+ * comp.data = 2;
+ * ...
+ * }
+ *
+ * Compiler Explorer test code: https://godbolt.org/z/voM4E36dT
+ *
+ * For another example of the above see commit 5e54510a9389 ("acpi: nfit:
+ * intel: avoid multiple -Wflex-array-member-not-at-end warnings")
+ *
+ * Link: https://git.kernel.org/linus/5e54510a9389caa9
+ *
* @TYPE: Flexible structure type name, including "struct" keyword.
* @NAME: Name for a variable to define.
* @FAM: The flexible-array member within @TYPE