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
     

11 Jul, 2017

4 commits

  • Including pulls in a lot of bloat from and
    that is not needed to call the BUILD_BUG() family of
    macros. Split them out into their own header, .

    Also correct some checkpatch.pl errors for the BUILD_BUG_ON_ZERO() and
    BUILD_BUG_ON_NULL() macros by adding parentheses around the bitfield
    widths that begin with a minus sign.

    Link: http://lkml.kernel.org/r/20170525120316.24473-6-abbotti@mev.co.uk
    Signed-off-by: Ian Abbott
    Acked-by: Michal Nazarewicz
    Acked-by: Kees Cook
    Cc: Steven Rostedt
    Cc: Peter Zijlstra
    Cc: Jakub Kicinski
    Cc: Rasmus Villemoes
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Ian Abbott
     
  • Correct these checkpatch.pl errors:

    |ERROR: space required before that '-' (ctx:OxO)
    |#37: FILE: include/linux/bug.h:37:
    |+#define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); }))

    |ERROR: space required before that '-' (ctx:OxO)
    |#38: FILE: include/linux/bug.h:38:
    |+#define BUILD_BUG_ON_NULL(e) ((void *)sizeof(struct { int:-!!(e); }))

    I decided to wrap the bitfield expressions that begin with minus signs
    in parentheses rather than insert spaces before the minus signs.

    Link: http://lkml.kernel.org/r/20170525120316.24473-5-abbotti@mev.co.uk
    Signed-off-by: Ian Abbott
    Acked-by: Michal Nazarewicz
    Cc: Kees Cook
    Cc: Steven Rostedt
    Cc: Peter Zijlstra
    Cc: Jakub Kicinski
    Cc: Rasmus Villemoes
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Ian Abbott
     
  • Correct this checkpatch.pl error:

    |ERROR: "(foo*)" should be "(foo *)"
    |#19: FILE: include/linux/bug.h:19:
    |+#define BUILD_BUG_ON_NULL(e) ((void*)0)

    Link: http://lkml.kernel.org/r/20170525120316.24473-4-abbotti@mev.co.uk
    Signed-off-by: Ian Abbott
    Acked-by: Michal Nazarewicz
    Cc: Kees Cook
    Cc: Steven Rostedt
    Cc: Peter Zijlstra
    Cc: Jakub Kicinski
    Cc: Rasmus Villemoes
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Ian Abbott
     
  • Correct these checkpatch.pl warnings:

    |WARNING: Block comments use * on subsequent lines
    |#34: FILE: include/linux/bug.h:34:
    |+/* Force a compilation error if condition is true, but also produce a
    |+ result (of value 0 and type size_t), so the expression can be used

    |WARNING: Block comments use a trailing */ on a separate line
    |#36: FILE: include/linux/bug.h:36:
    |+ aren't permitted). */

    Link: http://lkml.kernel.org/r/20170525120316.24473-3-abbotti@mev.co.uk
    Signed-off-by: Ian Abbott
    Acked-by: Michal Nazarewicz
    Cc: Kees Cook
    Cc: Steven Rostedt
    Cc: Peter Zijlstra
    Cc: Jakub Kicinski
    Cc: Rasmus Villemoes
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Ian Abbott
     

30 Mar, 2017

1 commit

  • Josh suggested moving the _ONCE logic inside the trap handler, using a
    bit in the bug_entry::flags field, avoiding the need for the extra
    variable.

    Sadly this only works for WARN_ON_ONCE(), since the others have
    printk() statements prior to triggering the trap.

    Still, this saves a fair amount of text and some data:

    text data filename
    10682460 4530992 defconfig-build/vmlinux.orig
    10665111 4530096 defconfig-build/vmlinux.patched

    Suggested-by: Josh Poimboeuf
    Signed-off-by: Peter Zijlstra (Intel)
    Cc: Andy Lutomirski
    Cc: Arnd Bergmann
    Cc: Borislav Petkov
    Cc: Brian Gerst
    Cc: Denys Vlasenko
    Cc: H. Peter Anvin
    Cc: Linus Torvalds
    Cc: Peter Zijlstra
    Cc: Thomas Gleixner
    Signed-off-by: Ingo Molnar

    Peter Zijlstra
     

