From: Sandipan Das <sandipan@linux.vnet.ibm.com>
To: rientjes@google.com, akpm@linux-foundation.org,
gregkh@linuxfoundation.org, kstewart@linuxfoundation.org,
tglx@linutronix.de
Cc: linux-kernel@vger.kernel.org, naveen.n.rao@linux.vnet.ibm.com,
ast@fb.com
Subject: [PATCH] compiler, clang: handle randomizable anonymous structs
Date: Thu, 9 Nov 2017 12:16:45 +0530 [thread overview]
Message-ID: <20171109064645.25581-1-sandipan@linux.vnet.ibm.com> (raw)
The GCC randomize layout plugin can randomize the member
offsets of sensitive kernel data structures. To use this
feature, certain annotations and members are added to the
structures which affect the member offsets even if this
plugin is not used.
All of these structures are completely randomized, except
for task_struct which leaves out some of its members. All
the other members are wrapped within an anonymous struct
with the __randomize_layout attribute. This is done using
the randomized_struct_fields_start and
randomized_struct_fields_end defines. When the plugin is
disabled, the behaviour of this attribute can vary based
on the GCC version. For GCC 5.1+, this attribute maps to
__designated_init otherwise it is just an empty define
but the anonymous structure is still present. For other
compilers, both randomized_struct_fields_start and
randomized_struct_fields_end default to empty defines
meaning the anonymous structure is not introduced at all.
So, if a module compiled with Clang, such as a BPF program,
needs to access task_struct fields such as pid and comm,
the offsets of these members as recognized by Clang are
different from those recognized by modules compiled with
GCC. If GCC 4.6+ is used to build the kernel, this can be
solved by introducing appropriate defines for Clang so
that the anonymous structure is seen when determining the
offsets for the members.
Signed-off-by: Sandipan Das <sandipan@linux.vnet.ibm.com>
---
include/linux/compiler-clang.h | 3 +++
1 file changed, 3 insertions(+)
diff --git a/include/linux/compiler-clang.h b/include/linux/compiler-clang.h
index 54dfef70a072..780b1242bf24 100644
--- a/include/linux/compiler-clang.h
+++ b/include/linux/compiler-clang.h
@@ -16,3 +16,6 @@
* with any version that can compile the kernel
*/
#define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__)
+
+#define randomized_struct_fields_start struct {
+#define randomized_struct_fields_end };
--
2.13.6
next reply other threads:[~2017-11-09 6:46 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-09 6:46 Sandipan Das [this message]
2017-12-02 2:18 ` Alexei Starovoitov
2017-12-04 12:08 ` Greg KH
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=20171109064645.25581-1-sandipan@linux.vnet.ibm.com \
--to=sandipan@linux.vnet.ibm.com \
--cc=akpm@linux-foundation.org \
--cc=ast@fb.com \
--cc=gregkh@linuxfoundation.org \
--cc=kstewart@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=naveen.n.rao@linux.vnet.ibm.com \
--cc=rientjes@google.com \
--cc=tglx@linutronix.de \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®