05 Sep, 2018

2 commits

  • commit b86729109c5fd0a480300f40608aac68764b5adf upstream.

    GCC 8 changed the order of some fields and is very picky about ordering
    in static initializers, so instead just move to dynamic initializers,
    and drop the redundant already-zero field assignments.

    Suggested-by: Valdis Kletnieks
    Signed-off-by: Kees Cook
    Cc: Lance Albertson
    Signed-off-by: Greg Kroah-Hartman

    Kees Cook
     
  • commit 80d172431696482d9acd8d2c4ea78fed8956e2a1 upstream.

    GCC requires another #include to get the gcc-plugins to build cleanly.

    Signed-off-by: Valdis Kletnieks
    Signed-off-by: Kees Cook
    Cc: Lance Albertson
    Signed-off-by: Greg Kroah-Hartman

    Valdis Kletnieks
     

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

2 commits

  • Kees Cook
     
  • 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
     

02 Aug, 2017

1 commit


23 Jun, 2017

5 commits

  • The NIU ethernet driver intentionally stores a page struct pointer on
    top of the "mapping" field. Whitelist this case:

    drivers/net/ethernet/sun/niu.c: In function ‘niu_rx_pkt_ignore’:
    drivers/net/ethernet/sun/niu.c:3402:10: note: found mismatched ssa struct pointer types: ‘struct page’ and ‘struct address_space’

    *link = (struct page *) page->mapping;
    ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    Cc: David S. Miller
    Signed-off-by: Kees Cook

    Kees Cook
     
  • The big_key payload structure intentionally stores a struct path in
    two void pointers to avoid header soup. Whitelist this case:

    security/keys/big_key.c: In function ‘big_key_read’:
    security/keys/big_key.c:293:16: note: found mismatched rhs struct pointer types: ‘struct path’ and ‘void *’

    struct path *path = (struct path *)&key->payload.data[big_key_path];
    ^~~~

    Cc: David Howells
    Signed-off-by: Kees Cook

    Kees Cook
     
  • This is another false positive in bad cast detection:

    net/unix/af_unix.c: In function ‘unix_skb_scm_eq’:
    net/unix/af_unix.c:1621:31: note: found mismatched rhs struct pointer types: ‘struct unix_skb_parms’ and ‘char’

    const struct unix_skb_parms *u = &UNIXCB(skb);
    ^

    UNIXCB is:

    #define UNIXCB(skb) (*(struct unix_skb_parms *)&((skb)->cb))

    And ->cb is:

    char cb[48] __aligned(8);

    This is a rather crazy cast, but appears to be safe in the face of
    randomization, so whitelist it in the plugin.

    Cc: Hannes Frederic Sowa
    Cc: David S. Miller
    Signed-off-by: Kees Cook

    Kees Cook
     
  • The LSM initialization routines walk security_hook_heads as an array
    of struct list_head instead of via names to avoid a ton of needless
    source. Whitelist this to avoid the false positive warning from the
    plugin:

    security/security.c: In function ‘security_init’:
    security/security.c:59:20: note: found mismatched op0 struct pointer types: ‘struct list_head’ and ‘struct security_hook_heads’

    struct list_head *list = (struct list_head *) &security_hook_heads;
    ^

    Cc: Tetsuo Handa
    Cc: James Morris
    Signed-off-by: Kees Cook

    Kees Cook
     
  • 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
     

29 May, 2017

1 commit

  • The c-common.h file moved in stock gcc 4.7, not gcc 4.6. However, most
    people building plugins with gcc 4.6 are using the Debian or Ubuntu
    version, which includes a patch to move the headers to the 4.7 location.
    In case anyone trips over this with a stock gcc 4.6, add a pointer to the
    patch used by Debian/Ubuntu.

    Signed-off-by: Kees Cook

    Kees Cook
     

10 Mar, 2017

1 commit


28 Feb, 2017

1 commit

  • The name of the local variable was inadvertantly changed from
    sancov_plugin_pass_info to sancov_pass_info:

    scripts/gcc-plugins/sancov_plugin.c: In function ‘int plugin_init(plugin_name_args*, plugin_gcc_version*)’:
    scripts/gcc-plugins/sancov_plugin.c:136:67: error: ‘sancov_plugin_pass_info’ was not declared in this scope

    This changes the conditional reference to this variable as well.

    Fixes: 5a45a4c5c3f5 ("gcc-plugins: consolidate on PASS_INFO macro")
    Signed-off-by: Arnd Bergmann
    Signed-off-by: Kees Cook

    Arnd Bergmann
     

22 Feb, 2017

1 commit


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
     

14 Jan, 2017

1 commit


11 Jan, 2017

1 commit


04 Jan, 2017

2 commits

  • This updates gcc-common.h from Emese Revfy for gcc 7. This fixes issues seen
    by Kugan and Arnd. Build tested with gcc 5.4 and 7 snapshot.

    Cc: stable@vger.kernel.org
    Signed-off-by: Kees Cook

    Kees Cook
     
  • This fixes build errors seen on gcc-4.9.3 or gcc-5.3.1 for an ARM:

    arm-soc/init/initramfs.c: In function 'error':
    arm-soc/init/initramfs.c:50:1: error: unrecognizable insn:
    }
    ^
    (insn 26 25 27 5 (set (reg:SI 111 [ local_entropy.243 ])
    (rotatert:SI (reg:SI 116 [ local_entropy.243 ])
    (const_int -30 [0xffffffffffffffe2]))) -1
    (nil))

    Patch from PaX Team

    Reported-by: Arnd Bergmann
    Reported-by: Brad Spengler
    Cc: stable@vger.kernel.org
    Signed-off-by: Kees Cook

    Kees Cook
     

14 Dec, 2016

1 commit


01 Nov, 2016

2 commits

  • The stack frame size could grow too large when the plugin used long long
    on 32-bit architectures when the given function had too many basic blocks.

    The gcc warning was:

    drivers/pci/hotplug/ibmphp_ebda.c: In function 'ibmphp_access_ebda':
    drivers/pci/hotplug/ibmphp_ebda.c:409:1: warning: the frame size of 1108 bytes is larger than 1024 bytes [-Wframe-larger-than=]

    This switches latent_entropy from u64 to unsigned long.

    Thanks to PaX Team and Emese Revfy for the patch.

    Signed-off-by: Kees Cook

    Kees Cook
     
  • This explicitly exports symbols that gcc expects from plugins.

    Based on code from Emese Revfy.

    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

2 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