25 Feb, 2017

1 commit

  • The CHECK_DATA_CORRUPTION() macro was designed to have callers do
    something meaningful/protective on failure. However, using "return
    false" in the macro too strictly limits the design patterns of callers.
    Instead, let callers handle the logic test directly, but make sure that
    the result IS checked by forcing __must_check (which appears to not be
    able to be used directly on macro expressions).

    Link: http://lkml.kernel.org/r/20170206204547.GA125312@beast
    Signed-off-by: Kees Cook
    Suggested-by: Arnd Bergmann
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Kees Cook
     

01 Nov, 2016

1 commit

  • The kernel checks for cases of data structure corruption under some
    CONFIGs (e.g. CONFIG_DEBUG_LIST). When corruption is detected, some
    systems may want to BUG() immediately instead of letting the system run
    with known corruption. Usually these kinds of manipulation primitives can
    be used by security flaws to gain arbitrary memory write control. This
    provides a new config CONFIG_BUG_ON_DATA_CORRUPTION and a corresponding
    macro CHECK_DATA_CORRUPTION for handling these situations. Notably, even
    if not BUGing, the kernel should not continue processing the corrupted
    structure.

    This is inspired by similar hardening by Syed Rameez Mustafa in MSM
    kernels, and in PaX and Grsecurity, which is likely in response to earlier
    removal of the BUG calls in commit 924d9addb9b1 ("list debugging: use
    WARN() instead of BUG()").

    Signed-off-by: Kees Cook
    Acked-by: Steven Rostedt
    Signed-off-by: Paul E. McKenney
    Acked-by: Rik van Riel

    Kees Cook
     

09 Sep, 2016

1 commit

  • Common approach to accessing register fields is to define
    structures or sets of macros containing mask and shift pair.
    Operations on the register are then performed as follows:

    field = (reg >> shift) & mask;

    reg &= ~(mask << shift);
    reg |= (field & mask) << shift;

    Defining shift and mask separately is tedious. Ivo van Doorn
    came up with an idea of computing them at compilation time
    based on a single shifted mask (later refined by Felix) which
    can be used like this:

    #define REG_FIELD 0x000ff000

    field = FIELD_GET(REG_FIELD, reg);

    reg &= ~REG_FIELD;
    reg |= FIELD_PREP(REG_FIELD, field);

    FIELD_{GET,PREP} macros take care of finding out what the
    appropriate shift is based on compilation time ffs operation.

    GENMASK can be used to define registers (which is usually
    less error-prone and easier to match with datasheets).

    This approach is the most convenient I've seen so to limit code
    multiplication let's move the macros to a global header file.
    Attempts to use static inlines instead of macros failed due
    to false positive triggering of BUILD_BUG_ON()s, especially with
    GCC < 6.0.

    Signed-off-by: Jakub Kicinski
    Reviewed-by: Dinan Gunawardena
    Signed-off-by: Kalle Valo

    Jakub Kicinski
     

03 Mar, 2016

1 commit

  • With next generation power processor, we are having a new mmu model
    [1] that require us to maintain a different linux page table format.

    Inorder to support both current and future ppc64 systems with a single
    kernel we need to make sure kernel can select between different page
    table format at runtime. With the new MMU (radix MMU) added, we will
    have two different pmd hugepage size 16MB for hash model and 2MB for
    Radix model. Hence make HPAGE_PMD related values as a variable.

    Actual conversion of HPAGE_PMD to a variable for ppc64 happens in a
    followup patch.

    [1] http://ibm.biz/power-isa3 (Needs registration).

    Signed-off-by: Kirill A. Shutemov
    Signed-off-by: Aneesh Kumar K.V
    Signed-off-by: Michael Ellerman

    Kirill A. Shutemov
     

22 Feb, 2013

6 commits

  • Introduce compiletime_assert to compiler.h, which moves the details of
    how to break a build and emit an error message for a specific compiler
    to the headers where these details should be. Following in the
    tradition of the POSIX assert macro, compiletime_assert creates a
    build-time error when the supplied condition is *false*.

    Next, we add BUILD_BUG_ON_MSG to bug.h which simply wraps
    compiletime_assert, inverting the logic, so that it fails when the
    condition is *true*, consistent with the language "build bug on." This
    macro allows you to specify the error message you want emitted when the
    supplied condition is true.

    Finally, we remove all other code from bug.h that mucks with these
    details (BUILD_BUG & BUILD_BUG_ON), and have them all call
    BUILD_BUG_ON_MSG. This not only reduces source code bloat, but also
    prevents the possibility of code being changed for one macro and not for
    the other (which was previously the case for BUILD_BUG and
    BUILD_BUG_ON).

    Since __compiletime_error_fallback is now only used in compiler.h, I'm
    considering it a private macro and removing the double negation that's
    now extraneous.

    [akpm@linux-foundation.org: checkpatch fixes]
    Signed-off-by: Daniel Santos
    Cc: Andi Kleen
    Cc: Borislav Petkov
    Cc: David Rientjes
    Cc: Joe Perches
    Cc: Josh Triplett
    Cc: Paul Gortmaker
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Daniel Santos
     
  • Prior to the introduction of __attribute__((error("msg"))) in gcc 4.3,
    creating compile-time errors required a little trickery.
    BUILD_BUG{,_ON} uses this attribute when available to generate
    compile-time errors, but also uses the negative-sized array trick for
    older compilers, resulting in two error messages in some cases. The
    reason it's "some" cases is that as of gcc 4.4, the negative-sized array
    will not create an error in some situations, like inline functions.

    This patch replaces the negative-sized array code with the new
    __compiletime_error_fallback() macro which expands to the same thing
    unless the the error attribute is available, in which case it expands to
    do{}while(0), resulting in exactly one compile-time error on all
    versions of gcc.

    Note that we are not changing the negative-sized array code for the
    unoptimized version of BUILD_BUG_ON, since it has the potential to catch
    problems that would be disabled in later versions of gcc were
    __compiletime_error_fallback used. The reason is that that an
    unoptimized build can't always remove calls to an error-attributed
    function call (like we are using) that should effectively become dead
    code if it were optimized. However, using a negative-sized array with a
    similar value will not result in an false-positive (error). The only
    caveat being that it will also fail to catch valid conditions, which we
    should be expecting in an unoptimized build anyway.

    Signed-off-by: Daniel Santos
    Cc: Andi Kleen
    Cc: Borislav Petkov
    Cc: David Rientjes
    Cc: Joe Perches
    Cc: Josh Triplett
    Cc: Paul Gortmaker
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Daniel Santos
     
  • Negative sized arrays wont create a compile-time error in some cases
    starting with gcc 4.4 (e.g., inlined functions), but gcc 4.3 introduced
    the error function attribute that will.

    This patch modifies BUILD_BUG_ON to behave like BUILD_BUG already does,
    using the error function attribute so that you don't have to build the
    entire kernel to discover that you have a problem, and then enjoy trying
    to track it down from a link-time error.

    Also, we are only including asm/bug.h and then expecting that
    linux/compiler.h will eventually be included to define __linktime_error
    (used in BUILD_BUG_ON). This patch includes it directly for clarity and
    to avoid the possibility of changes in /*/include/asm/bug.h being
    changed or not including linux/compiler.h for some reason.

    Signed-off-by: Daniel Santos
    Acked-by: Borislav Petkov
    Cc: Andi Kleen
    Cc: David Rientjes
    Cc: Joe Perches
    Cc: Josh Triplett
    Cc: Paul Gortmaker
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Daniel Santos
     
  • When calling BUILD_BUG_ON in an optimized build using gcc 4.3 and later,
    the condition will be evaulated twice, possibily with side-effects. This
    patch eliminates that error.

    [akpm@linux-foundation.org: tweak code layout]
    Signed-off-by: Daniel Santos
    Cc: Andi Kleen
    Cc: Borislav Petkov
    Cc: David Rientjes
    Cc: Joe Perches
    Cc: Josh Triplett
    Cc: Paul Gortmaker
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Daniel Santos
     
  • When __CHECKER__ is defined, we disable all of the BUILD_BUG.* macros.
    However, both BUILD_BUG_ON_NOT_POWER_OF_2 and BUILD_BUG_ON was evaluating
    to nothing in this case, and we want (0) since this is a function-like
    macro that will be followed by a semicolon.

    Signed-off-by: Daniel Santos
    Acked-by: Borislav Petkov
    Cc: Andi Kleen
    Cc: David Rientjes
    Cc: Joe Perches
    Cc: Josh Triplett
    Cc: Paul Gortmaker
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Daniel Santos
     
  • __linktime_error() does the same thing as __compiletime_error() and is
    only used in bug.h. Since the macro defines a function attribute that
    will cause a failure at compile-time (not link-time), it makes more sense
    to keep __compiletime_error(), which is also neatly mated with
    __compiletime_warning().

    Signed-off-by: Daniel Santos
    Acked-by: David Rientjes
    Acked-by: Borislav Petkov
    Cc: Andi Kleen
    Cc: Joe Perches
    Cc: Josh Triplett
    Cc: Paul Gortmaker
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Daniel Santos
     

27 Nov, 2012

1 commit

  • Commit baf05aa9271b ("bug: introduce BUILD_BUG_ON_INVALID() macro")
    introduces this macro only when _CHECKER_ is not defined. Define a
    silent macro in the else condition to fix following sparse warning:

    mm/filemap.c:395:9: error: undefined identifier 'BUILD_BUG_ON_INVALID'
    mm/filemap.c:396:9: error: undefined identifier 'BUILD_BUG_ON_INVALID'
    mm/filemap.c:397:9: error: undefined identifier 'BUILD_BUG_ON_INVALID'
    include/linux/mm.h:419:9: error: undefined identifier 'BUILD_BUG_ON_INVALID'
    include/linux/mm.h:419:9: error: not a function

    Signed-off-by: Tushar Behera
    Acked-by: Konstantin Khlebnikov
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Tushar Behera
     

30 May, 2012

1 commit

  • Sometimes we want to check some expressions correctness at compile time.
    "(void)(e);" or "if (e);" can be dangerous if the expression has
    side-effects, and gcc sometimes generates a lot of code, even if the
    expression has no effect.

    This patch introduces macro BUILD_BUG_ON_INVALID() for such checks, it
    forces a compilation error if expression is invalid without any extra
    code.

    [Cast to "long" required because sizeof does not work for bit-fields.]

    Signed-off-by: Konstantin Khlebnikov
    Cc: Linus Torvalds
    Cc: Geert Uytterhoeven
    Cc: "H. Peter Anvin"
    Cc: Cong Wang
    Cc: Hugh Dickins
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Konstantin Khlebnikov
     

05 Mar, 2012

1 commit

  • The support for BUILD_BUG in linux/kernel.h predates the
    addition of linux/bug.h -- with this chunk off separate,
    you can run into situations where a person gets a compile
    fail even when they've included linux/bug.h, like this:

    CC lib/string.o
    lib/string.c: In function 'strlcat':
    lib/string.c:225:2: error: implicit declaration of function 'BUILD_BUG_ON'
    make[2]: *** [lib/string.o] Error 1
    $
    $ grep linux/bug.h lib/string.c
    #include
    $

    Since the above violates the principle of least surprise, move
    the BUG chunks from kernel.h to bug.h so it is all together.

    Signed-off-by: Paul Gortmaker

    Paul Gortmaker
     

17 Jun, 2009

1 commit

  • They're in linux/bug.h at present, which causes include order tangles. In
    particular, linux/bug.h cannot be used by linux/atomic.h because,
    according to Nikanth:

    linux/bug.h pulls in linux/module.h => linux/spinlock.h => asm/spinlock.h
    (which uses atomic_inc) => asm/atomic.h.

    bug.h is a pretty low-level thing and module.h is a higher-level thing,
    IMO.

    Cc: Nikanth Karthikesan
    Cc: Rusty Russell
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Andrew Morton
     

17 Jul, 2007

1 commit

  • The current generic bug implementation has a call to dump_stack() in case a
    WARN_ON(whatever) gets hit. Since report_bug(), which calls dump_stack(),
    gets called from an exception handler we can do better: just pass the
    pt_regs structure to report_bug() and pass it to show_regs() in case of a
    warning. This will give more debug informations like register contents,
    etc... In addition this avoids some pointless lines that dump_stack()
    emits, since it includes a stack backtrace of the exception handler which
    is of no interest in case of a warning. E.g. on s390 the following lines
    are currently always present in a stack backtrace if dump_stack() gets
    called from report_bug():

    [] show_trace+0x92/0xe8)
    [] show_stack+0xa0/0xd0
    [] dump_stack+0x2e/0x3c
    [] report_bug+0x98/0xf8
    [] illegal_op+0x1fc/0x21c
    [] sysc_return+0x0/0x10

    Acked-by: Jeremy Fitzhardinge
    Acked-by: Haavard Skinnemoen
    Cc: Andi Kleen
    Cc: Kyle McMartin
    Cc: Paul Mackerras
    Cc: Paul Mundt
    Cc: Martin Schwidefsky
    Signed-off-by: Heiko Carstens
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Heiko Carstens
     

09 Dec, 2006

1 commit

  • This patch adds common handling for kernel BUGs, for use by architectures as
    they wish. The code is derived from arch/powerpc.

    The advantages of having common BUG handling are:
    - consistent BUG reporting across architectures
    - shared implementation of out-of-line file/line data
    - implement CONFIG_DEBUG_BUGVERBOSE consistently

    This means that in inline impact of BUG is just the illegal instruction
    itself, which is an improvement for i386 and x86-64.

    A BUG is represented in the instruction stream as an illegal instruction,
    which has file/line information associated with it. This extra information is
    stored in the __bug_table section in the ELF file.

    When the kernel gets an illegal instruction, it first confirms it might
    possibly be from a BUG (ie, in kernel mode, the right illegal instruction).
    It then calls report_bug(). This searches __bug_table for a matching
    instruction pointer, and if found, prints the corresponding file/line
    information. If report_bug() determines that it wasn't a BUG which caused the
    trap, it returns BUG_TRAP_TYPE_NONE.

    Some architectures (powerpc) implement WARN using the same mechanism; if the
    illegal instruction was the result of a WARN, then report_bug(Q) returns
    CONFIG_DEBUG_BUGVERBOSE; otherwise it returns BUG_TRAP_TYPE_BUG.

    lib/bug.c keeps a list of loaded modules which can be searched for __bug_table
    entries. The architecture must call
    module_bug_finalize()/module_bug_cleanup() from its corresponding
    module_finalize/cleanup functions.

    Unsetting CONFIG_DEBUG_BUGVERBOSE will reduce the kernel size by some amount.
    At the very least, filename and line information will not be recorded for each
    but, but architectures may decide to store no extra information per BUG at
    all.

    Unfortunately, gcc doesn't have a general way to mark an asm() as noreturn, so
    architectures will generally have to include an infinite loop (or similar) in
    the BUG code, so that gcc knows execution won't continue beyond that point.
    gcc does have a __builtin_trap() operator which may be useful to achieve the
    same effect, unfortunately it cannot be used to actually implement the BUG
    itself, because there's no way to get the instruction's address for use in
    generating the __bug_table entry.

    [randy.dunlap@oracle.com: Handle BUG=n, GENERIC_BUG=n to prevent build errors]
    [bunk@stusta.de: include/linux/bug.h must always #include
    Cc: Andi Kleen
    Cc: Hugh Dickens
    Cc: Michael Ellerman
    Cc: Paul Mackerras
    Cc: Benjamin Herrenschmidt
    Cc: Rusty Russell
    Signed-off-by: Adrian Bunk
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Jeremy Fitzhardinge