Merge tag 'meminit-v5.2-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees...
authorLinus Torvalds <torvalds@linux-foundation.org>
Tue, 7 May 2019 19:44:49 +0000 (12:44 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Tue, 7 May 2019 19:44:49 +0000 (12:44 -0700)
Pull compiler-based variable initialization updates from Kees Cook:
 "This is effectively part of my gcc-plugins tree, but as this adds some
  Clang support, it felt weird to still call it "gcc-plugins". :)

  This consolidates Kconfig for the existing stack variable
  initialization (via structleak and stackleak gcc plugins) and adds
  Alexander Potapenko's support for Clang's new similar functionality.

  Summary:

   - Consolidate memory initialization Kconfigs (Kees)

   - Implement support for Clang's stack variable auto-init (Alexander)"

* tag 'meminit-v5.2-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux:
  security: Implement Clang's stack initialization
  security: Move stackleak config to Kconfig.hardening
  security: Create "kernel hardening" config area

1  2 
Makefile
security/Kconfig

diff --combined Makefile
+++ b/Makefile
@@@ -2,7 -2,7 +2,7 @@@
  VERSION = 5
  PATCHLEVEL = 1
  SUBLEVEL = 0
 -EXTRAVERSION = -rc2
 +EXTRAVERSION =
  NAME = Shy Crocodile
  
  # *DOCUMENTATION*
@@@ -31,12 -31,26 +31,12 @@@ _all
  # descending is started. They are now explicitly listed as the
  # prepare rule.
  
 -# Ugly workaround for Debian make-kpkg:
 -# make-kpkg directly includes the top Makefile of Linux kernel. In such a case,
 -# skip sub-make to support debian_* targets in ruleset/kernel_version.mk, but
 -# displays warning to discourage such abusage.
 -ifneq ($(word 2, $(MAKEFILE_LIST)),)
 -$(warning Do not include top Makefile of Linux Kernel)
 -sub-make-done := 1
 -MAKEFLAGS += -rR
 -endif
 -
 -ifneq ($(sub-make-done),1)
 +ifneq ($(sub_make_done),1)
  
  # Do not use make's built-in rules and variables
  # (this increases performance and avoids hard-to-debug behaviour)
  MAKEFLAGS += -rR
  
 -# 'MAKEFLAGS += -rR' does not become immediately effective for old
 -# GNU Make versions. Cancel implicit rules for this Makefile.
 -$(lastword $(MAKEFILE_LIST)): ;
 -
  # Avoid funny character set dependencies
  unexport LC_ALL
  LC_COLLATE=C
