Skip to content

Commit 893ab00

Browse files
committed
kbuild: remove cc-option test of -fno-stack-protector
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 <[email protected]> Reviewed-by: Kees Cook <[email protected]> Acked-by: Ard Biesheuvel <[email protected]> Reviewed-by: Nick Desaulniers <[email protected]>
1 parent dd7699e commit 893ab00

File tree

23 files changed

+29
-40
lines changed

23 files changed

+29
-40
lines changed

Documentation/kbuild/kconfig-language.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -540,8 +540,8 @@ followed by a test macro::
540540
If you need to expose a compiler capability to makefiles and/or C source files,
541541
`CC_HAS_` is the recommended prefix for the config option::
542542

543-
config CC_HAS_STACKPROTECTOR_NONE
544-
def_bool $(cc-option,-fno-stack-protector)
543+
config CC_HAS_ASM_GOTO
544+
def_bool $(success,$(srctree)/scripts/gcc-goto.sh $(CC))
545545

546546
Build as module only
547547
~~~~~~~~~~~~~~~~~~~~

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,7 @@ ifneq ($(CONFIG_FRAME_WARN),0)
762762
KBUILD_CFLAGS += -Wframe-larger-than=$(CONFIG_FRAME_WARN)
763763
endif
764764

765-
stackp-flags-$(CONFIG_CC_HAS_STACKPROTECTOR_NONE) := -fno-stack-protector
765+
stackp-flags-y := -fno-stack-protector
766766
stackp-flags-$(CONFIG_STACKPROTECTOR) := -fstack-protector
767767
stackp-flags-$(CONFIG_STACKPROTECTOR_STRONG) := -fstack-protector-strong
768768

arch/Kconfig

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -478,9 +478,6 @@ config HAVE_STACKPROTECTOR
478478
An arch should select this symbol if:
479479
- it has implemented a stack canary (e.g. __stack_chk_guard)
480480

481-
config CC_HAS_STACKPROTECTOR_NONE
482-
def_bool $(cc-option,-fno-stack-protector)
483-
484481
config STACKPROTECTOR
485482
bool "Stack Protector buffer overflow detection"
486483
depends on HAVE_STACKPROTECTOR

arch/arm/boot/compressed/Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,8 @@ endif
8484

8585
# -fstack-protector-strong triggers protection checks in this code,
8686
# but it is being used too early to link to meaningful stack_chk logic.
87-
nossp-flags-$(CONFIG_CC_HAS_STACKPROTECTOR_NONE) := -fno-stack-protector
8887
$(foreach o, $(libfdt_objs) atags_to_fdt.o, \
89-
$(eval CFLAGS_$(o) := -I $(srctree)/scripts/dtc/libfdt $(nossp-flags-y)))
88+
$(eval CFLAGS_$(o) := -I $(srctree)/scripts/dtc/libfdt -fno-stack-protector))
9089

9190
# These were previously generated C files. When you are building the kernel
9291
# with O=, make sure to remove the stale files in the output tree. Otherwise,

arch/mips/vdso/Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ cflags-vdso := $(ccflags-vdso) \
3535
-O3 -g -fPIC -fno-strict-aliasing -fno-common -fno-builtin -G 0 \
3636
-mrelax-pic-calls $(call cc-option, -mexplicit-relocs) \
3737
-fno-stack-protector -fno-jump-tables -DDISABLE_BRANCH_PROFILING \
38-
$(call cc-option, -fno-asynchronous-unwind-tables) \
39-
$(call cc-option, -fno-stack-protector)
38+
$(call cc-option, -fno-asynchronous-unwind-tables)
4039
aflags-vdso := $(ccflags-vdso) \
4140
-D__ASSEMBLY__ -Wa,-gdwarf-2
4241

arch/powerpc/kernel/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ CFLAGS_prom_init.o += $(DISABLE_LATENT_ENTROPY_PLUGIN)
1616
CFLAGS_btext.o += $(DISABLE_LATENT_ENTROPY_PLUGIN)
1717
CFLAGS_prom.o += $(DISABLE_LATENT_ENTROPY_PLUGIN)
1818

