Merge tag 'vla-v4.20-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux
authorLinus Torvalds <torvalds@linux-foundation.org>
Sun, 28 Oct 2018 20:26:45 +0000 (13:26 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Sun, 28 Oct 2018 20:26:45 +0000 (13:26 -0700)
Pull VLA removal from Kees Cook:
 "Globally warn on VLA use.

  This turns on "-Wvla" globally now that the last few trees with their
  VLA removals have landed (crypto, block, net, and powerpc).

  Arnd mentioned that there may be a couple more VLAs hiding in
  hard-to-find randconfigs, but nothing big has shaken out in the last
  month or so in linux-next.

  We should be basically VLA-free now! Wheee. :)

  Summary:

   - Remove unused fallback for BUILD_BUG_ON (which technically contains
     a VLA)

   - Lift -Wvla to the top-level Makefile"

* tag 'vla-v4.20-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux:
  Makefile: Globally enable VLA warning
  compiler.h: give up __compiletime_assert_fallback()

1  2 
Makefile
include/linux/compiler.h
lib/Makefile

diff --combined Makefile
index eb73f062e9e9da16a63fb20aa59479abe52ee12f,f1760e8db5732484c12d6d439a6ec870575198ed..9aa352b38815801e37fd3cb04c66fa96511443f5
+++ b/Makefile
@@@ -2,8 -2,8 +2,8 @@@
  VERSION = 4
  PATCHLEVEL = 19
  SUBLEVEL = 0
 -EXTRAVERSION = -rc2
 -NAME = Merciless Moray
 +EXTRAVERSION =
 +NAME = "People's Front"
  
  # *DOCUMENTATION*
  # To see a list of typical targets execute "make help"
  PHONY := _all
  _all:
  
 -# o Do not use make's built-in rules and variables
 -#   (this increases performance and avoids hard-to-debug behaviour);
 -# o Look for make include files relative to root of kernel src
 -MAKEFLAGS += -rR --include-dir=$(CURDIR)
 +# Do not use make's built-in rules and variables
 +# (this increases performance and avoids hard-to-debug behaviour)
 +MAKEFLAGS += -rR
  
  # Avoid funny character set dependencies
  unexport LC_ALL
