All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kees Cook <keescook@chromium.org>
To: kernel-hardening@lists.openwall.com
Cc: Kees Cook <keescook@chromium.org>,
	Bob Moore <robert.moore@intel.com>, Lv Zheng <lv.zheng@intel.com>,
	"Rafael J . Wysocki" <rafael.j.wysocki@intel.com>,
	Laura Abbott <labbott@redhat.com>,
	x86@kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v2 20/20] ACPICA: Use designated initializers
Date: Fri, 26 May 2017 13:17:24 -0700	[thread overview]
Message-ID: <1495829844-69341-21-git-send-email-keescook@chromium.org> (raw)
In-Reply-To: <1495829844-69341-1-git-send-email-keescook@chromium.org>

The struct layout randomization plugin detects and randomizes any structs
that contain only function pointers. Once layout is randomized, all
initialization must be designated or the compiler will misalign the
assignments. This switches all the ACPICA function pointer struct to
use designated initializers, using the proposed upstream ACPICA macro:
https://github.com/acpica/acpica/pull/248/

Cc: Bob Moore <robert.moore@intel.com>
Cc: Lv Zheng <lv.zheng@intel.com>
Cc: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Signed-off-by: Kees Cook <keescook@chromium.org>
---
 drivers/acpi/acpica/hwxfsleep.c               | 14 +++++++++-----
 include/acpi/platform/acenv.h                 |  4 ++++
 include/acpi/platform/aclinux.h               |  2 ++
 scripts/gcc-plugins/randomize_layout_plugin.c |  4 ----
 4 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/drivers/acpi/acpica/hwxfsleep.c b/drivers/acpi/acpica/hwxfsleep.c
index 5733b1167e46..558fe4cdf29a 100644
--- a/drivers/acpi/acpica/hwxfsleep.c
+++ b/drivers/acpi/acpica/hwxfsleep.c
@@ -70,11 +70,15 @@ static acpi_status acpi_hw_sleep_dispatch(u8 sleep_state, u32 function_id);
 /* Legacy functions are optional, based upon ACPI_REDUCED_HARDWARE */
 
 static struct acpi_sleep_functions acpi_sleep_dispatch[] = {
-	{ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
-	 acpi_hw_extended_sleep},
-	{ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
-	 acpi_hw_extended_wake_prep},
-	{ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake), acpi_hw_extended_wake}
+	{ACPI_STRUCT_INIT (legacy_function,
+			   ACPI_HW_OPTIONAL_FUNCTION (acpi_hw_legacy_sleep)),
+	 ACPI_STRUCT_INIT (extended_function, acpi_hw_extended_sleep) },
+	{ACPI_STRUCT_INIT (legacy_function,
+			   ACPI_HW_OPTIONAL_FUNCTION (acpi_hw_legacy_wake_prep)),
+	 ACPI_STRUCT_INIT (extended_function, acpi_hw_extended_wake_prep) },
+	{ACPI_STRUCT_INIT (legacy_function,
+			   ACPI_HW_OPTIONAL_FUNCTION (acpi_hw_legacy_wake)),
+	 ACPI_STRUCT_INIT (extended_function, acpi_hw_extended_wake) }
 };
 
 /*
diff --git a/include/acpi/platform/acenv.h b/include/acpi/platform/acenv.h
index 09994b063243..912563c66948 100644
--- a/include/acpi/platform/acenv.h
+++ b/include/acpi/platform/acenv.h
@@ -382,4 +382,8 @@
 #define ACPI_INIT_FUNCTION
 #endif
 
+#ifndef ACPI_STRUCT_INIT
+#define ACPI_STRUCT_INIT(field, value) value
+#endif
+
 #endif				/* __ACENV_H__ */
diff --git a/include/acpi/platform/aclinux.h b/include/acpi/platform/aclinux.h
index a39e3f67616f..047f13865608 100644
--- a/include/acpi/platform/aclinux.h
+++ b/include/acpi/platform/aclinux.h
@@ -178,6 +178,8 @@
 #define ACPI_MSG_BIOS_ERROR     KERN_ERR "ACPI BIOS Error (bug): "
 #define ACPI_MSG_BIOS_WARNING   KERN_WARNING "ACPI BIOS Warning (bug): "
 