@@@ -139,7 -153,6 +139,7 @@@ $(if $(KBUILD_OUTPUT),, 
  # 'sub-make' below.
  MAKEFLAGS += --include-dir=$(CURDIR)
  
 +need-sub-make := 1
  else
  
  # Do not print "Entering directory ..." at all for in-tree build.
@@@ -147,18 -160,6 +147,18 @@@ MAKEFLAGS += --no-print-director
  
  endif # ifneq ($(KBUILD_OUTPUT),)
  
 +ifneq ($(filter 3.%,$(MAKE_VERSION)),)
 +# 'MAKEFLAGS += -rR' does not immediately become effective for GNU Make 3.x
 +# We need to invoke sub-make to avoid implicit rules in the top Makefile.
 +need-sub-make := 1
 +# Cancel implicit rules for this Makefile.
 +$(lastword $(MAKEFILE_LIST)): ;
 +endif
 +
 +export sub_make_done := 1
 +
 +ifeq ($(need-sub-make),1)
 +
  PHONY += $(MAKECMDGOALS) sub-make
  
  $(filter-out _all sub-make $(CURDIR)/Makefile, $(MAKECMDGOALS)) _all: sub-make
  
  # Invoke a second make in the output directory, passing relevant variables
  sub-make:
 -      $(Q)$(MAKE) sub-make-done=1 \
 +      $(Q)$(MAKE) \
        $(if $(KBUILD_OUTPUT),-C $(KBUILD_OUTPUT) KBUILD_SRC=$(CURDIR)) \
        -f $(CURDIR)/Makefile $(filter-out _all sub-make,$(MAKECMDGOALS))
  
 -else # sub-make-done
 +endif # need-sub-make
 +endif # sub_make_done
 +
  # We process the rest of the Makefile if this is the final invocation of make
 +ifeq ($(need-sub-make),)
  
  # Do not print "Entering directory ...",
  # but we want to display it when entering to the output directory
@@@ -499,8 -497,7 +499,8 @@@ outputmakefile
  ifneq ($(KBUILD_SRC),)
        $(Q)ln -fsn $(srctree) source
        $(Q)$(CONFIG_SHELL) $(srctree)/scripts/mkmakefile $(srctree)
 -      $(Q){ echo "# this is build directory, ignore it"; echo "*"; } > .gitignore
 +      $(Q)test -e .gitignore || \
 +      { echo "# this is build directory, ignore it"; echo "*"; } > .gitignore
  endif
  
  ifneq ($(shell $(CC) --version 2>&1 | head -n 1 | grep clang),)
@@@ -678,10 -675,9 +678,10 @@@ KBUILD_CFLAGS    += $(call cc-disable-warn
  KBUILD_CFLAGS += $(call cc-disable-warning, format-truncation)
  KBUILD_CFLAGS += $(call cc-disable-warning, format-overflow)
  KBUILD_CFLAGS += $(call cc-disable-warning, int-in-bool-context)
 +KBUILD_CFLAGS += $(call cc-disable-warning, address-of-packed-member)
  
  ifdef CONFIG_CC_OPTIMIZE_FOR_SIZE
 -KBUILD_CFLAGS += $(call cc-option,-Oz,-Os)
 +KBUILD_CFLAGS += -Os
  else
  KBUILD_CFLAGS   += -O2
  endif
@@@ -720,6 -716,7 +720,6 @@@ ifdef CONFIG_CC_IS_CLAN
  KBUILD_CPPFLAGS += $(call cc-option,-Qunused-arguments,)
  KBUILD_CFLAGS += $(call cc-disable-warning, format-invalid-specifier)
  KBUILD_CFLAGS += $(call cc-disable-warning, gnu)
 -KBUILD_CFLAGS += $(call cc-disable-warning, address-of-packed-member)
  # Quiet clang warning: comparison of unsigned expression < 0 is always false
  KBUILD_CFLAGS += $(call cc-disable-warning, tautological-compare)
  # CLANG uses a _MergedGlobals as optimization, but this breaks modpost, as the
@@@ -748,6 -745,11 +748,11 @@@ KBUILD_CFLAGS    += -fomit-frame-pointe
  endif
  endif
  
+ # Initialize all stack variables with a pattern, if desired.
+ ifdef CONFIG_INIT_STACK_ALL
+ KBUILD_CFLAGS += -ftrivial-auto-var-init=pattern
+ endif
  DEBUG_CFLAGS  := $(call cc-option, -fno-var-tracking-assignments)
  
  ifdef CONFIG_DEBUG_INFO
@@@ -811,10 -813,6 +816,10 @@@ KBUILD_CFLAGS_KERNEL += -ffunction-sect
  LDFLAGS_vmlinux += --gc-sections
  endif
  
 +ifdef CONFIG_LIVEPATCH
 +KBUILD_CFLAGS += $(call cc-option, -flive-patching=inline-clone)
 +endif
 +
  # arch Makefile may override CC so keep this after arch Makefile is included
  NOSTDINC_FLAGS += -nostdinc -isystem $(shell $(CC) -print-file-name=include)
  
@@@ -957,11 -955,9 +962,11 @@@ mod_sign_cmd = tru
  endif
  export mod_sign_cmd
  
 +HOST_LIBELF_LIBS = $(shell pkg-config libelf --libs 2>/dev/null || echo -lelf)
 +
  ifdef CONFIG_STACK_VALIDATION
    has_libelf := $(call try-run,\
 -              echo "int main() {}" | $(HOSTCC) -xc -o /dev/null -lelf -,1,0)
 +              echo "int main() {}" | $(HOSTCC) -xc -o /dev/null $(HOST_LIBELF_LIBS) -,1,0)
    ifeq ($(has_libelf),1)
      objtool_target := tools/objtool FORCE
    else
@@@ -1766,7 -1762,7 +1771,7 @@@ existing-targets := $(wildcard $(sort $
  
  endif   # ifeq ($(config-targets),1)
  endif   # ifeq ($(mixed-targets),1)
 -endif   # sub-make-done
 +endif   # need-sub-make
  
  PHONY += FORCE
  FORCE:
diff --combined security/Kconfig
@@@ -239,46 -239,8 +239,46 @@@ source "security/safesetid/Kconfig
  
  source "security/integrity/Kconfig"
  
 +choice
 +      prompt "First legacy 'major LSM' to be initialized"
 +      default DEFAULT_SECURITY_SELINUX if SECURITY_SELINUX
 +      default DEFAULT_SECURITY_SMACK if SECURITY_SMACK
 +      default DEFAULT_SECURITY_TOMOYO if SECURITY_TOMOYO
 +      default DEFAULT_SECURITY_APPARMOR if SECURITY_APPARMOR
 +      default DEFAULT_SECURITY_DAC
 +
 +      help
 +        This choice is there only for converting CONFIG_DEFAULT_SECURITY
 +        in old kernel configs to CONFIG_LSM in new kernel configs. Don't
 +        change this choice unless you are creating a fresh kernel config,
 +        for this choice will be ignored after CONFIG_LSM has been set.
 +
 +        Selects the legacy "major security module" that will be
 +        initialized first. Overridden by non-default CONFIG_LSM.
 +
 +      config DEFAULT_SECURITY_SELINUX
 +              bool "SELinux" if SECURITY_SELINUX=y
 +
 +      config DEFAULT_SECURITY_SMACK
 +              bool "Simplified Mandatory Access Control" if SECURITY_SMACK=y
 +
 +      config DEFAULT_SECURITY_TOMOYO
 +              bool "TOMOYO" if SECURITY_TOMOYO=y
 +
 +      config DEFAULT_SECURITY_APPARMOR
 +              bool "AppArmor" if SECURITY_APPARMOR=y
 +
 +      config DEFAULT_SECURITY_DAC
 +              bool "Unix Discretionary Access Controls"
 +
 +endchoice
 +
  config LSM
        string "Ordered list of enabled LSMs"
 +      default "yama,loadpin,safesetid,integrity,smack,selinux,tomoyo,apparmor" if DEFAULT_SECURITY_SMACK
 +      default "yama,loadpin,safesetid,integrity,apparmor,selinux,smack,tomoyo" if DEFAULT_SECURITY_APPARMOR
 +      default "yama,loadpin,safesetid,integrity,tomoyo" if DEFAULT_SECURITY_TOMOYO
 +      default "yama,loadpin,safesetid,integrity" if DEFAULT_SECURITY_DAC
        default "yama,loadpin,safesetid,integrity,selinux,smack,tomoyo,apparmor"
        help
          A comma-separated list of LSMs, in initialization order.
  
          If unsure, leave this as the default.
  
+ source "security/Kconfig.hardening"
  endmenu