kbuild: remove cc-option test of -fno-stack-protector
authorMasahiro Yamada <masahiroy@kernel.org>
Fri, 26 Jun 2020 18:59:12 +0000 (03:59 +0900)
committerMasahiro Yamada <masahiroy@kernel.org>
Tue, 7 Jul 2020 02:13:10 +0000 (11:13 +0900)
Some Makefiles already pass -fno-stack-protector unconditionally.
For example, arch/arm64/kernel/vdso/Makefile, arch/x86/xen/Makefile.

No problem report so far about hard-coding this option. So, we can
assume all supported compilers know -fno-stack-protector.

GCC 4.8 and Clang support this option (https://godbolt.org/z/_HDGzN)

Get rid of cc-option from -fno-stack-protector.

Remove CONFIG_CC_HAS_STACKPROTECTOR_NONE, which is always 'y'.

Note:
arch/mips/vdso/Makefile adds -fno-stack-protector twice, first
unconditionally, and second conditionally. I removed the second one.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Reviewed-by: Kees Cook <keescook@chromium.org>
Acked-by: Ard Biesheuvel <ardb@kernel.org>
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
23 files changed:
Documentation/kbuild/kconfig-language.rst
Makefile
arch/Kconfig
arch/arm/boot/compressed/Makefile
arch/mips/vdso/Makefile
arch/powerpc/kernel/Makefile
arch/powerpc/platforms/powermac/Makefile
arch/sparc/vdso/Makefile
arch/um/Makefile
arch/x86/Makefile
arch/x86/boot/compressed/Makefile
arch/x86/entry/vdso/Makefile
arch/x86/kernel/cpu/Makefile
arch/x86/lib/Makefile
arch/x86/mm/Makefile
arch/x86/power/Makefile
arch/x86/purgatory/Makefile
arch/x86/um/vdso/Makefile
arch/x86/xen/Makefile
drivers/firmware/efi/libstub/Makefile
drivers/xen/Makefile
lib/Makefile
mm/kasan/Makefile

index a1601ec3317b49dab521f06296f9b7427f8795eb..2538e7cb08e6bc0ab71af53901253bcdb10cdf0c 100644 (file)
@@ -540,8 +540,8 @@ followed by a test macro::
 If you need to expose a compiler capability to makefiles and/or C source files,
 `CC_HAS_` is the recommended prefix for the config option::
 
-  config CC_HAS_STACKPROTECTOR_NONE
-       def_bool $(cc-option,-fno-stack-protector)
+  config CC_HAS_ASM_GOTO
+       def_bool $(success,$(srctree)/scripts/gcc-goto.sh $(CC))
 
 Build as module only
 ~~~~~~~~~~~~~~~~~~~~
index fe0164a654c769200612a921b1432231c69580f3..ea283c9bbaa897db8c8467e0716f2a97cdc59923 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -762,7 +762,7 @@ ifneq ($(CONFIG_FRAME_WARN),0)
 KBUILD_CFLAGS += -Wframe-larger-than=$(CONFIG_FRAME_WARN)
 endif
 
-stackp-flags-$(CONFIG_CC_HAS_STACKPROTECTOR_NONE) := -fno-stack-protector
+stackp-flags-y                                    := -fno-stack-protector
 stackp-flags-$(CONFIG_STACKPROTECTOR)             := -fstack-protector
 stackp-flags-$(CONFIG_STACKPROTECTOR_STRONG)      := -fstack-protector-strong
 
index 8cc35dc556c72e9cfba7d92dce292d9897f36a12..1ea61290900ab481eebc42d645d83fd05a9766b1 100644 (file)
@@ -478,9 +478,6 @@ config HAVE_STACKPROTECTOR
          An arch should select this symbol if:
          - it has implemented a stack canary (e.g. __stack_chk_guard)
 
-config CC_HAS_STACKPROTECTOR_NONE
-       def_bool $(cc-option,-fno-stack-protector)
-
 config STACKPROTECTOR
        bool "Stack Protector buffer overflow detection"
        depends on HAVE_STACKPROTECTOR
index 00602a6fba04733ffb9aa64dbf0022e5469db8b9..cb7a56c6723c1fc39a5fd7b9cb49c39385d3e812 100644 (file)
@@ -84,9 +84,8 @@ endif
 
 # -fstack-protector-strong triggers protection checks in this code,
 # but it is being used too early to link to meaningful stack_chk logic.
-nossp-flags-$(CONFIG_CC_HAS_STACKPROTECTOR_NONE) := -fno-stack-protector
 $(foreach o, $(libfdt_objs) atags_to_fdt.o, \
-       $(eval CFLAGS_$(o) := -I $(srctree)/scripts/dtc/libfdt $(nossp-flags-y)))
+       $(eval CFLAGS_$(o) := -I $(srctree)/scripts/dtc/libfdt -fno-stack-protector))
 
 # These were previously generated C files. When you are building the kernel
 # with O=, make sure to remove the stale files in the output tree. Otherwise,