+#define ACPI_STRUCT_INIT(field, value)	.field = value
+
 #else				/* !__KERNEL__ */
 
 #define ACPI_USE_STANDARD_HEADERS
diff --git a/scripts/gcc-plugins/randomize_layout_plugin.c b/scripts/gcc-plugins/randomize_layout_plugin.c
index bb2c6789c4b7..e1526554487e 100644
--- a/scripts/gcc-plugins/randomize_layout_plugin.c
+++ b/scripts/gcc-plugins/randomize_layout_plugin.c
@@ -346,10 +346,6 @@ static int relayout_struct(tree type)
 	    !strcmp((const char *)ORIG_TYPE_NAME(type), "RAWPCIFACTORY"))
 		return 0;
 
-	/* Skip ACPICA structs until refreshed with designated_init. */
-	if (!strcmp((const char *)ORIG_TYPE_NAME(type), "acpi_sleep_functions"))
-		return 0;
-
 	/* throw out any structs in uapi */
 	xloc = expand_location(DECL_SOURCE_LOCATION(TYPE_FIELDS(type)));
 
-- 
2.7.4

WARNING: multiple messages have this Message-ID (diff)
From: Kees Cook <keescook@chromium.org>
To: kernel-hardening@lists.openwall.com
Cc: Kees Cook <keescook@chromium.org>,
	Bob Moore <robert.moore@intel.com>, Lv Zheng <lv.zheng@intel.com>,
	"Rafael J . Wysocki" <rafael.j.wysocki@intel.com>,
	Laura Abbott <labbott@redhat.com>,
	x86@kernel.org, linux-kernel@vger.kernel.org
Subject: [kernel-hardening] [PATCH v2 20/20] ACPICA: Use designated initializers
Date: Fri, 26 May 2017 13:17:24 -0700	[thread overview]
Message-ID: <1495829844-69341-21-git-send-email-keescook@chromium.org> (raw)
In-Reply-To: <1495829844-69341-1-git-send-email-keescook@chromium.org>

The struct layout randomization plugin detects and randomizes any structs
that contain only function pointers. Once layout is randomized, all
initialization must be designated or the compiler will misalign the
assignments. This switches all the ACPICA function pointer struct to
use designated initializers, using the proposed upstream ACPICA macro:
https://github.com/acpica/acpica/pull/248/

Cc: Bob Moore <robert.moore@intel.com>
Cc: Lv Zheng <lv.zheng@intel.com>
Cc: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Signed-off-by: Kees Cook <keescook@chromium.org>
---
 drivers/acpi/acpica/hwxfsleep.c               | 14 +++++++++-----
 include/acpi/platform/acenv.h                 |  4 ++++
 include/acpi/platform/aclinux.h               |  2 ++
 scripts/gcc-plugins/randomize_layout_plugin.c |  4 ----
 4 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/drivers/acpi/acpica/hwxfsleep.c b/drivers/acpi/acpica/hwxfsleep.c