19-
CFLAGS_prom_init.o += $(call cc-option, -fno-stack-protector)
19+
CFLAGS_prom_init.o += -fno-stack-protector
2020
CFLAGS_prom_init.o += -DDISABLE_BRANCH_PROFILING
2121
CFLAGS_prom_init.o += -ffreestanding
2222

arch/powerpc/platforms/powermac/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# SPDX-License-Identifier: GPL-2.0
22
CFLAGS_bootx_init.o += -fPIC
3-
CFLAGS_bootx_init.o += $(call cc-option, -fno-stack-protector)
3+
CFLAGS_bootx_init.o += -fno-stack-protector
44

55
KASAN_SANITIZE_bootx_init.o := n
66

arch/sparc/vdso/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ $(obj)/vdso-image-%.c: $(obj)/vdso%.so.dbg $(obj)/vdso%.so $(obj)/vdso2c FORCE
5454
# optimize sibling calls.
5555
#
5656
CFL := $(PROFILING) -mcmodel=medlow -fPIC -O2 -fasynchronous-unwind-tables -m64 \
57-
$(filter -g%,$(KBUILD_CFLAGS)) $(call cc-option, -fno-stack-protector) \
57+
$(filter -g%,$(KBUILD_CFLAGS)) -fno-stack-protector \
5858
-fno-omit-frame-pointer -foptimize-sibling-calls \
5959
-DDISABLE_BRANCH_PROFILING -DBUILD_VDSO
6060

@@ -93,7 +93,7 @@ KBUILD_CFLAGS_32 := $(filter-out -fno-pic,$(KBUILD_CFLAGS_32))
9393
KBUILD_CFLAGS_32 := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS_32))
9494
KBUILD_CFLAGS_32 := $(filter-out $(SPARC_REG_CFLAGS),$(KBUILD_CFLAGS_32))
9595
KBUILD_CFLAGS_32 += -m32 -msoft-float -fpic
96-
KBUILD_CFLAGS_32 += $(call cc-option, -fno-stack-protector)
96+
KBUILD_CFLAGS_32 += -fno-stack-protector
9797
KBUILD_CFLAGS_32 += $(call cc-option, -foptimize-sibling-calls)
9898
KBUILD_CFLAGS_32 += -fno-omit-frame-pointer
9999
KBUILD_CFLAGS_32 += -DDISABLE_BRANCH_PROFILING

arch/um/Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,7 @@ LINK-$(CONFIG_LD_SCRIPT_STATIC) += -static
121121
LINK-$(CONFIG_LD_SCRIPT_DYN) += -Wl,-rpath,/lib $(call cc-option, -no-pie)
122122

123123
CFLAGS_NO_HARDENING := $(call cc-option, -fno-PIC,) $(call cc-option, -fno-pic,) \
124-
$(call cc-option, -fno-stack-protector,) \
125-
$(call cc-option, -fno-stack-protector-all,)
124+
-fno-stack-protector $(call cc-option, -fno-stack-protector-all)
126125

127126
# Options used by linker script
128127
export LDS_START := $(START)

arch/x86/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ REALMODE_CFLAGS := $(M16_CFLAGS) -g -Os -DDISABLE_BRANCH_PROFILING \
3737
-mno-mmx -mno-sse
3838

3939
REALMODE_CFLAGS += $(call __cc-option, $(CC), $(REALMODE_CFLAGS), -ffreestanding)
40-
REALMODE_CFLAGS += $(call __cc-option, $(CC), $(REALMODE_CFLAGS), -fno-stack-protector)
40+
REALMODE_CFLAGS += -fno-stack-protector
4141
REALMODE_CFLAGS += $(call __cc-option, $(CC), $(REALMODE_CFLAGS), -Wno-address-of-packed-member)
4242
REALMODE_CFLAGS += $(call __cc-option, $(CC), $(REALMODE_CFLAGS), $(cc_stack_align4))
4343
export REALMODE_CFLAGS

0 commit comments

Comments
 (0)