24 Jun, 2020

1 commit

  • The kernel code instrumentation in stackleak gcc plugin works in two stages.
    At first, stack tracking is added to GIMPLE representation of every function
    (except some special cases). And later, when stack frame size info is
    available, stack tracking is removed from the RTL representation of the
    functions with small stack frame. There is an unwanted side-effect for these
    functions: some of them do useless work with caller-saved registers.

    As an example of such case, proc_sys_write without() instrumentation:
    55 push %rbp
    41 b8 01 00 00 00 mov $0x1,%r8d
    48 89 e5 mov %rsp,%rbp
    e8 11 ff ff ff callq ffffffff81284610
    5d pop %rbp
    c3 retq
    0f 1f 44 00 00 nopl 0x0(%rax,%rax,1)
    66 2e 0f 1f 84 00 00 nopw %cs:0x0(%rax,%rax,1)
    00 00 00

    proc_sys_write() with instrumentation:
    55 push %rbp
    48 89 e5 mov %rsp,%rbp
    41 56 push %r14
    41 55 push %r13
    41 54 push %r12
    53 push %rbx
    49 89 f4 mov %rsi,%r12
    48 89 fb mov %rdi,%rbx
    49 89 d5 mov %rdx,%r13
    49 89 ce mov %rcx,%r14
    4c 89 f1 mov %r14,%rcx
    4c 89 ea mov %r13,%rdx
    4c 89 e6 mov %r12,%rsi
    48 89 df mov %rbx,%rdi
    41 b8 01 00 00 00 mov $0x1,%r8d
    e8 f2 fe ff ff callq ffffffff81298e80
    5b pop %rbx
    41 5c pop %r12
    41 5d pop %r13
    41 5e pop %r14
    5d pop %rbp
    c3 retq
    66 0f 1f 84 00 00 00 nopw 0x0(%rax,%rax,1)
    00 00

    Let's improve the instrumentation to avoid this:

    1. Make stackleak_track_stack() save all register that it works with.
    Use no_caller_saved_registers attribute for that function. This attribute
    is available for x86_64 and i386 starting from gcc-7.

    2. Insert calling stackleak_track_stack() in asm:
    asm volatile("call stackleak_track_stack" :: "r" (current_stack_pointer))
    Here we use ASM_CALL_CONSTRAINT trick from arch/x86/include/asm/asm.h.
    The input constraint is taken into account during gcc shrink-wrapping
    optimization. It is needed to be sure that stackleak_track_stack() call is
    inserted after the prologue of the containing function, when the stack
    frame is prepared.

    This work is a deep reengineering of the idea described on grsecurity blog
    https://grsecurity.net/resolving_an_unfortunate_stackleak_interaction

    Signed-off-by: Alexander Popov
    Acked-by: Miguel Ojeda
    Link: https://lore.kernel.org/r/20200624123330.83226-5-alex.popov@linux.com
    Signed-off-by: Kees Cook

    Alexander Popov
     

05 Mar, 2019

