Forum | Documentation | Website | Blog

Skip to content
Snippets Groups Projects
  1. Dec 08, 2021
  2. Nov 14, 2021
  3. Nov 06, 2021
    • Kees Cook's avatar
      Compiler Attributes: add __alloc_size() for better bounds checking · 86cffecd
      Kees Cook authored
      GCC and Clang can use the "alloc_size" attribute to better inform the
      results of __builtin_object_size() (for compile-time constant values).
      Clang can additionally use alloc_size to inform the results of
      __builtin_dynamic_object_size() (for run-time values).
      
      Because GCC sees the frequent use of struct_size() as an allocator size
      argument, and notices it can return SIZE_MAX (the overflow indication),
      it complains about these call sites overflowing (since SIZE_MAX is
      greater than the default -Walloc-size-larger-than=PTRDIFF_MAX).  This
      isn't helpful since we already know a SIZE_MAX will be caught at
      run-time (this was an intentional design).  To deal with this, we must
      disable this check as it is both a false positive and redundant.  (Clang
      does not have this warning option.)
      
      Unfortunately, just checking the -Wno-alloc-size-larger-than is not
      sufficient to make the __alloc_size attribute behave correctly under
      older GCC versions.  The attribute itself must be disabled in those
      situations too, as there appears to be no way to reliably silence the
      SIZE_MAX constant expression cases for GCC versions less than 9.1:
      
         In file included from ./include/linux/resource_ext.h:11,
                          from ./include/linux/pci.h:40,
                          from drivers/net/ethernet/intel/ixgbe/ixgbe.h:9,
                          from drivers/net/ethernet/intel/ixgbe/ixgbe_lib.c:4:
         In function 'kmalloc_node',
             inlined from 'ixgbe_alloc_q_vector' at ./include/linux/slab.h:743:9:
         ./include/linux/slab.h:618:9: error: argument 1 value '18446744073709551615' exceeds maximum object size 9223372036854775807 [-Werror=alloc-size-larger-than=]
           return __kmalloc_node(size, flags, node);
                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         ./include/linux/slab.h: In function 'ixgbe_alloc_q_vector':
         ./include/linux/slab.h:455:7: note: in a call to allocation function '__kmalloc_node' declared here
          void *__kmalloc_node(size_t size, gfp_t flags, int node) __assume_slab_alignment __malloc;
                ^~~~~~~~~~~~~~
      
      Specifically:
       '-Wno-alloc-size-larger-than' is not correctly handled by GCC < 9.1
          https://godbolt.org/z/hqsfG7q84 (doesn't disable)
          https://godbolt.org/z/P9jdrPTYh (doesn't admit to not knowing about option)
          https://godbolt.org/z/465TPMWKb (only warns when other warnings appear)
      
       '-Walloc-size-larger-than=18446744073709551615' is not handled by GCC < 8.2
          https://godbolt.org/z/73hh1EPxz (ignores numeric value)
      
      Since anything marked with __alloc_size would also qualify for marking
      with __malloc, just include __malloc along with it to avoid redundant
      markings.  (Suggested by Linus Torvalds.)
      
      Finally, make sure checkpatch.pl doesn't get confused about finding the
      __alloc_size attribute on functions.  (Thanks to Joe Perches.)
      
      Link: https://lkml.kernel.org/r/20210930222704.2631604-3-keescook@chromium.org
      
      
      Signed-off-by: default avatarKees Cook <keescook@chromium.org>
      Tested-by: default avatarRandy Dunlap <rdunlap@infradead.org>
      Cc: Andy Whitcroft <apw@canonical.com>
      Cc: Christoph Lameter <cl@linux.com>
      Cc: Daniel Micay <danielmicay@gmail.com>
      Cc: David Rientjes <rientjes@google.com>
      Cc: Dennis Zhou <dennis@kernel.org>
      Cc: Dwaipayan Ray <dwaipayanray1@gmail.com>
      Cc: Joe Perches <joe@perches.com>
      Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
      Cc: Lukas Bulwahn <lukas.bulwahn@gmail.com>
      Cc: Pekka Enberg <penberg@kernel.org>
      Cc: Tejun Heo <tj@kernel.org>
      Cc: Vlastimil Babka <vbabka@suse.cz>
      Cc: Alexandre Bounine <alex.bou9@gmail.com>
      Cc: Gustavo A. R. Silva <gustavoars@kernel.org>
      Cc: Ira Weiny <ira.weiny@intel.com>
      Cc: Jing Xiangfeng <jingxiangfeng@huawei.com>
      Cc: John Hubbard <jhubbard@nvidia.com>
      Cc: kernel test robot <lkp@intel.com>
      Cc: Matt Porter <mporter@kernel.crashing.org>
      Cc: Miguel Ojeda <ojeda@kernel.org>
      Cc: Nathan Chancellor <nathan@kernel.org>
      Cc: Nick Desaulniers <ndesaulniers@google.com>
      Cc: Souptick Joarder <jrdr.linux@gmail.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      86cffecd
  4. Nov 01, 2021
  5. Oct 31, 2021
  6. Oct 25, 2021
  7. Oct 24, 2021
  8. Oct 18, 2021
  9. Oct 10, 2021
  10. Oct 03, 2021
  11. Sep 26, 2021
  12. Sep 25, 2021
  13. Sep 21, 2021
    • Alexey Dobriyan's avatar
      isystem: delete global -isystem compile option · 04e85bbf
      Alexey Dobriyan authored
      Further isolate kernel from userspace, prevent accidental inclusion of
      undesireable headers, mainly float.h and stdatomic.h.
      
      nds32 keeps -isystem globally due to intrinsics used in entrenched header.
      
      -isystem is selectively reenabled for some files, again, for intrinsics.
      
      Compile tested on:
      
      hexagon-defconfig hexagon-allmodconfig
      alpha-allmodconfig alpha-allnoconfig alpha-defconfig arm64-allmodconfig
      arm64-allnoconfig arm64-defconfig arm-am200epdkit arm-aspeed_g4
      arm-aspeed_g5 arm-assabet arm-at91_dt arm-axm55xx arm-badge4 arm-bcm2835
      arm-cerfcube arm-clps711x arm-cm_x300 arm-cns3420vb arm-colibri_pxa270
      arm-colibri_pxa300 arm-collie arm-corgi arm-davinci_all arm-dove
      arm-ep93xx arm-eseries_pxa arm-exynos arm-ezx arm-footbridge arm-gemini
      arm-h3600 arm-h5000 arm-hackkit arm-hisi arm-imote2 arm-imx_v4_v5
      arm-imx_v6_v7 arm-integrator arm-iop32x arm-ixp4xx arm-jornada720
      arm-keystone arm-lart arm-lpc18xx arm-lpc32xx arm-lpd270 arm-lubbock
      arm-magician arm-mai...
      04e85bbf
  14. Sep 19, 2021
  15. Sep 13, 2021
  16. Sep 12, 2021
  17. Sep 08, 2021
  18. Sep 05, 2021
    • Linus Torvalds's avatar
      Enable '-Werror' by default for all kernel builds · 3fe617cc
      Linus Torvalds authored
      
      ... but make it a config option so that broken environments can disable
      it when required.
      
      We really should always have a clean build, and will disable specific
      over-eager warnings as required, if we can't fix them.  But while I
      fairly religiously enforce that in my own tree, it doesn't get enforced
      by various build robots that don't necessarily report warnings.
      
      So this just makes '-Werror' a default compiler flag, but allows people
      to disable it for their configuration if they have some particular
      issues.
      
      Occasionally, new compiler versions end up enabling new warnings, and it
      can take a while before we have them fixed (or the warnings disabled if
      that is what it takes), so the config option allows for that situation.
      
      Hopefully this will mean that I get fewer pull requests that have new
      warnings that were not noticed by various automation we have in place.
      
      Knock wood.
      
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      3fe617cc
  19. Sep 02, 2021
    • Nathan Chancellor's avatar
      kbuild: Shuffle blank line to improve comment meaning · 6272cc38
      Nathan Chancellor authored
      
      -Wunused-but-set-variable and -Wunused-const-variable are both disabled
      for the same reason but there is a blank line between them and no blank
      line between -Wno-unused-const-variable and the block.
      
      Shuffle the new line so that it is clear that the comment applied to
      both flags and the next block is separate from them.
      
      Signed-off-by: default avatarNathan Chancellor <nathan@kernel.org>
      Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
      6272cc38
    • Nathan Chancellor's avatar
      kbuild: Add a comment above -Wno-gnu · 5c6ae0ef
      Nathan Chancellor authored
      
      Whenever a warning is disabled, it is helpful for future travelers to
      understand why the warning is disabled and why it is acceptable to do
      so. Add a comment for -Wno-gnu so that people understand why it is
      disabled.
      
      Signed-off-by: default avatarNathan Chancellor <nathan@kernel.org>
      Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
      5c6ae0ef
    • Nathan Chancellor's avatar
      kbuild: Remove -Wno-format-invalid-specifier from clang block · a312b60d
      Nathan Chancellor authored
      Turning on -Wformat does not reveal any instances of this warning across
      several different builds so remove this line to keep the number of
      disabled warnings as slim as possible.
      
      This has been disabled since commit 61163efa
      
       ("kbuild: LLVMLinux:
      Add Kbuild support for building kernel with Clang"), which does not
      explain exactly why it was turned off but since it was so long ago in
      terms of both the kernel and LLVM so it is possible that some bug got
      fixed along the way.
      
      Signed-off-by: default avatarNathan Chancellor <nathan@kernel.org>
      Reviewed-by: default avatarNick Desaulniers <ndesaulniers@google.com>
      Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
      a312b60d
    • Nick Desaulniers's avatar
      Makefile: remove stale cc-option checks · 7d73c3e9
      Nick Desaulniers authored
      cc-option, cc-option-yn, and cc-disable-warning all invoke the compiler
      during build time, and can slow down the build when these checks become
      stale for our supported compilers, whose minimally supported versions
      increases over time. See Documentation/process/changes.rst for the
      current supported minimal versions (GCC 4.9+, clang 10.0.1+). Compiler
      version support for these flags may be verified on godbolt.org.
      
      The following flags are GCC only and supported since at least GCC 4.9.
      Remove cc-option and cc-disable-warning tests.
      * -fno-tree-loop-im
      * -Wno-maybe-uninitialized
      * -fno-reorder-blocks
      * -fno-ipa-cp-clone
      * -fno-partial-inlining
      * -femit-struct-debug-baseonly
      * -fno-inline-functions-called-once
      * -fconserve-stack
      
      The following flags are supported by all supported versions of GCC and
      Clang. Remove their cc-option, cc-option-yn, and cc-disable-warning tests.
      * -fno-delete-null-pointer-checks
      * -fno-var-tracking
      * -Wno-array-bounds
      
      The following configs are made dependent on GCC, since they use GCC
      specific flags.
      * READABLE_ASM
      * DEBUG_SECTION_MISMATCH
      
      -mfentry was not supported by s390-linux-gnu-gcc until gcc-9+, add a
      comment.
      
      --param=allow-store-data-races=0 was renamed to -fno-allow-store-data-races
      in the GCC 10 release; add a comment.
      
      -Wmaybe-uninitialized (GCC specific) was being added for CONFIG_GCOV,
      then again unconditionally; add it only once.
      
      Also, base RETPOLINE_CFLAGS and RETPOLINE_VDSO_CFLAGS on CONFIC_CC_IS_*
      then remove cc-option tests for Clang.
      
      Link: https://github.com/ClangBuiltLinux/linux/issues/1436
      
      
      Acked-by: default avatarMiguel Ojeda <ojeda@kernel.org>
      Reviewed-by: default avatarNathan Chancellor <nathan@kernel.org>
      Signed-off-by: default avatarNick Desaulniers <ndesaulniers@google.com>
      Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
      7d73c3e9
  20. Sep 01, 2021
  21. Aug 29, 2021
  22. Aug 22, 2021
  23. Aug 15, 2021
  24. Aug 09, 2021
  25. Aug 08, 2021
  26. Aug 05, 2021
  27. Aug 04, 2021
  28. Aug 01, 2021
  29. Jul 25, 2021
  30. Jul 20, 2021
    • Kees Cook's avatar
      hardening: Introduce CONFIG_ZERO_CALL_USED_REGS · a82adfd5
      Kees Cook authored
      When CONFIG_ZERO_CALL_USED_REGS is enabled, build the kernel with
      "-fzero-call-used-regs=used-gpr" (in GCC 11). This option will zero any
      caller-used register contents just before returning from a function,
      ensuring that temporary values are not leaked beyond the function
      boundary. This means that register contents are less likely to be
      available for side channel attacks and information exposures.
      
      Additionally this helps reduce the number of useful ROP gadgets in the
      kernel image by about 20%:
      
      $ ROPgadget.py --nosys --nojop --binary vmlinux.stock | tail -n1
      Unique gadgets found: 337245
      
      $ ROPgadget.py --nosys --nojop --binary vmlinux.zero-call-regs | tail -n1
      Unique gadgets found: 267175
      
      and more notably removes simple "write-what-where" gadgets:
      
      $ ROPgadget.py --ropchain --binary vmlinux.stock | sed -n '/Step 1/,/Step 2/p'
      - Step 1 -- Write-what-where gadgets
      
              [+] Gadget found: 0xffffffff8102d76c mov qword ptr [rsi], rdx ; ret
              [+] Gadget found: 0xffffffff81000cf5 pop rsi ; ret
              [+] Gadget found: 0xffffffff8104d7c8 pop rdx ; ret
              [-] Can't find the 'xor rdx, rdx' gadget. Try with another 'mov [reg], reg'
      
              [+] Gadget found: 0xffffffff814c2b4c mov qword ptr [rsi], rdi ; ret
              [+] Gadget found: 0xffffffff81000cf5 pop rsi ; ret
              [+] Gadget found: 0xffffffff81001e51 pop rdi ; ret
              [-] Can't find the 'xor rdi, rdi' gadget. Try with another 'mov [reg], reg'
      
              [+] Gadget found: 0xffffffff81540d61 mov qword ptr [rsi], rdi ; pop rbx ; pop rbp ; ret
              [+] Gadget found: 0xffffffff81000cf5 pop rsi ; ret
              [+] Gadget found: 0xffffffff81001e51 pop rdi ; ret
              [-] Can't find the 'xor rdi, rdi' gadget. Try with another 'mov [reg], reg'
      
              [+] Gadget found: 0xffffffff8105341e mov qword ptr [rsi], rax ; ret
              [+] Gadget found: 0xffffffff81000cf5 pop rsi ; ret
              [+] Gadget found: 0xffffffff81029a11 pop rax ; ret
              [+] Gadget found: 0xffffffff811f1c3b xor rax, rax ; ret
      
      - Step 2 -- Init syscall number gadgets
      
      $ ROPgadget.py --ropchain --binary vmlinux.zero* | sed -n '/Step 1/,/Step 2/p'
      - Step 1 -- Write-what-where gadgets
      
              [-] Can't find the 'mov qword ptr [r64], r64' gadget
      
      For an x86_64 parallel build tests, this has a less than 1% performance
      impact, and grows the image size less than 1%:
      
      $ size vmlinux.stock vmlinux.zero-call-regs
         text    data     bss     dec     hex filename
      22437676   8559152 14127340 45124168 2b08a48 vmlinux.stock
      22453184   8563248 14110956 45127388 2b096dc vmlinux.zero-call-regs
      
      Impact for other architectures may vary. For example, arm64 sees a 5.5%
      image size growth, mainly due to needing to always clear x16 and x17:
      https://lore.kernel.org/lkml/20210510134503.GA88495@C02TD0UTHF1T.local/
      
      
      
      Signed-off-by: default avatarKees Cook <keescook@chromium.org>
      a82adfd5
  31. Jul 18, 2021