Skip to content
Snippets Groups Projects
  1. May 16, 2023
    • Kees Cook's avatar
      ubsan: Tighten UBSAN_BOUNDS on GCC · 2d47c695
      Kees Cook authored
      
      The use of -fsanitize=bounds on GCC will ignore some trailing arrays,
      leaving a gap in coverage. Switch to using -fsanitize=bounds-strict to
      match Clang's stricter behavior.
      
      Cc: Marco Elver <elver@google.com>
      Cc: Masahiro Yamada <masahiroy@kernel.org>
      Cc: Nathan Chancellor <nathan@kernel.org>
      Cc: Nick Desaulniers <ndesaulniers@google.com>
      Cc: Nicolas Schier <nicolas@fjasle.eu>
      Cc: Tom Rix <trix@redhat.com>
      Cc: Josh Poimboeuf <jpoimboe@kernel.org>
      Cc: Miroslav Benes <mbenes@suse.cz>
      Cc: linux-kbuild@vger.kernel.org
      Cc: llvm@lists.linux.dev
      Signed-off-by: default avatarKees Cook <keescook@chromium.org>
      Link: https://lore.kernel.org/r/20230405022356.gonna.338-kees@kernel.org
      2d47c695
  2. Jan 20, 2022
  3. Feb 26, 2021
  4. Dec 16, 2020
  5. Oct 16, 2020
  6. Sep 24, 2020
    • Masahiro Yamada's avatar
      kbuild: move CFLAGS_{KASAN,UBSAN,KCSAN} exports to relevant Makefiles · bb273211
      Masahiro Yamada authored
      
      Move CFLAGS_KASAN*, CFLAGS_UBSAN, CFLAGS_KCSAN to Makefile.kasan,
      Makefile.ubsan, Makefile.kcsan, respectively.
      
      This commit also avoids the same -fsanitize=* flags being added to
      CFLAGS_UBSAN multiple times.
      
      Prior to this commit, the ubsan flags were appended by the '+='
      operator, without any initialization. Some build targets such as
      'make bindeb-pkg' recurses to the top Makefile, and ended up with
      adding the same flags to CFLAGS_UBSAN twice.
      
      Clear CFLAGS_UBSAN with ':=' to make it a simply expanded variable.
      This is better than a recursively expanded variable, which evaluates
      $(call cc-option, ...) multiple times before Kbuild starts descending
      to subdirectories.
      
      Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
      Acked-by: default avatarMarco Elver <elver@google.com>
      bb273211
  7. Aug 09, 2020
  8. Apr 07, 2020
    • Kees Cook's avatar
      ubsan: split "bounds" checker from other options · 277a1085
      Kees Cook authored
      In order to do kernel builds with the bounds checker individually
      available, introduce CONFIG_UBSAN_BOUNDS, with the remaining options under
      CONFIG_UBSAN_MISC.
      
      For example, using this, we can start to expand the coverage syzkaller is
      providing.  Right now, all of UBSan is disabled for syzbot builds because
      taken as a whole, it is too noisy.  This will let us focus on one feature
      at a time.
      
      For the bounds checker specifically, this provides a mechanism to
      eliminate an entire class of array overflows with close to zero
      performance overhead (I cannot measure a difference).  In my (mostly)
      defconfig, enabling bounds checking adds ~4200 checks to the kernel.
      Performance changes are in the noise, likely due to the branch predictors
      optimizing for the non-fail path.
      
      Some notes on the bounds checker:
      
      - it does not instrument {mem,str}*()-family functions, it only
        instruments direct indexed accesses (e.g. "foo[i]"). Dealing with
        the {mem,str}*()-family functions is a work-in-progress around
        CONFIG_FORTIFY_SOURCE[1].
      
      - it ignores flexible array members, including the very old single
        byte (e.g. "int foo[1];") declarations. (Note that GCC's
        implementation appears to ignore _all_ trailing arrays, but Clang only
        ignores empty, 0, and 1 byte arrays[2].)
      
      [1] https://github.com/KSPP/linux/issues/6
      [2] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92589
      
      
      
      Suggested-by: default avatarElena Petrova <lenaptr@google.com>
      Signed-off-by: default avatarKees Cook <keescook@chromium.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Reviewed-by: default avatarAndrey Ryabinin <aryabinin@virtuozzo.com>
      Acked-by: default avatarDmitry Vyukov <dvyukov@google.com>
      Cc: Alexander Potapenko <glider@google.com>
      Cc: Andrey Konovalov <andreyknvl@google.com>
      Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
      Cc: Arnd Bergmann <arnd@arndb.de>
      Cc: Dan Carpenter <dan.carpenter@oracle.com>
      Cc: "Gustavo A. R. Silva" <gustavo@embeddedor.com>
      Link: http://lkml.kernel.org/r/20200227193516.32566-3-keescook@chromium.org
      
      
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      277a1085
    • Kees Cook's avatar
      ubsan: add trap instrumentation option · 0887a7eb
      Kees Cook authored
      
      Patch series "ubsan: Split out bounds checker", v5.
      
      This splits out the bounds checker so it can be individually used.  This
      is enabled in Android and hopefully for syzbot.  Includes LKDTM tests for
      behavioral corner-cases (beyond just the bounds checker), and adjusts
      ubsan and kasan slightly for correct panic handling.
      
      This patch (of 6):
      
      The Undefined Behavior Sanitizer can operate in two modes: warning
      reporting mode via lib/ubsan.c handler calls, or trap mode, which uses
      __builtin_trap() as the handler.  Using lib/ubsan.c means the kernel image
      is about 5% larger (due to all the debugging text and reporting structures
      to capture details about the warning conditions).  Using the trap mode,
      the image size changes are much smaller, though at the loss of the
      "warning only" mode.
      
      In order to give greater flexibility to system builders that want minimal
      changes to image size and are prepared to deal with kernel code being
      aborted and potentially destabilizing the system, this introduces
      CONFIG_UBSAN_TRAP.  The resulting image sizes comparison:
      
         text    data     bss       dec       hex     filename
      19533663   6183037  18554956  44271656  2a38828 vmlinux.stock
      19991849   7618513  18874448  46484810  2c54d4a vmlinux.ubsan
      19712181   6284181  18366540  44362902  2a4ec96 vmlinux.ubsan-trap
      
      CONFIG_UBSAN=y:      image +4.8% (text +2.3%, data +18.9%)
      CONFIG_UBSAN_TRAP=y: image +0.2% (text +0.9%, data +1.6%)
      
      Additionally adjusts the CONFIG_UBSAN Kconfig help for clarity and removes
      the mention of non-existing boot param "ubsan_handle".
      
      Suggested-by: default avatarElena Petrova <lenaptr@google.com>
      Signed-off-by: default avatarKees Cook <keescook@chromium.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Acked-by: default avatarDmitry Vyukov <dvyukov@google.com>
      Cc: Andrey Ryabinin <aryabinin@virtuozzo.com>
      Cc: Andrey Konovalov <andreyknvl@google.com>
      Cc: Alexander Potapenko <glider@google.com>
      Cc: Dan Carpenter <dan.carpenter@oracle.com>
      Cc: "Gustavo A. R. Silva" <gustavo@embeddedor.com>
      Cc: Arnd Bergmann <arnd@arndb.de>
      Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
      Link: http://lkml.kernel.org/r/20200227193516.32566-2-keescook@chromium.org
      
      
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      0887a7eb
  9. May 06, 2019
  10. Aug 11, 2018
  11. Feb 07, 2018
  12. Nov 02, 2017
    • Greg Kroah-Hartman's avatar
      License cleanup: add SPDX GPL-2.0 license identifier to files with no license · b2441318
      Greg Kroah-Hartman authored
      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...
      b2441318
  13. Nov 11, 2016
    • Arnd Bergmann's avatar
      Kbuild: enable -Wmaybe-uninitialized warning for "make W=1" · a76bcf55
      Arnd Bergmann authored
      Traditionally, we have always had warnings about uninitialized variables
      enabled, as this is part of -Wall, and generally a good idea [1], but it
      also always produced false positives, mainly because this is a variation
      of the halting problem and provably impossible to get right in all cases
      [2].
      
      Various people have identified cases that are particularly bad for false
      positives, and in commit e74fc973 ("Turn off -Wmaybe-uninitialized
      when building with -Os"), I turned off the warning for any build that
      was done with CC_OPTIMIZE_FOR_SIZE.  This drastically reduced the number
      of false positive warnings in the default build but unfortunately had
      the side effect of turning the warning off completely in 'allmodconfig'
      builds, which in turn led to a lot of warnings (both actual bugs, and
      remaining false positives) to go in unnoticed.
      
      With commit 877417e6 ("Kbuild: change CC_OPTIMIZE_FOR_SIZE
      definition") enabled the warning again for allmodconfig builds in v4.7
      and in v4.8-rc1, I had finally managed to address all warnings I get in
      an ARM allmodconfig build and most other maybe-uninitialized warnings
      for ARM randconfig builds.
      
      However, commit 6e8d666e ("Disable "maybe-uninitialized" warning
      globally") was merged at the same time and disabled it completely for
      all configurations, because of false-positive warnings on x86 that I had
      not addressed until then.  This caused a lot of actual bugs to get
      merged into mainline, and I sent several dozen patches for these during
      the v4.9 development cycle.  Most of these are actual bugs, some are for
      correct code that is safe because it is only called under external
      constraints that make it impossible to run into the case that gcc sees,
      and in a few cases gcc is just stupid and finds something that can
      obviously never happen.
      
      I have now done a few thousand randconfig builds on x86 and collected
      all patches that I needed to address every single warning I got (I can
      provide the combined patch for the other warnings if anyone is
      interested), so I hope we can get the warning back and let people catch
      the actual bugs earlier.
      
      This reverts the change to disable the warning completely and for now
      brings it back at the "make W=1" level, so we can get it merged into
      mainline without introducing false positives.  A follow-up patch enables
      it on all levels unless some configuration option turns it off because
      of false-positives.
      
      Link: https://rusty.ozlabs.org/?p=232 [1]
      Link: https://gcc.gnu.org/wiki/Better_Uninitialized_Warnings
      
       [2]
      Signed-off-by: default avatarArnd Bergmann <arnd@arndb.de>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      a76bcf55
  14. Sep 20, 2016
  15. Jul 27, 2016
    • Linus Torvalds's avatar
      Disable "maybe-uninitialized" warning globally · 6e8d666e
      Linus Torvalds authored
      
      Several build configurations had already disabled this warning because
      it generates a lot of false positives.  But some had not, and it was
      still enabled for "allmodconfig" builds, for example.
      
      Looking at the warnings produced, every single one I looked at was a
      false positive, and the warnings are frequent enough (and big enough)
      that they can easily hide real problems that you don't notice in the
      noise generated by -Wmaybe-uninitialized.
      
      The warning is good in theory, but this is a classic case of a warning
      that causes more problems than the warning can solve.
      
      If gcc gets better at avoiding false positives, we may be able to
      re-enable this warning.  But as is, we're better off without it, and I
      want to be able to see the *real* warnings.
      
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      6e8d666e
  16. Mar 22, 2016
  17. Jan 21, 2016
Loading