1 commit

  • This adjusts structleak to also work with non-struct types when they
    are passed by reference, since those variables may leak just like
    anything else. This is exposed via an improved set of Kconfig options.
    (This does mean structleak is slightly misnamed now.)

    Building with CONFIG_GCC_PLUGIN_STRUCTLEAK_BYREF_ALL should give the
    kernel complete initialization coverage of all stack variables passed
    by reference, including padding (see lib/test_stackinit.c).

    Using CONFIG_GCC_PLUGIN_STRUCTLEAK_VERBOSE to count added initializations
    under defconfig:

    ..._BYREF: 5945 added initializations
    ..._BYREF_ALL: 16606 added initializations

    There is virtually no change to text+data size (both have less than 0.05%
    growth):

    text data bss dec hex filename
    19502103 5051456 1917000 26470559 193e89f vmlinux.stock
    19513412 5051456 1908808 26473676 193f4cc vmlinux.byref
    19516974 5047360 1900616 26464950 193d2b6 vmlinux.byref_all

    The measured performance difference is in the noise for hackbench and
    kernel build benchmarks:

    Stock:

    5x hackbench -g 20 -l 1000
    Mean: 10.649s
    Std Dev: 0.339

    5x kernel build (4-way parallel)
    Mean: 261.98s
    Std Dev: 1.53

    CONFIG_GCC_PLUGIN_STRUCTLEAK_BYREF:

    5x hackbench -g 20 -l 1000
    Mean: 10.540s
    Std Dev: 0.233

    5x kernel build (4-way parallel)
    Mean: 260.52s
    Std Dev: 1.31

    CONFIG_GCC_PLUGIN_STRUCTLEAK_BYREF_ALL:

    5x hackbench -g 20 -l 1000
    Mean: 10.320
    Std Dev: 0.413

    5x kernel build (4-way parallel)
    Mean: 260.10
    Std Dev: 0.86

    This does not yet solve missing padding initialization for structures
    on the stack that are never passed by reference (which should be a tiny
    minority). Hopefully this will be more easily addressed by upstream
    compiler fixes after clarifying the C11 padding initialization
    specification.

    Signed-off-by: Kees Cook
    Reviewed-by: Ard Biesheuvel

    Kees Cook
     

30 Dec, 2018

1 commit

  • Pull Kbuild updates from Masahiro Yamada:
    "Kbuild core:
    - remove unneeded $(call cc-option,...) switches
    - consolidate Clang compiler flags into CLANG_FLAGS
    - announce the deprecation of SUBDIRS
    - fix single target build for external module
    - simplify the dependencies of 'prepare' stage targets
    - allow fixdep to directly write to .*.cmd files
    - simplify dependency generation for CONFIG_TRIM_UNUSED_KSYMS
    - change if_changed_rule to accept multi-line recipe
    - move .SECONDARY special target to scripts/Kbuild.include
    - remove redundant 'set -e'
    - improve parallel execution for CONFIG_HEADERS_CHECK
    - misc cleanups

    Treewide fixes and cleanups
    - set Clang flags correctly for PowerPC boot images
    - fix UML build error with CONFIG_GCC_PLUGINS
    - remove unneeded patterns from .gitignore files
    - refactor firmware/Makefile
    - remove unneeded rules for *offsets.s
    - avoid unneeded regeneration of intermediate .s files
    - clean up ./Kbuild

    Modpost:
    - remove unused -M, -K options
    - fix false positive warnings about section mismatch
    - use simple devtable lookup instead of linker magic
    - misc cleanups

    Coccinelle:
    - relax boolinit.cocci checks for overall consistency
    - fix warning messages of boolinit.cocci

    Other tools:
    - improve -dirty check of scripts/setlocalversion
    - add a tool to generate compile_commands.json from .*.cmd files"

    * tag 'kbuild-v4.21' of git://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild: (51 commits)
    kbuild: remove unused cmd_gentimeconst
    kbuild: remove $(obj)/ prefixes in ./Kbuild
    treewide: add intermediate .s files to targets
    treewide: remove explicit rules for *offsets.s
    firmware: refactor firmware/Makefile
    firmware: remove unnecessary patterns from .gitignore
    scripts: remove unnecessary ihex2fw and check-lc_ctypes from .gitignore
    um: remove unused filechk_gen_header in Makefile
    scripts: add a tool to produce a compile_commands.json file
    kbuild: add -Werror=implicit-int flag unconditionally
    kbuild: add -Werror=strict-prototypes flag unconditionally
    kbuild: add -fno-PIE flag unconditionally
    scripts: coccinelle: Correct warning message
    scripts: coccinelle: only suggest true/false in files that already use them
    kbuild: handle part-of-module correctly for *.ll and *.symtypes
    kbuild: refactor part-of-module
    kbuild: refactor quiet_modtag
    kbuild: remove redundant quiet_modtag for $(obj-m)
    kbuild: refactor Makefile.asm-generic
    user/Makefile: Fix typo and capitalization in comment section
    ...

    Linus Torvalds
     