index 2e64c7600eead1b809c8815ff28c2dc7185c2061..57fe8323528193ba4326271ac00fa114403b3277 100644 (file)
@@ -35,8 +35,7 @@ cflags-vdso := $(ccflags-vdso) \
        -O3 -g -fPIC -fno-strict-aliasing -fno-common -fno-builtin -G 0 \
        -mrelax-pic-calls $(call cc-option, -mexplicit-relocs) \
        -fno-stack-protector -fno-jump-tables -DDISABLE_BRANCH_PROFILING \
-       $(call cc-option, -fno-asynchronous-unwind-tables) \
-       $(call cc-option, -fno-stack-protector)
+       $(call cc-option, -fno-asynchronous-unwind-tables)
 aflags-vdso := $(ccflags-vdso) \
        -D__ASSEMBLY__ -Wa,-gdwarf-2
 
index 244542ae2a915698a246df455f9416040e7ed163..3a83f2b876a5dce1ae0ac55d9d30f4139c7042f5 100644 (file)
@@ -16,7 +16,7 @@ CFLAGS_prom_init.o += $(DISABLE_LATENT_ENTROPY_PLUGIN)
 CFLAGS_btext.o += $(DISABLE_LATENT_ENTROPY_PLUGIN)
 CFLAGS_prom.o += $(DISABLE_LATENT_ENTROPY_PLUGIN)
 
-CFLAGS_prom_init.o += $(call cc-option, -fno-stack-protector)
+CFLAGS_prom_init.o += -fno-stack-protector
 CFLAGS_prom_init.o += -DDISABLE_BRANCH_PROFILING
 CFLAGS_prom_init.o += -ffreestanding
 
index f4247ade71cafccdf8b3fd5ea4b6b02639fe0e32..cf85f0662d0ddbe77590701556a98cfd97de5867 100644 (file)
@@ -1,6 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0
 CFLAGS_bootx_init.o            += -fPIC
-CFLAGS_bootx_init.o            += $(call cc-option, -fno-stack-protector)
+CFLAGS_bootx_init.o            += -fno-stack-protector
 
 KASAN_SANITIZE_bootx_init.o := n
 
index 708cb6304c2db782d135365b59d44189530b5fa8..f44355e46f31f4bbbfc888b012d3f053a0ed45a9 100644 (file)
@@ -54,7 +54,7 @@ $(obj)/vdso-image-%.c: $(obj)/vdso%.so.dbg $(obj)/vdso%.so $(obj)/vdso2c FORCE
 # optimize sibling calls.
 #
 CFL := $(PROFILING) -mcmodel=medlow -fPIC -O2 -fasynchronous-unwind-tables -m64 \
-       $(filter -g%,$(KBUILD_CFLAGS)) $(call cc-option, -fno-stack-protector) \
+       $(filter -g%,$(KBUILD_CFLAGS)) -fno-stack-protector \
        -fno-omit-frame-pointer -foptimize-sibling-calls \
        -DDISABLE_BRANCH_PROFILING -DBUILD_VDSO
 
@@ -93,7 +93,7 @@ KBUILD_CFLAGS_32 := $(filter-out -fno-pic,$(KBUILD_CFLAGS_32))
 KBUILD_CFLAGS_32 := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS_32))
 KBUILD_CFLAGS_32 := $(filter-out $(SPARC_REG_CFLAGS),$(KBUILD_CFLAGS_32))
 KBUILD_CFLAGS_32 += -m32 -msoft-float -fpic
-KBUILD_CFLAGS_32 += $(call cc-option, -fno-stack-protector)
+KBUILD_CFLAGS_32 += -fno-stack-protector
 KBUILD_CFLAGS_32 += $(call cc-option, -foptimize-sibling-calls)
 KBUILD_CFLAGS_32 += -fno-omit-frame-pointer
 KBUILD_CFLAGS_32 += -DDISABLE_BRANCH_PROFILING
