All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kees Cook <keescook@chromium.org>
To: Brad Spengler <spender@grsecurity.net>
Cc: Josh Triplett <josh@joshtriplett.org>,
	PaX Team <pageexec@freemail.hu>, Emese Revfy <re.emese@gmail.com>,
	kernel-hardening@lists.openwall.com
Subject: [kernel-hardening] [PATCH] randstruct: Use -Werror=designated-init
Date: Wed, 1 Feb 2017 12:23:47 -0800	[thread overview]
Message-ID: <20170201202347.GA75273@beast> (raw)

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

                 reply	other threads:[~2017-02-01 20:23 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170201202347.GA75273@beast \
    --to=keescook@chromium.org \
    --cc=josh@joshtriplett.org \
    --cc=kernel-hardening@lists.openwall.com \
    --cc=pageexec@freemail.hu \
    --cc=re.emese@gmail.com \
    --cc=spender@grsecurity.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.