13 Dec, 2018

1 commit

  • On ARM, we currently only change the value of the stack canary when
    switching tasks if the kernel was built for UP. On SMP kernels, this
    is impossible since the stack canary value is obtained via a global
    symbol reference, which means
    a) all running tasks on all CPUs must use the same value
    b) we can only modify the value when no kernel stack frames are live
    on any CPU, which is effectively never.

    So instead, use a GCC plugin to add a RTL pass that replaces each
    reference to the address of the __stack_chk_guard symbol with an
    expression that produces the address of the 'stack_canary' field
    that is added to struct thread_info. This way, each task will use
    its own randomized value.

    Cc: Russell King
    Cc: Kees Cook
    Cc: Emese Revfy
    Cc: Arnd Bergmann
    Cc: Laura Abbott
    Cc: kernel-hardening@lists.openwall.com
    Acked-by: Nicolas Pitre
    Signed-off-by: Ard Biesheuvel
    Signed-off-by: Kees Cook

    Ard Biesheuvel
     

01 Dec, 2018

1 commit


05 Sep, 2018

1 commit

  • The STACKLEAK feature erases the kernel stack before returning from
    syscalls. That reduces the information which kernel stack leak bugs can
    reveal and blocks some uninitialized stack variable attacks.

    This commit introduces the STACKLEAK gcc plugin. It is needed for
    tracking the lowest border of the kernel stack, which is important
    for the code erasing the used part of the kernel stack at the end
    of syscalls (comes in a separate commit).

    The STACKLEAK feature is ported from grsecurity/PaX. More information at:
    https://grsecurity.net/
    https://pax.grsecurity.net/

    This code is modified from Brad Spengler/PaX Team's code in the last
    public patch of grsecurity/PaX based on our understanding of the code.
    Changes or omissions from the original code are ours and don't reflect
    the original grsecurity/PaX code.

    Signed-off-by: Alexander Popov
    Tested-by: Laura Abbott
    Signed-off-by: Kees Cook

    Alexander Popov
     

25 Jul, 2018

1 commit

  • The layout of Makefile.gcc-plugins had uneven tabs, and the long names
    of things made this file a bit hard to quickly visually parse. This
    breaks lines and moves options to the same tab depth. While we're at
    it, this also adds some comments about the various sections.

    Signed-off-by: Kees Cook

    Kees Cook
     

03 Jul, 2018

1 commit


11 Jun, 2018

3 commits

  • Run scripts/gcc-plugin.sh from Kconfig so that users can enable
    GCC_PLUGINS only when the compiler supports building plugins.

    Kconfig defines a new symbol, PLUGIN_HOSTCC. This will contain
    the compiler (g++ or gcc) used for building plugins, or empty
    if the plugin can not be supported at all.

    This allows us to remove all ugly testing in Makefile.gcc-plugins.

    Signed-off-by: Masahiro Yamada
    Acked-by: Kees Cook

    Masahiro Yamada
     
  • For PowerPC, GCC 5.2 is the requirement for GCC plugins. Move the
    version check to Kconfig so that the GCC plugin menus will be hidden
    if an older compiler is in use.

    Signed-off-by: Masahiro Yamada
    Acked-by: Andrew Donnellan
    Reviewed-by: Kees Cook

    Masahiro Yamada
     
  • As Documentation/kbuild/kconfig-language.txt notes, 'select' should be
    be used with care - it forces a lower limit of another symbol, ignoring
    the dependency. Currently, KCOV can select GCC_PLUGINS even if arch
    does not select HAVE_GCC_PLUGINS. This could cause the unmet direct
    dependency.

    Now that Kconfig can test compiler capability, let's handle this in a
    more sophisticated way.

    There are two ways to enable KCOV; use the compiler that natively
    supports -fsanitize-coverage=trace-pc, or build the SANCOV plugin if
    the compiler has ability to build GCC plugins. Hence, the correct
    dependency for KCOV is:

    depends on CC_HAS_SANCOV_TRACE_PC || GCC_PLUGINS

    You do not need to build the SANCOV plugin if the compiler already
    supports -fsanitize-coverage=trace-pc. Hence, the select should be:

    select GCC_PLUGIN_SANCOV if !CC_HAS_SANCOV_TRACE_PC

    With this, GCC_PLUGIN_SANCOV is selected only when necessary, so
    scripts/Makefile.gcc-plugins can be cleaner.

    I also cleaned up Kconfig and scripts/Makefile.kcov as well.

    Signed-off-by: Masahiro Yamada
    Reviewed-by: Kees Cook

    Masahiro Yamada
     