@@@ -135,13 -136,6 +135,13 @@@ KBUILD_OUTPUT := $(shell mkdir -p $(KBU
  $(if $(KBUILD_OUTPUT),, \
       $(error failed to create output directory "$(saved-output)"))
  
 +# Look for make include files relative to root of kernel src
 +#
 +# This does not become effective immediately because MAKEFLAGS is re-parsed
 +# once after the Makefile is read.  It is OK since we are going to invoke
 +# 'sub-make' below.
 +MAKEFLAGS += --include-dir=$(CURDIR)
 +
  PHONY += $(MAKECMDGOALS) sub-make
  
  $(filter-out _all sub-make $(CURDIR)/Makefile, $(MAKECMDGOALS)) _all: sub-make
@@@ -305,7 -299,19 +305,7 @@@ KERNELRELEASE = $(shell cat include/con
  KERNELVERSION = $(VERSION)$(if $(PATCHLEVEL),.$(PATCHLEVEL)$(if $(SUBLEVEL),.$(SUBLEVEL)))$(EXTRAVERSION)
  export VERSION PATCHLEVEL SUBLEVEL KERNELRELEASE KERNELVERSION
  
 -# SUBARCH tells the usermode build what the underlying arch is.  That is set
 -# first, and if a usermode build is happening, the "ARCH=um" on the command
 -# line overrides the setting of ARCH below.  If a native build is happening,
 -# then ARCH is assigned, getting whatever value it gets normally, and
 -# SUBARCH is subsequently ignored.
 -
 -SUBARCH := $(shell uname -m | sed -e s/i.86/x86/ -e s/x86_64/x86/ \
 -                                -e s/sun4u/sparc64/ \
 -                                -e s/arm.*/arm/ -e s/sa110/arm/ \
 -                                -e s/s390x/s390/ -e s/parisc64/parisc/ \
 -                                -e s/ppc.*/powerpc/ -e s/mips.*/mips/ \
 -                                -e s/sh[234].*/sh/ -e s/aarch64.*/arm64/ \
 -                                -e s/riscv.*/riscv/)
 +include scripts/subarch.include
  
  # Cross compiling and selecting different set of gcc/bin-utils
  # ---------------------------------------------------------------------------
@@@ -482,21 -488,20 +482,21 @@@ PHONY += outputmakefil
  outputmakefile:
  ifneq ($(KBUILD_SRC),)
        $(Q)ln -fsn $(srctree) source
 -      $(Q)$(CONFIG_SHELL) $(srctree)/scripts/mkmakefile \
 -          $(srctree) $(objtree) $(VERSION) $(PATCHLEVEL)
 +      $(Q)$(CONFIG_SHELL) $(srctree)/scripts/mkmakefile $(srctree)
  endif
  
  ifeq ($(cc-name),clang)
  ifneq ($(CROSS_COMPILE),)
  CLANG_TARGET  := --target=$(notdir $(CROSS_COMPILE:%-=%))
 -GCC_TOOLCHAIN := $(realpath $(dir $(shell which $(LD)))/..)
 +GCC_TOOLCHAIN_DIR := $(dir $(shell which $(LD)))
 +CLANG_PREFIX  := --prefix=$(GCC_TOOLCHAIN_DIR)
 +GCC_TOOLCHAIN := $(realpath $(GCC_TOOLCHAIN_DIR)/..)
  endif
  ifneq ($(GCC_TOOLCHAIN),)
  CLANG_GCC_TC  := --gcc-toolchain=$(GCC_TOOLCHAIN)
  endif
 -KBUILD_CFLAGS += $(CLANG_TARGET) $(CLANG_GCC_TC)
 -KBUILD_AFLAGS += $(CLANG_TARGET) $(CLANG_GCC_TC)
 +KBUILD_CFLAGS += $(CLANG_TARGET) $(CLANG_GCC_TC) $(CLANG_PREFIX)
 +KBUILD_AFLAGS += $(CLANG_TARGET) $(CLANG_GCC_TC) $(CLANG_PREFIX)
  KBUILD_CFLAGS += $(call cc-option, -no-integrated-as)
  KBUILD_AFLAGS += $(call cc-option, -no-integrated-as)
  endif
@@@ -611,11 -616,6 +611,11 @@@ CFLAGS_GCOV      := -fprofile-arcs -ftest-co
        $(call cc-disable-warning,maybe-uninitialized,)
  export CFLAGS_GCOV
  
 +# The arch Makefiles can override CC_FLAGS_FTRACE. We may also append it later.
 +ifdef CONFIG_FUNCTION_TRACER
 +  CC_FLAGS_FTRACE := -pg
 +endif
 +
  # The arch Makefile can set ARCH_{CPP,A,C}FLAGS to override the default
  # values of the respective KBUILD_* variables
  ARCH_CPPFLAGS :=
@@@ -718,7 -718,7 +718,7 @@@ els
  
  # These warnings generated too much noise in a regular build.
  # Use make W=1 to enable them (see scripts/Makefile.extrawarn)
 -KBUILD_CFLAGS += $(call cc-disable-warning, unused-but-set-variable)
 +KBUILD_CFLAGS += -Wno-unused-but-set-variable
  endif
  
  KBUILD_CFLAGS += $(call cc-disable-warning, unused-const-variable)
@@@ -755,6 -755,9 +755,6 @@@ KBUILD_CFLAGS      += $(call cc-option, -fe
  endif
  
  ifdef CONFIG_FUNCTION_TRACER
 -ifndef CC_FLAGS_FTRACE
 -CC_FLAGS_FTRACE := -pg
 -endif
  ifdef CONFIG_FTRACE_MCOUNT_RECORD
    # gcc 5 supports generating the mcount tables directly
    ifeq ($(call cc-option-yn,-mrecord-mcount),y)
@@@ -799,10 -802,13 +799,13 @@@ endi
  NOSTDINC_FLAGS += -nostdinc -isystem $(shell $(CC) -print-file-name=include)
  
  # warn about C99 declaration after statement
 -KBUILD_CFLAGS += $(call cc-option,-Wdeclaration-after-statement,)
 +KBUILD_CFLAGS += -Wdeclaration-after-statement
  
+ # Variable Length Arrays (VLAs) should not be used anywhere in the kernel
+ KBUILD_CFLAGS += $(call cc-option,-Wvla)
  # disable pointer signed / unsigned warnings in gcc 4.0
 -KBUILD_CFLAGS += $(call cc-disable-warning, pointer-sign)
 +KBUILD_CFLAGS += -Wno-pointer-sign
  
  # disable stringop warnings in gcc 8+
  KBUILD_CFLAGS += $(call cc-disable-warning, stringop-truncation)
@@@ -1068,7 -1074,7 +1071,7 @@@ include/config/kernel.release: $(srctre
  # Carefully list dependencies so we do not try to build scripts twice
  # in parallel
  PHONY += scripts
 -scripts: scripts_basic asm-generic gcc-plugins $(autoksyms_h)
 +scripts: scripts_basic scripts_dtc asm-generic gcc-plugins $(autoksyms_h)
        $(Q)$(MAKE) $(build)=$(@)
  
  # Things we need to do before we recursively start building the kernel
  # version.h and scripts_basic is processed / created.
  
  # Listed in dependency order
 -PHONY += prepare archprepare prepare0 prepare1 prepare2 prepare3
 +PHONY += prepare archprepare macroprepare prepare0 prepare1 prepare2 prepare3
  
  # prepare3 is used to check if we are building in a separate output directory,
  # and if so do:
@@@ -1101,9 -1107,7 +1104,9 @@@ prepare2: prepare3 outputmakefile asm-g
  prepare1: prepare2 $(version_h) $(autoksyms_h) include/generated/utsrelease.h
        $(cmd_crmodverdir)
  
 -archprepare: archheaders archscripts prepare1 scripts_basic
 +macroprepare: prepare1 archmacros
 +
 +archprepare: archheaders archscripts macroprepare scripts_basic
  
  prepare0: archprepare gcc-plugins
        $(Q)$(MAKE) $(build)=.
@@@ -1171,9 -1175,6 +1174,9 @@@ archheaders
  PHONY += archscripts
  archscripts:
  
 +PHONY += archmacros
 +archmacros:
 +
  PHONY += __headers
  __headers: $(version_h) scripts_basic uapi-asm-generic archheaders archscripts
        $(Q)$(MAKE) $(build)=scripts build_unifdef
@@@ -1217,35 -1218,6 +1220,35 @@@ kselftest-merge
                $(srctree)/tools/testing/selftests/*/config
        +$(Q)$(MAKE) -f $(srctree)/Makefile olddefconfig
  
 +# ---------------------------------------------------------------------------
 +# Devicetree files
 +
 +ifneq ($(wildcard $(srctree)/arch/$(SRCARCH)/boot/dts/),)
 +dtstree := arch/$(SRCARCH)/boot/dts
 +endif
 +
 +ifneq ($(dtstree),)
 +
 +%.dtb: prepare3 scripts_dtc
 +      $(Q)$(MAKE) $(build)=$(dtstree) $(dtstree)/$@
 +
 +PHONY += dtbs dtbs_install
 +dtbs: prepare3 scripts_dtc
 +      $(Q)$(MAKE) $(build)=$(dtstree)
 +
 +dtbs_install:
 +      $(Q)$(MAKE) $(dtbinst)=$(dtstree)
 +
 +ifdef CONFIG_OF_EARLY_FLATTREE
 +all: dtbs
 +endif
 +
 +endif
 +
 +PHONY += scripts_dtc
 +scripts_dtc: scripts_basic
 +      $(Q)$(MAKE) $(build)=scripts/dtc
 +
  # ---------------------------------------------------------------------------
  # Modules
  
@@@ -1455,12 -1427,6 +1458,12 @@@ help
        @echo  '  kselftest-merge - Merge all the config dependencies of kselftest to existing'
        @echo  '                    .config.'
        @echo  ''
 +      @$(if $(dtstree), \
 +              echo 'Devicetree:'; \
 +              echo '* dtbs            - Build device tree blobs for enabled boards'; \
 +              echo '  dtbs_install    - Install dtbs to $(INSTALL_DTBS_PATH)'; \
 +              echo '')
 +
        @echo 'Userspace tools targets:'
        @echo '  use "make tools/help"'
        @echo '  or  "cd tools; make help"'
@@@ -1652,6 -1618,9 +1655,6 @@@ namespacecheck
  export_report:
        $(PERL) $(srctree)/scripts/export_report.pl
  
 -endif #ifeq ($(config-targets),1)
 -endif #ifeq ($(mixed-targets),1)
 -
  PHONY += checkstack kernelrelease kernelversion image_name
  
  # UML needs a little special treatment here.  It wants to use the host
@@@ -1758,15 -1727,14 +1761,15 @@@ cmd_crmodverdir = $(Q)mkdir -p $(MODVER
                    $(if $(KBUILD_MODULES),; rm -f $(MODVERDIR)/*)
  
  # read all saved command lines
 -
 -cmd_files := $(wildcard .*.cmd $(foreach f,$(sort $(targets)),$(dir $(f)).$(notdir $(f)).cmd))
 +cmd_files := $(wildcard .*.cmd)
  
  ifneq ($(cmd_files),)
    $(cmd_files): ;     # Do not try to update included dependency files
    include $(cmd_files)
  endif
  
 +endif   # ifeq ($(config-targets),1)
 +endif   # ifeq ($(mixed-targets),1)
  endif # skip-makefile
  
  PHONY += FORCE
diff --combined include/linux/compiler.h
index 1921545c6351d03bfa356775c03ccfc371bda3dd,87c776c3ce73251c3847a9c94ceec1754651af11..4170fcee5adb30780dae6c06a5b34bcd57855d02
@@@ -99,13 -99,22 +99,13 @@@ void ftrace_likely_update(struct ftrace
   * unique, to convince GCC not to merge duplicate inline asm statements.
   */
  #define annotate_reachable() ({                                               \
 -      asm volatile("%c0:\n\t"                                         \
 -                   ".pushsection .discard.reachable\n\t"              \
 -                   ".long %c0b - .\n\t"                               \
 -                   ".popsection\n\t" : : "i" (__COUNTER__));          \
 +      asm volatile("ANNOTATE_REACHABLE counter=%c0"                   \
 +                   : : "i" (__COUNTER__));                            \
  })
  #define annotate_unreachable() ({                                     \
 -      asm volatile("%c0:\n\t"                                         \
 -                   ".pushsection .discard.unreachable\n\t"            \
 -                   ".long %c0b - .\n\t"                               \
 -                   ".popsection\n\t" : : "i" (__COUNTER__));          \
 +      asm volatile("ANNOTATE_UNREACHABLE counter=%c0"                 \
 +                   : : "i" (__COUNTER__));                            \
  })
 -#define ASM_UNREACHABLE                                                       \
 -      "999:\n\t"                                                      \
 -      ".pushsection .discard.unreachable\n\t"                         \
 -      ".long 999b - .\n\t"                                            \
 -      ".popsection\n\t"
  #else
  #define annotate_reachable()
  #define annotate_unreachable()
@@@ -290,45 -299,6 +290,45 @@@ static inline void *offset_to_ptr(cons
        return (void *)((unsigned long)off + *off);
  }
  
 +#else /* __ASSEMBLY__ */
 +
 +#ifdef __KERNEL__
 +#ifndef LINKER_SCRIPT
 +
 +#ifdef CONFIG_STACK_VALIDATION
 +.macro ANNOTATE_UNREACHABLE counter:req
 +\counter:
 +      .pushsection .discard.unreachable
 +      .long \counter\()b -.
 +      .popsection
 +.endm
 +
 +.macro ANNOTATE_REACHABLE counter:req
 +\counter:
 +      .pushsection .discard.reachable
 +      .long \counter\()b -.
 +      .popsection
 +.endm
 +
 +.macro ASM_UNREACHABLE
 +999:
 +      .pushsection .discard.unreachable
 +      .long 999b - .
 +      .popsection
 +.endm
 +#else /* CONFIG_STACK_VALIDATION */
 +.macro ANNOTATE_UNREACHABLE counter:req
 +.endm
 +
 +.macro ANNOTATE_REACHABLE counter:req
 +.endm
 +
 +.macro ASM_UNREACHABLE
 +.endm
 +#endif /* CONFIG_STACK_VALIDATION */
 +
 +#endif /* LINKER_SCRIPT */
 +#endif /* __KERNEL__ */
  #endif /* __ASSEMBLY__ */
  
  #ifndef __optimize
  #endif
  #ifndef __compiletime_error
  # define __compiletime_error(message)
- /*
-  * Sparse complains of variable sized arrays due to the temporary variable in
-  * __compiletime_assert. Unfortunately we can't just expand it out to make
-  * sparse see a constant array size without breaking compiletime_assert on old
-  * versions of GCC (e.g. 4.2.4), so hide the array from sparse altogether.
-  */
- # ifndef __CHECKER__
- #  define __compiletime_error_fallback(condition) \
-       do { ((void)sizeof(char[1 - 2 * condition])); } while (0)
- # endif
- #endif
- #ifndef __compiletime_error_fallback
- # define __compiletime_error_fallback(condition) do { } while (0)
  #endif
  
  #ifdef __OPTIMIZE__
  # define __compiletime_assert(condition, msg, prefix, suffix)         \
        do {                                                            \
-               int __cond = !(condition);                              \
                extern void prefix ## suffix(void) __compiletime_error(msg); \
-               if (__cond)                                             \
+               if (!(condition))                                       \
                        prefix ## suffix();                             \
-               __compiletime_error_fallback(__cond);                   \
        } while (0)
  #else
  # define __compiletime_assert(condition, msg, prefix, suffix) do { } while (0)
diff --combined lib/Makefile
index 3d341f59f756f7af070c8483ce22834f4ee8b94c,8e0aca8a2f099dcbcdd9c5250841217a5561727c..988949c4fd3a7f49df646f3fcd195d0d1ad01dec
@@@ -18,13 -18,13 +18,13 @@@ KCOV_INSTRUMENT_debugobjects.o := 
  KCOV_INSTRUMENT_dynamic_debug.o := n
  
  lib-y := ctype.o string.o vsprintf.o cmdline.o \
 -       rbtree.o radix-tree.o timerqueue.o\
 +       rbtree.o radix-tree.o timerqueue.o xarray.o \
         idr.o int_sqrt.o extable.o \
         sha1.o chacha20.o irq_regs.o argv_split.o \
         flex_proportions.o ratelimit.o show_mem.o \
         is_single_threaded.o plist.o decompress.o kobject_uevent.o \
         earlycpio.o seq_buf.o siphash.o dec_and_lock.o \
 -       nmi_backtrace.o nodemask.o win_minmax.o
 +       nmi_backtrace.o nodemask.o win_minmax.o memcat_p.o
  
  lib-$(CONFIG_PRINTK) += dump_stack.o
  lib-$(CONFIG_MMU) += ioremap.o
@@@ -53,7 -53,9 +53,9 @@@ obj-$(CONFIG_TEST_HASH) += test_hash.o 
  obj-$(CONFIG_TEST_IDA) += test_ida.o
  obj-$(CONFIG_TEST_KASAN) += test_kasan.o
  CFLAGS_test_kasan.o += -fno-builtin
+ CFLAGS_test_kasan.o += $(call cc-disable-warning, vla)
  obj-$(CONFIG_TEST_UBSAN) += test_ubsan.o
+ CFLAGS_test_ubsan.o += $(call cc-disable-warning, vla)
  UBSAN_SANITIZE_test_ubsan.o := y
  obj-$(CONFIG_TEST_KSTRTOX) += test-kstrtox.o
  obj-$(CONFIG_TEST_LIST_SORT) += test_list_sort.o
@@@ -68,11 -70,9 +70,11 @@@ obj-$(CONFIG_TEST_PRINTF) += test_print
  obj-$(CONFIG_TEST_BITMAP) += test_bitmap.o
  obj-$(CONFIG_TEST_BITFIELD) += test_bitfield.o
  obj-$(CONFIG_TEST_UUID) += test_uuid.o
 +obj-$(CONFIG_TEST_XARRAY) += test_xarray.o
  obj-$(CONFIG_TEST_PARMAN) += test_parman.o
  obj-$(CONFIG_TEST_KMOD) += test_kmod.o
  obj-$(CONFIG_TEST_DEBUG_VIRTUAL) += test_debug_virtual.o
 +obj-$(CONFIG_TEST_MEMCAT_P) += test_memcat_p.o
  
  ifeq ($(CONFIG_DEBUG_KOBJECT),y)
  CFLAGS_kobject.o += -DDEBUG
@@@ -121,6 -121,7 +123,6 @@@ obj-$(CONFIG_ZLIB_INFLATE) += zlib_infl
  obj-$(CONFIG_ZLIB_DEFLATE) += zlib_deflate/
  obj-$(CONFIG_REED_SOLOMON) += reed_solomon/
  obj-$(CONFIG_BCH) += bch.o
 -CFLAGS_bch.o := $(call cc-option,-Wframe-larger-than=4500)
  obj-$(CONFIG_LZO_COMPRESS) += lzo/
  obj-$(CONFIG_LZO_DECOMPRESS) += lzo/
  obj-$(CONFIG_LZ4_COMPRESS) += lz4/
@@@ -272,4 -273,3 +274,4 @@@ obj-$(CONFIG_GENERIC_LIB_LSHRDI3) += ls
  obj-$(CONFIG_GENERIC_LIB_MULDI3) += muldi3.o
  obj-$(CONFIG_GENERIC_LIB_CMPDI2) += cmpdi2.o
  obj-$(CONFIG_GENERIC_LIB_UCMPDI2) += ucmpdi2.o
 +obj-$(CONFIG_GENERIC_LIB_UMODDI3) += umoddi3.o udivmoddi4.o