index 3f27aa3ec0a6f83bd64bdca035be3e29408caf6f..1cea46ff9bb78dd1a397e4fceb4a80442c2cc4c9 100644 (file)
@@ -121,8 +121,7 @@ LINK-$(CONFIG_LD_SCRIPT_STATIC) += -static
 LINK-$(CONFIG_LD_SCRIPT_DYN) += -Wl,-rpath,/lib $(call cc-option, -no-pie)
 
 CFLAGS_NO_HARDENING := $(call cc-option, -fno-PIC,) $(call cc-option, -fno-pic,) \
-       $(call cc-option, -fno-stack-protector,) \
-       $(call cc-option, -fno-stack-protector-all,)
+       -fno-stack-protector $(call cc-option, -fno-stack-protector-all)
 
 # Options used by linker script
 export LDS_START      := $(START)
index 00e378de8bc0b3b9feabe378845f966ce2ff1a74..89c3cdfba7535e8bbdc0b968c81e56c28d51b028 100644 (file)
@@ -37,7 +37,7 @@ REALMODE_CFLAGS       := $(M16_CFLAGS) -g -Os -DDISABLE_BRANCH_PROFILING \
                   -mno-mmx -mno-sse
 
 REALMODE_CFLAGS += $(call __cc-option, $(CC), $(REALMODE_CFLAGS), -ffreestanding)
-REALMODE_CFLAGS += $(call __cc-option, $(CC), $(REALMODE_CFLAGS), -fno-stack-protector)
+REALMODE_CFLAGS += -fno-stack-protector
 REALMODE_CFLAGS += $(call __cc-option, $(CC), $(REALMODE_CFLAGS), -Wno-address-of-packed-member)
 REALMODE_CFLAGS += $(call __cc-option, $(CC), $(REALMODE_CFLAGS), $(cc_stack_align4))
 export REALMODE_CFLAGS
index 7619742f91c9a9c98c285de38abd2891cd8c6ebc..c88a31569a5ebb726842461abc36c026cc3b8866 100644 (file)
@@ -36,7 +36,7 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
 KBUILD_CFLAGS += $(cflags-y)
 KBUILD_CFLAGS += -mno-mmx -mno-sse
 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
-KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
+KBUILD_CFLAGS += -fno-stack-protector
 KBUILD_CFLAGS += $(call cc-disable-warning, address-of-packed-member)
 KBUILD_CFLAGS += $(call cc-disable-warning, gnu)
 KBUILD_CFLAGS += -Wno-pointer-sign
index 04e65f0698f60b09c8b699013b4b659bffe8bdb1..215376d975a29637ad9906c6889f154a867f1139 100644 (file)
@@ -82,7 +82,7 @@ $(obj)/vdso-image-%.c: $(obj)/vdso%.so.dbg $(obj)/vdso%.so $(obj)/vdso2c FORCE
 # optimize sibling calls.
 #
 CFL := $(PROFILING) -mcmodel=small -fPIC -O2 -fasynchronous-unwind-tables -m64 \
-       $(filter -g%,$(KBUILD_CFLAGS)) $(call cc-option, -fno-stack-protector) \
+       $(filter -g%,$(KBUILD_CFLAGS)) -fno-stack-protector \
        -fno-omit-frame-pointer -foptimize-sibling-calls \
        -DDISABLE_BRANCH_PROFILING -DBUILD_VDSO
 
@@ -151,7 +151,7 @@ KBUILD_CFLAGS_32 := $(filter-out -mfentry,$(KBUILD_CFLAGS_32))
 KBUILD_CFLAGS_32 := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS_32))
 KBUILD_CFLAGS_32 := $(filter-out $(RETPOLINE_CFLAGS),$(KBUILD_CFLAGS_32))
 KBUILD_CFLAGS_32 += -m32 -msoft-float -mregparm=0 -fpic
-KBUILD_CFLAGS_32 += $(call cc-option, -fno-stack-protector)
+KBUILD_CFLAGS_32 += -fno-stack-protector
 KBUILD_CFLAGS_32 += $(call cc-option, -foptimize-sibling-calls)
 KBUILD_CFLAGS_32 += -fno-omit-frame-pointer
 KBUILD_CFLAGS_32 += -DDISABLE_BRANCH_PROFILING
