• Sandipan Das's avatar
    include/linux/compiler-clang.h: handle randomizable anonymous structs · 75e63076
    Sandipan Das authored
    commit 4ca59b14 upstream.
    
    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.
    
    Link: http://lkml.kernel.org/r/20171109064645.25581-1-sandipan@linux.vnet.ibm.comSigned-off-by: default avatarSandipan Das <sandipan@linux.vnet.ibm.com>
    Cc: David Rientjes <rientjes@google.com>
    Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
    Cc: Kate Stewart <kstewart@linuxfoundation.org>
    Cc: Thomas Gleixner <tglx@linutronix.de>
    Cc: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
    Cc: Alexei Starovoitov <ast@fb.com>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
    Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
    75e63076
Name
Last commit
Last update
Documentation Loading commit data...
arch Loading commit data...
block Loading commit data...
certs Loading commit data...
crypto Loading commit data...
drivers Loading commit data...
firmware Loading commit data...
fs Loading commit data...
include Loading commit data...
init Loading commit data...
ipc Loading commit data...
kernel Loading commit data...
lib Loading commit data...
mm Loading commit data...
net Loading commit data...
samples Loading commit data...
scripts Loading commit data...
security Loading commit data...
sound Loading commit data...
tools Loading commit data...
usr Loading commit data...
virt Loading commit data...
.cocciconfig Loading commit data...
.get_maintainer.ignore Loading commit data...
.gitattributes Loading commit data...
.gitignore Loading commit data...
.mailmap Loading commit data...
COPYING Loading commit data...
CREDITS Loading commit data...
Kbuild Loading commit data...
Kconfig Loading commit data...
MAINTAINERS Loading commit data...
Makefile Loading commit data...
README Loading commit data...