index 5733b1167e46..558fe4cdf29a 100644
--- a/drivers/acpi/acpica/hwxfsleep.c
+++ b/drivers/acpi/acpica/hwxfsleep.c
@@ -70,11 +70,15 @@ static acpi_status acpi_hw_sleep_dispatch(u8 sleep_state, u32 function_id);
 /* Legacy functions are optional, based upon ACPI_REDUCED_HARDWARE */
 
 static struct acpi_sleep_functions acpi_sleep_dispatch[] = {
-	{ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
-	 acpi_hw_extended_sleep},
-	{ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
-	 acpi_hw_extended_wake_prep},
-	{ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake), acpi_hw_extended_wake}
+	{ACPI_STRUCT_INIT (legacy_function,
+			   ACPI_HW_OPTIONAL_FUNCTION (acpi_hw_legacy_sleep)),
+	 ACPI_STRUCT_INIT (extended_function, acpi_hw_extended_sleep) },
+	{ACPI_STRUCT_INIT (legacy_function,
+			   ACPI_HW_OPTIONAL_FUNCTION (acpi_hw_legacy_wake_prep)),
+	 ACPI_STRUCT_INIT (extended_function, acpi_hw_extended_wake_prep) },
+	{ACPI_STRUCT_INIT (legacy_function,
+			   ACPI_HW_OPTIONAL_FUNCTION (acpi_hw_legacy_wake)),
+	 ACPI_STRUCT_INIT (extended_function, acpi_hw_extended_wake) }
 };
 
 /*
diff --git a/include/acpi/platform/acenv.h b/include/acpi/platform/acenv.h
index 09994b063243..912563c66948 100644
--- a/include/acpi/platform/acenv.h
+++ b/include/acpi/platform/acenv.h
@@ -382,4 +382,8 @@
 #define ACPI_INIT_FUNCTION
 #endif
 
+#ifndef ACPI_STRUCT_INIT
+#define ACPI_STRUCT_INIT(field, value) value
+#endif
+
 #endif				/* __ACENV_H__ */
diff --git a/include/acpi/platform/aclinux.h b/include/acpi/platform/aclinux.h
index a39e3f67616f..047f13865608 100644
--- a/include/acpi/platform/aclinux.h
+++ b/include/acpi/platform/aclinux.h
@@ -178,6 +178,8 @@
 #define ACPI_MSG_BIOS_ERROR     KERN_ERR "ACPI BIOS Error (bug): "
 #define ACPI_MSG_BIOS_WARNING   KERN_WARNING "ACPI BIOS Warning (bug): "
 
+#define ACPI_STRUCT_INIT(field, value)	.field = value
+
 #else				/* !__KERNEL__ */
 
 #define ACPI_USE_STANDARD_HEADERS
diff --git a/scripts/gcc-plugins/randomize_layout_plugin.c b/scripts/gcc-plugins/randomize_layout_plugin.c
index bb2c6789c4b7..e1526554487e 100644
--- a/scripts/gcc-plugins/randomize_layout_plugin.c
+++ b/scripts/gcc-plugins/randomize_layout_plugin.c
@@ -346,10 +346,6 @@ static int relayout_struct(tree type)
 	    !strcmp((const char *)ORIG_TYPE_NAME(type), "RAWPCIFACTORY"))
 		return 0;
 
-	/* Skip ACPICA structs until refreshed with designated_init. */
-	if (!strcmp((const char *)ORIG_TYPE_NAME(type), "acpi_sleep_functions"))
-		return 0;
-
 	/* throw out any structs in uapi */
 	xloc = expand_location(DECL_SOURCE_LOCATION(TYPE_FIELDS(type)));
 
-- 
2.7.4

  parent reply	other threads:[~2017-05-27  1:13 UTC|newest]