05 May, 2018

1 commit

  • Since commit d677a4d60193 ("Makefile: support flag
    -fsanitizer-coverage=trace-cmp"), you miss to build the SANCOV
    plugin under some circumstances.

    CONFIG_KCOV=y
    CONFIG_KCOV_ENABLE_COMPARISONS=y
    Your compiler does not support -fsanitize-coverage=trace-pc
    Your compiler does not support -fsanitize-coverage=trace-cmp

    Under this condition, $(CFLAGS_KCOV) is not empty but contains a
    space, so the following ifeq-conditional is false.

    ifeq ($(CFLAGS_KCOV),)

    Then, scripts/Makefile.gcc-plugins misses to add sancov_plugin.so to
    gcc-plugin-y while the SANCOV plugin is necessary as an alternative
    means.

    Fixes: d677a4d60193 ("Makefile: support flag -fsanitizer-coverage=trace-cmp")
    Signed-off-by: Masahiro Yamada
    Acked-by: Kees Cook

    Masahiro Yamada
     

02 Nov, 2017

1 commit

  • Many source files in the tree are missing licensing information, which
    makes it harder for compliance tools to determine the correct license.

    By default all files without license information are under the default
    license of the kernel, which is GPL version 2.

    Update the files which contain no license information with the 'GPL-2.0'
    SPDX license identifier. The SPDX identifier is a legally binding
    shorthand, which can be used instead of the full boiler plate text.

    This patch is based on work done by Thomas Gleixner and Kate Stewart and
    Philippe Ombredanne.

    How this work was done:

    Patches were generated and checked against linux-4.14-rc6 for a subset of
    the use cases:
    - file had no licensing information it it.
    - file was a */uapi/* one with no licensing information in it,
    - file was a */uapi/* one with existing licensing information,

    Further patches will be generated in subsequent months to fix up cases
    where non-standard license headers were used, and references to license
    had to be inferred by heuristics based on keywords.

    The analysis to determine which SPDX License Identifier to be applied to
    a file was done in a spreadsheet of side by side results from of the
    output of two independent scanners (ScanCode & Windriver) producing SPDX
    tag:value files created by Philippe Ombredanne. Philippe prepared the
    base worksheet, and did an initial spot review of a few 1000 files.

    The 4.13 kernel was the starting point of the analysis with 60,537 files
    assessed. Kate Stewart did a file by file comparison of the scanner
    results in the spreadsheet to determine which SPDX license identifier(s)
    to be applied to the file. She confirmed any determination that was not
    immediately clear with lawyers working with the Linux Foundation.

    Criteria used to select files for SPDX license identifier tagging was:
    - Files considered eligible had to be source code files.
    - Make and config files were included as candidates if they contained >5
    lines of source
    - File already had some variant of a license header in it (even if
    Reviewed-by: Philippe Ombredanne
    Reviewed-by: Thomas Gleixner
    Signed-off-by: Greg Kroah-Hartman

    Greg Kroah-Hartman
     

08 Aug, 2017

1 commit

  • In the Linux kernel, struct type variables are rarely passed by-value,
    and so functions that initialize such variables typically take an input
    reference to the variable rather than returning a value that can
    subsequently be used in an assignment.

    If the initalization function is not part of the same compilation unit,
    the lack of an assignment operation defeats any analysis the compiler
    can perform as to whether the variable may be used before having been
    initialized. This means we may end up passing on such variables
    uninitialized, resulting in potential information leaks.

    So extend the existing structleak GCC plugin so it will [optionally]
    apply to all struct type variables that have their address taken at any
    point, rather than only to variables of struct types that have a __user
    annotation.

    Signed-off-by: Ard Biesheuvel
    Signed-off-by: Kees Cook

    Ard Biesheuvel
     

23 Jun, 2017

1 commit

  • This randstruct plugin is modified from Brad Spengler/PaX Team's code
    in the last public patch of grsecurity/PaX based on my understanding
    of the code. Changes or omissions from the original code are mine and
    don't reflect the original grsecurity/PaX code.

    The randstruct GCC plugin randomizes the layout of selected structures
    at compile time, as a probabilistic defense against attacks that need to
    know the layout of structures within the kernel. This is most useful for
    "in-house" kernel builds where neither the randomization seed nor other
    build artifacts are made available to an attacker. While less useful for
    distribution kernels (where the randomization seed must be exposed for
    third party kernel module builds), it still has some value there since now
    all kernel builds would need to be tracked by an attacker.

    In more performance sensitive scenarios, GCC_PLUGIN_RANDSTRUCT_PERFORMANCE
    can be selected to make a best effort to restrict randomization to
    cacheline-sized groups of elements, and will not randomize bitfields. This
    comes at the cost of reduced randomization.

    Two annotations are defined,__randomize_layout and __no_randomize_layout,
    which respectively tell the plugin to either randomize or not to
    randomize instances of the struct in question. Follow-on patches enable
    the auto-detection logic for selecting structures for randomization
    that contain only function pointers. It is disabled here to assist with
    bisection.

    Since any randomized structs must be initialized using designated
    initializers, __randomize_layout includes the __designated_init annotation
    even when the plugin is disabled so that all builds will require
    the needed initialization. (With the plugin enabled, annotations for
    automatically chosen structures are marked as well.)

    The main differences between this implemenation and grsecurity are:
    - disable automatic struct selection (to be enabled in follow-up patch)
    - add designated_init attribute at runtime and for manual marking
    - clarify debugging output to differentiate bad cast warnings
    - add whitelisting infrastructure
    - support gcc 7's DECL_ALIGN and DECL_MODE changes (Laura Abbott)
    - raise minimum required GCC version to 4.7

    Earlier versions of this patch series were ported by Michael Leibowitz.

    Signed-off-by: Kees Cook

    Kees Cook
     

23 Feb, 2017

1 commit

  • Pull powerpc updates from Michael Ellerman:
    "Highlights include:

    - Support for direct mapped LPC on POWER9, giving Linux direct access
    to devices that may be on there such as a UART.

    - Memory hotplug support for the Power9 Radix MMU.

    - Add new AUX vectors describing the processor's cache geometry, to
    be used by glibc.

    - The ability for a guest to ask the hypervisor to resize the guest's
    hash table, and in addition support for doing so automatically when
    memory is hotplugged into/out-of the guest. This allows the hash
    table to be sized based on the current memory usage of the guest,
    rather than the maximum possible memory usage.

    - Implementation of optprobes (kprobe optimisation) for powerpc.

    In addition there's the topic branch shared with the KVM tree, which
    includes support for guests to use the Radix MMU on Power9.

    Thanks to:
    Alistair Popple, Andrew Donnellan, Aneesh Kumar K.V, Anju T, Anton
    Blanchard, Benjamin Herrenschmidt, Chris Packham, Daniel Axtens,
    Daniel Borkmann, David Gibson, Finn Thain, Gautham R. Shenoy, Gavin
    Shan, Greg Kurz, Joel Stanley, John Allen, Madhavan Srinivasan,
    Mahesh Salgaonkar, Markus Elfring, Michael Neuling, Nathan Fontenot,
    Naveen N. Rao, Nicholas Piggin, Paul Mackerras, Ravi Bangoria, Reza
    Arbab, Shailendra Singh, Vaibhav Jain, Wei Yongjun"

    * tag 'powerpc-4.11-1' of git://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux: (129 commits)
    powerpc/mm/radix: Skip ptesync in pte update helpers
    powerpc/mm/radix: Use ptep_get_and_clear_full when clearing pte for full mm
    powerpc/mm/radix: Update pte update sequence for pte clear case
    powerpc/mm: Update PROTFAULT handling in the page fault path
    powerpc/xmon: Fix data-breakpoint
    powerpc/mm: Fix build break with BOOK3S_64=n and MEMORY_HOTPLUG=y
    powerpc/mm: Fix build break when CMA=n && SPAPR_TCE_IOMMU=y
    powerpc/mm: Fix build break with RADIX=y & HUGETLBFS=n
    powerpc/pseries: Fix typo in parameter description
    powerpc/kprobes: Remove kprobe_exceptions_notify()
    kprobes: Introduce weak variant of kprobe_exceptions_notify()
    powerpc/ftrace: Fix confusing help text for DISABLE_MPROFILE_KERNEL
    powerpc/powernv: Fix opal_exit tracepoint opcode
    powerpc: Add a prototype for mcount() so it can be versioned
    powerpc: Drop GPL from of_node_to_nid() export to match other arches
    powerpc/kprobes: Optimize kprobe in kretprobe_trampoline()
    powerpc/kprobes: Implement Optprobes
    powerpc/kprobes: Fixes for kprobe_lookup_name() on BE
    powerpc: Add helper to check if offset is within relative branch range
    powerpc/bpf: Introduce __PPC_SH64()
    ...

    Linus Torvalds
     

03 Feb, 2017

2 commits

  • Enable support for GCC plugins on powerpc.

    Add an additional version check in gcc-plugins-check to advise users to
    upgrade to gcc 5.2+ on powerpc to avoid issues with header files (gcc
    Acked-by: Kees Cook
    Signed-off-by: Michael Ellerman

    Andrew Donnellan
     
  • The variable DISABLE_LATENT_ENTROPY_PLUGIN is defined when
    CONFIG_PAX_LATENT_ENTROPY is set. This is leftover from the original PaX
    version of the plugin code and doesn't actually exist. Change the condition
    to depend on CONFIG_GCC_PLUGIN_LATENT_ENTROPY instead.

    Fixes: 38addce8b600 ("gcc-plugins: Add latent_entropy plugin")
    Signed-off-by: Andrew Donnellan
    Signed-off-by: Michael Ellerman

    Andrew Donnellan
     

19 Jan, 2017

1 commit

  • This plugin detects any structures that contain __user attributes and
    makes sure it is being fully initialized so that a specific class of
    information exposure is eliminated. (This plugin was originally designed
    to block the exposure of siginfo in CVE-2013-2141.)

    Ported from grsecurity/PaX. This version adds a verbose option to the
    plugin and the Kconfig.

    Signed-off-by: Kees Cook

    Kees Cook
     

11 Oct, 2016

1 commit

  • This adds a new gcc plugin named "latent_entropy". It is designed to
    extract as much possible uncertainty from a running system at boot time as
    possible, hoping to capitalize on any possible variation in CPU operation
    (due to runtime data differences, hardware differences, SMP ordering,
    thermal timing variation, cache behavior, etc).

    At the very least, this plugin is a much more comprehensive example for
    how to manipulate kernel code using the gcc plugin internals.

    The need for very-early boot entropy tends to be very architecture or
    system design specific, so this plugin is more suited for those sorts
    of special cases. The existing kernel RNG already attempts to extract
    entropy from reliable runtime variation, but this plugin takes the idea to
    a logical extreme by permuting a global variable based on any variation
    in code execution (e.g. a different value (and permutation function)
    is used to permute the global based on loop count, case statement,
    if/then/else branching, etc).

    To do this, the plugin starts by inserting a local variable in every
    marked function. The plugin then adds logic so that the value of this
    variable is modified by randomly chosen operations (add, xor and rol) and
    random values (gcc generates separate static values for each location at
    compile time and also injects the stack pointer at runtime). The resulting
    value depends on the control flow path (e.g., loops and branches taken).

    Before the function returns, the plugin mixes this local variable into
    the latent_entropy global variable. The value of this global variable
    is added to the kernel entropy pool in do_one_initcall() and _do_fork(),
    though it does not credit any bytes of entropy to the pool; the contents
    of the global are just used to mix the pool.

    Additionally, the plugin can pre-initialize arrays with build-time
    random contents, so that two different kernel builds running on identical
    hardware will not have the same starting values.

    Signed-off-by: Emese Revfy
    [kees: expanded commit message and code comments]
    Signed-off-by: Kees Cook

    Emese Revfy
     

09 Aug, 2016

3 commits


08 Jun, 2016

3 commits

  • The sancov gcc plugin inserts a __sanitizer_cov_trace_pc() call
    at the start of basic blocks.

    This plugin is a helper plugin for the kcov feature. It supports
    all gcc versions with plugin support (from gcc-4.5 on).
    It is based on the gcc commit "Add fuzzing coverage support" by Dmitry Vyukov
    (https://gcc.gnu.org/viewcvs/gcc?limit_changes=0&view=revision&revision=231296).

    Signed-off-by: Emese Revfy
    Acked-by: Kees Cook
    Signed-off-by: Michal Marek

    Emese Revfy
     
  • Add a very simple plugin to demonstrate the GCC plugin infrastructure. This GCC
    plugin computes the cyclomatic complexity of each function.

    The complexity M of a function's control flow graph is defined as:
    M = E - N + 2P
    where
    E = the number of edges
    N = the number of nodes
    P = the number of connected components (exit nodes).

    Signed-off-by: Emese Revfy
    Acked-by: Kees Cook
    Signed-off-by: Michal Marek

    Emese Revfy
     
  • This patch allows to build the whole kernel with GCC plugins. It was ported from
    grsecurity/PaX. The infrastructure supports building out-of-tree modules and
    building in a separate directory. Cross-compilation is supported too.
    Currently the x86, arm, arm64 and uml architectures enable plugins.

    The directory of the gcc plugins is scripts/gcc-plugins. You can use a file or a directory
    there. The plugins compile with these options:
    * -fno-rtti: gcc is compiled with this option so the plugins must use it too
    * -fno-exceptions: this is inherited from gcc too
    * -fasynchronous-unwind-tables: this is inherited from gcc too
    * -ggdb: it is useful for debugging a plugin (better backtrace on internal
    errors)
    * -Wno-narrowing: to suppress warnings from gcc headers (ipa-utils.h)
    * -Wno-unused-variable: to suppress warnings from gcc headers (gcc_version
    variable, plugin-version.h)

    The infrastructure introduces a new Makefile target called gcc-plugins. It
    supports all gcc versions from 4.5 to 6.0. The scripts/gcc-plugin.sh script
    chooses the proper host compiler (gcc-4.7 can be built by either gcc or g++).
    This script also checks the availability of the included headers in
    scripts/gcc-plugins/gcc-common.h.

    The gcc-common.h header contains frequently included headers for GCC plugins
    and it has a compatibility layer for the supported gcc versions.

    The gcc-generate-*-pass.h headers automatically generate the registration
    structures for GIMPLE, SIMPLE_IPA, IPA and RTL passes.

    Note that 'make clean' keeps the *.so files (only the distclean or mrproper
    targets clean all) because they are needed for out-of-tree modules.

    Based on work created by the PaX Team.

    Signed-off-by: Emese Revfy
    Acked-by: Kees Cook
    Signed-off-by: Michal Marek

    Emese Revfy