* [kernel-hardening] [PATCH] randstruct: Use -Werror=designated-init
@ 2017-02-01 20:23 Kees Cook
0 siblings, 0 replies; only message in thread
From: Kees Cook @ 2017-02-01 20:23 UTC (permalink / raw)
To: Brad Spengler; +Cc: Josh Triplett, PaX Team, Emese Revfy, kernel-hardening
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(+)
diff --git a/Makefile b/Makefile
index f21d750fa022..1f94aba409b5 100644
--- a/Makefile
+++ b/Makefile
@@ -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)
diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h
index 3ae2773b0498..fc411495e534 100644
--- a/include/linux/compiler-gcc.h
+++ b/include/linux/compiler-gcc.h
@@ -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
diff --git a/scripts/gcc-plugins/randomize_layout_plugin.c b/scripts/gcc-plugins/randomize_layout_plugin.c
index 1f62fabc1141..9e314e4d9162 100644
--- a/scripts/gcc-plugins/randomize_layout_plugin.c
+++ b/scripts/gcc-plugins/randomize_layout_plugin.c
@@ -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));
}
--
2.7.4
--
Kees Cook
Pixel Security
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2017-02-01 20:23 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-01 20:23 [kernel-hardening] [PATCH] randstruct: Use -Werror=designated-init 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.