Thread overview: 116+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-26 20:17 [PATCH v2 00/20] Introduce struct layout randomization plugin Kees Cook
2017-05-26 20:17 ` [kernel-hardening] " Kees Cook
2017-05-26 20:17 ` [PATCH v2 01/20] NFS: Avoid cross-structure casting Kees Cook
2017-05-26 20:17   ` [kernel-hardening] " Kees Cook
2017-05-28  7:53   ` Christoph Hellwig
2017-05-28  7:53     ` [kernel-hardening] " Christoph Hellwig
2017-05-28 16:55     ` Kees Cook
2017-05-28 16:55       ` [kernel-hardening] " Kees Cook
2017-05-26 20:17 ` [PATCH v2 02/20] gcc-plugins: Detail c-common.h location for GCC 4.6 Kees Cook
2017-05-26 20:17   ` [kernel-hardening] " Kees Cook
2017-05-26 20:17 ` [PATCH v2 03/20] compiler: Add __designated_init annotation Kees Cook
2017-05-26 20:17   ` [kernel-hardening] " Kees Cook
2017-05-26 20:17 ` [PATCH v2 04/20] gcc-plugins: Add the randstruct plugin Kees Cook
2017-05-26 20:17   ` [kernel-hardening] " Kees Cook
2017-06-29 22:08   ` Arnd Bergmann
2017-06-29 22:08     ` [kernel-hardening] " Arnd Bergmann
2017-06-29 22:53     ` Kees Cook
2017-06-29 22:53       ` [kernel-hardening] " Kees Cook
2017-06-30  0:04       ` Kees Cook
2017-06-30  0:04         ` [kernel-hardening] " Kees Cook
2017-06-30  7:35       ` Arnd Bergmann
2017-06-30  7:35         ` [kernel-hardening] " Arnd Bergmann
2017-06-30  7:55         ` Ard Biesheuvel
2017-06-30  7:55           ` [kernel-hardening] " Ard Biesheuvel
2017-06-30  8:27           ` Arnd Bergmann
2017-06-30  8:27             ` [kernel-hardening] " Arnd Bergmann
2017-06-30 14:41             ` Kees Cook
2017-06-30 14:41               ` [kernel-hardening] " Kees Cook
2017-06-30 15:22               ` Arnd Bergmann
2017-06-30 15:22                 ` [kernel-hardening] " Arnd Bergmann
2017-05-26 20:17 ` [PATCH v2 05/20] randstruct: Whitelist struct security_hook_heads cast Kees Cook
2017-05-26 20:17   ` [kernel-hardening] " Kees Cook
2017-05-27  8:41   ` Christoph Hellwig
2017-05-27  8:41     ` [kernel-hardening] " Christoph Hellwig
2017-05-27 20:09     ` Kees Cook
2017-05-27 20:09       ` [kernel-hardening] " Kees Cook
2017-05-27 20:09       ` Kees Cook
2017-05-27 22:04       ` Tetsuo Handa
2017-05-27 22:04         ` [kernel-hardening] " Tetsuo Handa
2017-05-27 22:04         ` Tetsuo Handa
2017-05-28  0:43         ` [kernel-hardening] " Kees Cook
2017-05-28  0:43           ` Kees Cook
2017-05-28  0:43           ` Kees Cook
2017-05-30 10:34       ` James Morris
2017-05-30 10:34         ` [kernel-hardening] " James Morris
2017-05-30 10:34         ` James Morris
2017-05-26 20:17 ` [PATCH v2 06/20] randstruct: Whitelist UNIXCB cast Kees Cook
2017-05-26 20:17   ` [kernel-hardening] " Kees Cook
2017-05-26 20:20   ` Kees Cook
2017-05-26 20:20     ` [kernel-hardening] " Kees Cook
2017-05-28  7:56   ` Christoph Hellwig
2017-05-28  7:56     ` [kernel-hardening] " Christoph Hellwig
2017-05-26 20:17 ` [PATCH v2 07/20] randstruct: Whitelist big_key path struct overloading Kees Cook
2017-05-26 20:17   ` [kernel-hardening] " Kees Cook
2017-05-28  8:12   ` Christoph Hellwig
2017-05-28  8:12     ` [kernel-hardening] " Christoph Hellwig
2017-05-28 16:59     ` Kees Cook
2017-05-28 16:59       ` [kernel-hardening] " Kees Cook
2017-06-19 19:24       ` Kees Cook
2017-06-19 19:24         ` [kernel-hardening] " Kees Cook
2017-09-07  7:20         ` Christoph Hellwig
2017-09-07  7:20           ` [kernel-hardening] " Christoph Hellwig
2017-09-07 22:55           ` Kees Cook
2017-09-07 22:55             ` [kernel-hardening] " Kees Cook
2017-05-26 20:17 ` [PATCH v2 08/20] randstruct: Whitelist NIU struct page overloading Kees Cook
2017-05-26 20:17   ` [kernel-hardening] " Kees Cook
2017-05-28  8:15   ` Christoph Hellwig
2017-05-28  8:15     ` [kernel-hardening] " Christoph Hellwig
2017-05-28 17:35     ` Kees Cook
2017-05-28 17:35       ` [kernel-hardening] " Kees Cook
2017-05-28 17:35       ` Kees Cook
2017-05-28 17:37     ` Kees Cook
2017-05-28 17:37       ` [kernel-hardening] " Kees Cook
2017-05-28 17:37       ` Kees Cook
2017-05-26 20:17 ` [PATCH v2 09/20] randstruct: Mark various structs for randomization Kees Cook
2017-05-26 20:17   ` [kernel-hardening] " Kees Cook
2017-05-26 20:17 ` [PATCH v2 10/20] randstruct: opt-out externally exposed function pointer structs Kees Cook
2017-05-26 20:17   ` [kernel-hardening] " Kees Cook
2017-05-26 20:17 ` [PATCH v2 11/20] randstruct: Disable randomization of ACPICA structs Kees Cook
2017-05-26 20:17   ` [kernel-hardening] " Kees Cook
2017-05-27  8:42   ` Christoph Hellwig
2017-05-27  8:42     ` [kernel-hardening] " Christoph Hellwig
2017-05-27 20:03     ` Kees Cook
2017-05-27 20:03       ` [kernel-hardening] " Kees Cook
2017-05-28  4:55       ` Christoph Hellwig
2017-05-28  4:55         ` [kernel-hardening] " Christoph Hellwig
2017-05-26 20:17 ` [PATCH v2 12/20] sgi-xp: Use designated initializers Kees Cook
2017-05-26 20:17   ` [kernel-hardening] " Kees Cook
2017-05-27  8:44   ` Christoph Hellwig
2017-05-27  8:44     ` [kernel-hardening] " Christoph Hellwig
2017-05-26 20:17 ` [PATCH v2 13/20] drm/amdgpu: " Kees Cook
2017-05-26 20:17   ` [kernel-hardening] " Kees Cook
2017-05-26 20:17 ` [PATCH v2 14/20] drm/amd/powerplay: " Kees Cook
2017-05-26 20:17   ` [kernel-hardening] " Kees Cook
2017-05-27  8:47   ` Christoph Hellwig
2017-05-27  8:47     ` [kernel-hardening] " Christoph Hellwig
2017-05-27 20:10     ` Kees Cook
2017-05-27 20:10       ` [kernel-hardening] " Kees Cook
2017-05-26 20:17 ` [PATCH v2 15/20] mtk-vcodec: " Kees Cook
2017-05-26 20:17   ` [kernel-hardening] " Kees Cook
2017-05-26 20:17 ` [PATCH v2 16/20] ntfs: Use ERR_CAST() to avoid cross-structure cast Kees Cook
2017-05-26 20:17   ` [kernel-hardening] " Kees Cook
2017-05-26 20:17 ` [PATCH v2 17/20] ocfs2: " Kees Cook
2017-05-26 20:17   ` [kernel-hardening] " Kees Cook
2017-05-26 20:17 ` [PATCH v2 18/20] randstruct: Enable function pointer struct detection Kees Cook
2017-05-26 20:17   ` [kernel-hardening] " Kees Cook
2017-05-26 20:17 ` [PATCH v2 19/20] [RFC] task_struct: Allow randomized layout Kees Cook
2017-05-26 20:17   ` [kernel-hardening] " Kees Cook
2017-05-26 20:23   ` Linus Torvalds
2017-05-26 20:23     ` [kernel-hardening] " Linus Torvalds
2017-05-26 20:32     ` Kees Cook
2017-05-26 20:32       ` [kernel-hardening] " Kees Cook
2017-05-26 20:17 ` Kees Cook [this message]
2017-05-26 20:17   ` [kernel-hardening] [PATCH v2 20/20] ACPICA: Use designated initializers Kees Cook
2017-05-28  7:45   ` Christoph Hellwig
2017-05-28  7:45     ` [kernel-hardening] " Christoph Hellwig

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=1495829844-69341-21-git-send-email-keescook@chromium.org \
    --to=keescook@chromium.org \
    --cc=kernel-hardening@lists.openwall.com \
    --cc=labbott@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lv.zheng@intel.com \
    --cc=rafael.j.wysocki@intel.com \
    --cc=robert.moore@intel.com \
    --cc=x86@kernel.org \
    /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.