summaryrefslogtreecommitdiffstats
path: root/Makefile
diff options
context:
space:
mode:
authorMasahiro Yamada <yamada.masahiro@socionext.com>2018-05-28 05:22:00 -0400
committerMasahiro Yamada <yamada.masahiro@socionext.com>2018-06-08 05:56:00 -0400
commit2a61f4747eeaa85ce26ca9fbd81421b15facd018 (patch)
tree497f971a5b6af6085c8d2349e773045f6a88dcc1 /Makefile
parent315bab4e972d9795529b764718d475492db40c0f (diff)
stack-protector: test compiler capability in Kconfig and drop AUTO mode
Move the test for -fstack-protector(-strong) option to Kconfig. If the compiler does not support the option, the corresponding menu is automatically hidden. If STRONG is not supported, it will fall back to REGULAR. If REGULAR is not supported, it will be disabled. This means, AUTO is implicitly handled by the dependency solver of Kconfig, hence removed. I also turned the 'choice' into only two boolean symbols. The use of 'choice' is not a good idea here, because all of all{yes,mod,no}config would choose the first visible value, while we want allnoconfig to disable as many features as possible. X86 has additional shell scripts in case the compiler supports those options, but generates broken code. I added CC_HAS_SANE_STACKPROTECTOR to test this. I had to add -m32 to gcc-x86_32-has-stack-protector.sh to make it work correctly. Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com> Acked-by: Kees Cook <keescook@chromium.org>
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile93
1 files changed, 6 insertions, 87 deletions
diff --git a/Makefile b/Makefile
index 747edaf11559..ca9d98b4a71b 100644
--- a/Makefile
+++ b/Makefile
@@ -686,55 +686,11 @@ ifneq ($(CONFIG_FRAME_WARN),0)
686KBUILD_CFLAGS += $(call cc-option,-Wframe-larger-than=${CONFIG_FRAME_WARN}) 686KBUILD_CFLAGS += $(call cc-option,-Wframe-larger-than=${CONFIG_FRAME_WARN})
687endif 687endif
688 688
689# This selects the stack protector compiler flag. Testing it is delayed 689stackp-flags-$(CONFIG_CC_HAS_STACKPROTECTOR_NONE) := -fno-stack-protector
690# until after .config has been reprocessed, in the prepare-compiler-check 690stackp-flags-$(CONFIG_CC_STACKPROTECTOR) := -fstack-protector
691# target. 691stackp-flags-$(CONFIG_CC_STACKPROTECTOR_STRONG) := -fstack-protector-strong
692ifdef CONFIG_CC_STACKPROTECTOR_AUTO 692
693 stackp-flag := $(call cc-option,-fstack-protector-strong,$(call cc-option,-fstack-protector)) 693KBUILD_CFLAGS += $(stackp-flags-y)
694 stackp-name := AUTO
695else
696ifdef CONFIG_CC_STACKPROTECTOR_REGULAR
697 stackp-flag := -fstack-protector
698 stackp-name := REGULAR
699else
700ifdef CONFIG_CC_STACKPROTECTOR_STRONG
701 stackp-flag := -fstack-protector-strong
702 stackp-name := STRONG
703else
704 # If either there is no stack protector for this architecture or
705 # CONFIG_CC_STACKPROTECTOR_NONE is selected, we're done, and $(stackp-name)
706 # is empty, skipping all remaining stack protector tests.
707 #
708 # Force off for distro compilers that enable stack protector by default.
709 KBUILD_CFLAGS += $(call cc-option, -fno-stack-protector)
710endif
711endif
712endif
713# Find arch-specific stack protector compiler sanity-checking script.
714ifdef stackp-name
715ifneq ($(stackp-flag),)
716 stackp-path := $(srctree)/scripts/gcc-$(SRCARCH)_$(BITS)-has-stack-protector.sh
717 stackp-check := $(wildcard $(stackp-path))
718 # If the wildcard test matches a test script, run it to check functionality.
719 ifdef stackp-check
720 ifneq ($(shell $(CONFIG_SHELL) $(stackp-check) $(CC) $(KBUILD_CPPFLAGS) $(biarch)),y)
721 stackp-broken := y
722 endif
723 endif
724 ifndef stackp-broken
725 # If the stack protector is functional, enable code that depends on it.
726 KBUILD_CPPFLAGS += -DCONFIG_CC_STACKPROTECTOR
727 # Either we've already detected the flag (for AUTO) or we'll fail the
728 # build in the prepare-compiler-check rule (for specific flag).
729 KBUILD_CFLAGS += $(stackp-flag)
730 else
731 # We have to make sure stack protector is unconditionally disabled if
732 # the compiler is broken (in case we're going to continue the build in
733 # AUTO mode).
734 KBUILD_CFLAGS += $(call cc-option, -fno-stack-protector)
735 endif
736endif
737endif
738 694
739ifeq ($(cc-name),clang) 695ifeq ($(cc-name),clang)
740KBUILD_CPPFLAGS += $(call cc-option,-Qunused-arguments,) 696KBUILD_CPPFLAGS += $(call cc-option,-Qunused-arguments,)
@@ -1118,7 +1074,7 @@ endif
1118# prepare2 creates a makefile if using a separate output directory. 1074# prepare2 creates a makefile if using a separate output directory.
1119# From this point forward, .config has been reprocessed, so any rules 1075# From this point forward, .config has been reprocessed, so any rules
1120# that need to depend on updated CONFIG_* values can be checked here. 1076# that need to depend on updated CONFIG_* values can be checked here.
1121prepare2: prepare3 prepare-compiler-check outputmakefile asm-generic 1077prepare2: prepare3 outputmakefile asm-generic
1122 1078
1123prepare1: prepare2 $(version_h) $(autoksyms_h) include/generated/utsrelease.h \ 1079prepare1: prepare2 $(version_h) $(autoksyms_h) include/generated/utsrelease.h \
1124 include/config/auto.conf 1080 include/config/auto.conf
@@ -1144,43 +1100,6 @@ uapi-asm-generic:
1144PHONY += prepare-objtool 1100PHONY += prepare-objtool
1145prepare-objtool: $(objtool_target) 1101prepare-objtool: $(objtool_target)
1146 1102
1147# Check for CONFIG flags that require compiler support. Abort the build
1148# after .config has been processed, but before the kernel build starts.
1149#
1150# For security-sensitive CONFIG options, we don't want to fallback and/or
1151# silently change which compiler flags will be used, since that leads to
1152# producing kernels with different security feature characteristics
1153# depending on the compiler used. (For example, "But I selected
1154# CC_STACKPROTECTOR_STRONG! Why did it build with _REGULAR?!")
1155PHONY += prepare-compiler-check
1156prepare-compiler-check: FORCE
1157# Make sure compiler supports requested stack protector flag.
1158ifdef stackp-name
1159 # Warn about CONFIG_CC_STACKPROTECTOR_AUTO having found no option.
1160 ifeq ($(stackp-flag),)
1161 @echo CONFIG_CC_STACKPROTECTOR_$(stackp-name): \
1162 Compiler does not support any known stack-protector >&2
1163 else
1164 # Fail if specifically requested stack protector is missing.
1165 ifeq ($(call cc-option, $(stackp-flag)),)
1166 @echo Cannot use CONFIG_CC_STACKPROTECTOR_$(stackp-name): \
1167 $(stackp-flag) not supported by compiler >&2 && exit 1
1168 endif
1169 endif
1170endif
1171# Make sure compiler does not have buggy stack-protector support. If a
1172# specific stack-protector was requested, fail the build, otherwise warn.
1173ifdef stackp-broken
1174 ifeq ($(stackp-name),AUTO)
1175 @echo CONFIG_CC_STACKPROTECTOR_$(stackp-name): \
1176 $(stackp-flag) available but compiler is broken: disabling >&2
1177 else
1178 @echo Cannot use CONFIG_CC_STACKPROTECTOR_$(stackp-name): \
1179 $(stackp-flag) available but compiler is broken >&2 && exit 1
1180 endif
1181endif
1182 @:
1183
1184# Generate some files 1103# Generate some files
1185# --------------------------------------------------------------------------- 1104# ---------------------------------------------------------------------------
1186 1105