index dba6a83bc3493b917033ff1f1a2f7ceccdbf6c3a..93792b457b81546fa4cd23d2d3fb781888a899d9 100644 (file)
@@ -17,8 +17,7 @@ KCOV_INSTRUMENT_perf_event.o := n
 KCSAN_SANITIZE_common.o := n
 
 # Make sure load_percpu_segment has no stackprotector
-nostackp := $(call cc-option, -fno-stack-protector)
-CFLAGS_common.o                := $(nostackp)
+CFLAGS_common.o                := -fno-stack-protector
 
 obj-y                  := cacheinfo.o scattered.o topology.o
 obj-y                  += common.o
index 6110bce7237bdd1f547035f35c59a1ea6d95a3b6..d46fff11f06fa36b402b87e378bbbea68345f5b2 100644 (file)
@@ -24,7 +24,7 @@ ifdef CONFIG_FUNCTION_TRACER
 CFLAGS_REMOVE_cmdline.o = -pg
 endif
 
-CFLAGS_cmdline.o := $(call cc-option, -fno-stack-protector)
+CFLAGS_cmdline.o := -fno-stack-protector
 endif
 
 inat_tables_script = $(srctree)/arch/x86/tools/gen-insn-attr-x86.awk
index f7fd0e868c9c839c727ab06240f6ed3d3f28db75..5864219221ca8991dfb21baab0bd7a353cbdeff1 100644 (file)
@@ -22,10 +22,9 @@ obj-y                                :=  init.o init_$(BITS).o fault.o ioremap.o extable.o mmap.o \
 obj-y                          += pat/
 
 # Make sure __phys_addr has no stackprotector
-nostackp := $(call cc-option, -fno-stack-protector)
-CFLAGS_physaddr.o              := $(nostackp)
-CFLAGS_setup_nx.o              := $(nostackp)
-CFLAGS_mem_encrypt_identity.o  := $(nostackp)
+CFLAGS_physaddr.o              := -fno-stack-protector
+CFLAGS_setup_nx.o              := -fno-stack-protector
+CFLAGS_mem_encrypt_identity.o  := -fno-stack-protector
 
 CFLAGS_fault.o := -I $(srctree)/$(src)/../include/asm/trace
 
index 37923d715741ae29c792a09c6b0404c2c25c9788..6907b523e856b9c9dab6e34aad821f2d49ecee65 100644 (file)
@@ -3,8 +3,7 @@ OBJECT_FILES_NON_STANDARD_hibernate_asm_$(BITS).o := y
 
 # __restore_processor_state() restores %gs after S3 resume and so should not
 # itself be stack-protected
-nostackp := $(call cc-option, -fno-stack-protector)
-CFLAGS_cpu.o   := $(nostackp)
+CFLAGS_cpu.o   := -fno-stack-protector
 
 obj-$(CONFIG_PM_SLEEP)         += cpu.o
 obj-$(CONFIG_HIBERNATION)      += hibernate_$(BITS).o hibernate_asm_$(BITS).o hibernate.o
index 088bd764e0b7f6fe23c6456530ef5cf57c8c0fc8..183ac60e59901291c827c43fc4c5c93c0151a08e 100644 (file)
@@ -34,7 +34,7 @@ KCOV_INSTRUMENT := n
 PURGATORY_CFLAGS_REMOVE := -mcmodel=kernel
 PURGATORY_CFLAGS := -mcmodel=large -ffreestanding -fno-zero-initialized-in-bss
 PURGATORY_CFLAGS += $(DISABLE_STACKLEAK_PLUGIN) -DDISABLE_BRANCH_PROFILING
-PURGATORY_CFLAGS += $(call cc-option,-fno-stack-protector)
+PURGATORY_CFLAGS += -fno-stack-protector
 
 # Default KBUILD_CFLAGS can have -pg option set when FTRACE is enabled. That
 # in turn leaves some undefined symbols like __fentry__ in purgatory and not
index 0caddd6acb226c7e49e7bd7d9138d0966475e56b..5943387e3f3570e28cb376a4df2645b727be429b 100644 (file)
@@ -42,7 +42,7 @@ $(obj)/%.so: $(obj)/%.so.dbg FORCE
 # optimize sibling calls.
 #
 CFL := $(PROFILING) -mcmodel=small -fPIC -O2 -fasynchronous-unwind-tables -m64 \
