@@ -781,6 +781,9 @@ KBUILD_CFLAGS += $(call cc-option,-Werror=date-time)
# enforce correct pointer usage
KBUILD_CFLAGS += $(call cc-option,-Werror=incompatible-pointer-types)
+# Require designated initializers for all marked structures
+KBUILD_CFLAGS += $(call cc-option,-Werror=designated-init)
+
# use the deterministic mode of AR if available
KBUILD_ARFLAGS := $(call ar-option,D)
@@ -197,6 +197,8 @@
#ifdef RANDSTRUCT_PLUGIN
#define __randomize_layout __attribute__((randomize_layout))
#define __no_randomize_layout __attribute__((no_randomize_layout))
+#else
+#define __randomize_layout __attribute__((designated_init))
#endif
#ifdef CONSTIFY_PLUGIN
@@ -377,6 +377,7 @@ static int relayout_struct(tree type)
TYPE_FIELDS(variant) = list;
TYPE_ATTRIBUTES(variant) = copy_list(TYPE_ATTRIBUTES(variant));
TYPE_ATTRIBUTES(variant) = tree_cons(get_identifier("randomize_performed"), NULL_TREE, TYPE_ATTRIBUTES(variant));
+ TYPE_ATTRIBUTES(variant) = tree_cons(get_identifier("designated_init"), NULL_TREE, TYPE_ATTRIBUTES(variant));
if (has_flexarray)
TYPE_ATTRIBUTES(type) = tree_cons(get_identifier("has_flexarray"), NULL_TREE, TYPE_ATTRIBUTES(type));
}
GCC 5.1 and later supports -Werror=designated-init, which can be used with randstruct to locate places where designated initializers are missing. Suggested-by: Josh Triplett <josh@joshtriplett.org> Signed-off-by: Kees Cook <keescook@chromium.org> --- Makefile | 3 +++ include/linux/compiler-gcc.h | 2 ++ scripts/gcc-plugins/randomize_layout_plugin.c | 1 + 3 files changed, 6 insertions(+)