• 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
..
acpi Loading commit data...
asm-generic Loading commit data...
clocksource Loading commit data...
crypto Loading commit data...
drm Loading commit data...
dt-bindings Loading commit data...
keys Loading commit data...
kvm Loading commit data...
linux Loading commit data...
math-emu Loading commit data...
media Loading commit data...
memory Loading commit data...
misc Loading commit data...
net Loading commit data...
pcmcia Loading commit data...
ras Loading commit data...
rdma Loading commit data...
scsi Loading commit data...
soc Loading commit data...
sound Loading commit data...
target Loading commit data...
trace Loading commit data...
uapi Loading commit data...
video Loading commit data...
xen Loading commit data...