-       $(filter -g%,$(KBUILD_CFLAGS)) $(call cc-option, -fno-stack-protector) \
+       $(filter -g%,$(KBUILD_CFLAGS)) -fno-stack-protector \
        -fno-omit-frame-pointer -foptimize-sibling-calls
 
 $(vobjs): KBUILD_CFLAGS += $(CFL)
index 084de77a109e89f218b6ccd8dd61a383a46ddab3..5f1db522d06bfb193f1a81229002256949cba961 100644 (file)
@@ -9,9 +9,8 @@ CFLAGS_REMOVE_irq.o = -pg
 endif
 
 # Make sure early boot has no stackprotector
-nostackp := $(call cc-option, -fno-stack-protector)
-CFLAGS_enlighten_pv.o          := $(nostackp)
-CFLAGS_mmu_pv.o                        := $(nostackp)
+CFLAGS_enlighten_pv.o          := -fno-stack-protector
+CFLAGS_mmu_pv.o                        := -fno-stack-protector
 
 obj-y                          += enlighten.o
 obj-y                          += mmu.o
index 4cce372edaf4deae500173999b549e7f535e8528..12c4436e77fbba77697e5a4359bfd5d4963576c2 100644 (file)
@@ -30,7 +30,7 @@ KBUILD_CFLAGS                 := $(cflags-y) -Os -DDISABLE_BRANCH_PROFILING \
                                   -include $(srctree)/drivers/firmware/efi/libstub/hidden.h \
                                   -D__NO_FORTIFY \
                                   $(call cc-option,-ffreestanding) \
-                                  $(call cc-option,-fno-stack-protector) \
+                                  -fno-stack-protector \
                                   $(call cc-option,-fno-addrsig) \
                                   -D__DISABLE_EXPORTS
 
index 0d322f3d90cdbc12c82801977e4203d20aa12c4a..c25c9a699b483731d453d8ff6efcf75d4ade4a31 100644 (file)
@@ -5,8 +5,7 @@ obj-y   += mem-reservation.o
 obj-y  += events/
 obj-y  += xenbus/
 
-nostackp := $(call cc-option, -fno-stack-protector)
-CFLAGS_features.o                      := $(nostackp)
+CFLAGS_features.o                      := -fno-stack-protector
 
 dom0-$(CONFIG_ARM64) += arm-device.o
 dom0-$(CONFIG_PCI) += pci.o
index b1c42c10073b936cdc4ae425f12482c828025900..0cda70649f1ce2201fb74e1ea53b29d8e50d005c 100644 (file)
@@ -22,7 +22,7 @@ KCOV_INSTRUMENT_fault-inject.o := n
 ifdef CONFIG_AMD_MEM_ENCRYPT
 KASAN_SANITIZE_string.o := n
 
-CFLAGS_string.o := $(call cc-option, -fno-stack-protector)
+CFLAGS_string.o := -fno-stack-protector
 endif
 
 # Used by KCSAN while enabled, avoid recursion.
@@ -300,7 +300,7 @@ endif
 UBSAN_SANITIZE_ubsan.o := n
 KASAN_SANITIZE_ubsan.o := n
 KCSAN_SANITIZE_ubsan.o := n
-CFLAGS_ubsan.o := $(call cc-option, -fno-stack-protector) $(DISABLE_STACKLEAK_PLUGIN)
+CFLAGS_ubsan.o := -fno-stack-protector $(DISABLE_STACKLEAK_PLUGIN)
 
 obj-$(CONFIG_SBITMAP) += sbitmap.o
 
index d532c25877311797c5936f096f920adaec979b7e..370d970e5ab5bbaae1e21627245cad728a31742d 100644 (file)
@@ -16,7 +16,7 @@ CFLAGS_REMOVE_tags_report.o = $(CC_FLAGS_FTRACE)
 # Function splitter causes unnecessary splits in __asan_load1/__asan_store1
 # see: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63533
 CC_FLAGS_KASAN_RUNTIME := $(call cc-option, -fno-conserve-stack)
-CC_FLAGS_KASAN_RUNTIME += $(call cc-option, -fno-stack-protector)
+CC_FLAGS_KASAN_RUNTIME += -fno-stack-protector
 # Disable branch tracing to avoid recursion.
 CC_FLAGS_KASAN_RUNTIME += -DDISABLE_BRANCH_PROFILING