File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -595,10 +595,18 @@ ifneq ($(CONFIG_FRAME_WARN),0)
595595KBUILD_CFLAGS += $(call cc-option,-Wframe-larger-than=${CONFIG_FRAME_WARN})
596596endif
597597
598- # Force gcc to behave correct even for buggy distributions
599- ifndef CONFIG_CC_STACKPROTECTOR
600- KBUILD_CFLAGS += $(call cc-option, -fno-stack-protector)
598+ # Handle stack protector mode.
599+ ifdef CONFIG_CC_STACKPROTECTOR
600+ stackp-flag := -fstack-protector
601+ ifeq ($(call cc-option, $(stackp-flag)),)
602+ $(warning Cannot use CONFIG_CC_STACKPROTECTOR : \
603+ -fstack-protector not supported by compiler))
604+ endif
605+ else
606+ # Force off for distro compilers that enable stack protector by default.
607+ stackp-flag := $(call cc-option, -fno-stack-protector)
601608endif
609+ KBUILD_CFLAGS += $(stackp-flag )
602610
603611# This warning generated too much noise in a regular build.
604612# Use make W=1 to enable this warning (see scripts/Makefile.build)
Original file line number Diff line number Diff line change @@ -336,6 +336,28 @@ config SECCOMP_FILTER
336336
337337 See Documentation/prctl/seccomp_filter.txt for details.
338338
339+ config HAVE_CC_STACKPROTECTOR
340+ bool
341+ help
342+ An arch should select this symbol if:
343+ - its compiler supports the -fstack-protector option
344+ - it has implemented a stack canary (e.g. __stack_chk_guard)
345+
346+ config CC_STACKPROTECTOR
347+ bool "Enable -fstack-protector buffer overflow detection"
348+ depends on HAVE_CC_STACKPROTECTOR
349+ help
350+ This option turns on the -fstack-protector GCC feature. This
351+ feature puts, at the beginning of functions, a canary value on
352+ the stack just before the return address, and validates
353+ the value just before actually returning. Stack based buffer
354+ overflows (that need to overwrite this return address) now also
355+ overwrite the canary, which gets detected and the attack is then
356+ neutralized via a kernel panic.
357+
358+ This feature requires gcc version 4.2 or above, or a distribution
359+ gcc with the feature backported.
360+
339361config HAVE_CONTEXT_TRACKING
340362 bool
341363 help
Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ config ARM
3030 select HAVE_BPF_JIT
3131 select HAVE_CONTEXT_TRACKING
3232 select HAVE_C_RECORDMCOUNT
33+ select HAVE_CC_STACKPROTECTOR
3334 select HAVE_DEBUG_KMEMLEAK
3435 select HAVE_DMA_API_DEBUG
3536 select HAVE_DMA_ATTRS
@@ -1856,18 +1857,6 @@ config SECCOMP
18561857 and the task is only allowed to execute a few safe syscalls
18571858 defined by each seccomp mode.
18581859
1859- config CC_STACKPROTECTOR
1860- bool "Enable -fstack-protector buffer overflow detection (EXPERIMENTAL)"
1861- help
1862- This option turns on the -fstack-protector GCC feature. This
1863- feature puts, at the beginning of functions, a canary value on
1864- the stack just before the return address, and validates
1865- the value just before actually returning. Stack based buffer
1866- overflows (that need to overwrite this return address) now also
1867- overwrite the canary, which gets detected and the attack is then
1868- neutralized via a kernel panic.
1869- This feature requires gcc version 4.2 or above.
1870-
18711860config SWIOTLB
18721861 def_bool y
18731862
Original file line number Diff line number Diff line change @@ -40,10 +40,6 @@ ifeq ($(CONFIG_FRAME_POINTER),y)
4040KBUILD_CFLAGS +=-fno-omit-frame-pointer -mapcs -mno-sched-prolog
4141endif
4242
43- ifeq ($(CONFIG_CC_STACKPROTECTOR ) ,y)
44- KBUILD_CFLAGS +=-fstack-protector
45- endif
46-
4743ifeq ($(CONFIG_CPU_BIG_ENDIAN ) ,y)
4844KBUILD_CPPFLAGS += -mbig-endian
4945AS += -EB
Original file line number Diff line number Diff line change @@ -47,6 +47,7 @@ config MIPS
4747 select MODULES_USE_ELF_RELA if MODULES && 64BIT
4848 select CLONE_BACKWARDS
4949 select HAVE_DEBUG_STACKOVERFLOW
50+ select HAVE_CC_STACKPROTECTOR
5051
5152menu "Machine selection"
5253
@@ -2322,19 +2323,6 @@ config SECCOMP
23222323
23232324 If unsure, say Y. Only embedded should say N here.
23242325
2325- config CC_STACKPROTECTOR
2326- bool "Enable -fstack-protector buffer overflow detection (EXPERIMENTAL)"
2327- help
2328- This option turns on the -fstack-protector GCC feature. This
2329- feature puts, at the beginning of functions, a canary value on
2330- the stack just before the return address, and validates
2331- the value just before actually returning. Stack based buffer
2332- overflows (that need to overwrite this return address) now also
2333- overwrite the canary, which gets detected and the attack is then
2334- neutralized via a kernel panic.
2335-
2336- This feature requires gcc version 4.2 or above.
2337-
23382326config USE_OF
23392327 bool
23402328 select OF
Original file line number Diff line number Diff line change @@ -232,10 +232,6 @@ bootvars-y = VMLINUX_LOAD_ADDRESS=$(load-y) \
232232
233233LDFLAGS += -m $(ld-emul )
234234
235- ifdef CONFIG_CC_STACKPROTECTOR
236- KBUILD_CFLAGS += -fstack-protector
237- endif
238-
239235ifdef CONFIG_MIPS
240236CHECKFLAGS += $(shell $(CC ) $(KBUILD_CFLAGS ) -dM -E -x c /dev/null | \
241237 egrep -vw '__GNUC_(|MINOR_|PATCHLEVEL_) _' | \
Original file line number Diff line number Diff line change @@ -66,6 +66,7 @@ config SUPERH32
6666 select PERF_EVENTS
6767 select ARCH_HIBERNATION_POSSIBLE if MMU
6868 select SPARSE_IRQ
69+ select HAVE_CC_STACKPROTECTOR
6970
7071config SUPERH64
7172 def_bool ARCH = "sh64"
@@ -695,20 +696,6 @@ config SECCOMP
695696
696697 If unsure, say N.
697698
698- config CC_STACKPROTECTOR
699- bool "Enable -fstack-protector buffer overflow detection (EXPERIMENTAL)"
700- depends on SUPERH32
701- help
702- This option turns on the -fstack-protector GCC feature. This
703- feature puts, at the beginning of functions, a canary value on
704- the stack just before the return address, and validates
705- the value just before actually returning. Stack based buffer
706- overflows (that need to overwrite this return address) now also
707- overwrite the canary, which gets detected and the attack is then
708- neutralized via a kernel panic.
709-
710- This feature requires gcc version 4.2 or above.
711-
712699config SMP
713700 bool "Symmetric multi-processing support"
714701 depends on SYS_SUPPORTS_SMP
Original file line number Diff line number Diff line change @@ -199,10 +199,6 @@ ifeq ($(CONFIG_DWARF_UNWINDER),y)
199199 KBUILD_CFLAGS += -fasynchronous-unwind-tables
200200endif
201201
202- ifeq ($(CONFIG_CC_STACKPROTECTOR ) ,y)
203- KBUILD_CFLAGS += -fstack-protector
204- endif
205-
206202libs-$(CONFIG_SUPERH32) := arch/sh/lib/ $(libs-y )
207203libs-$(CONFIG_SUPERH64) := arch/sh/lib64/ $(libs-y )
208204
Original file line number Diff line number Diff line change @@ -125,6 +125,7 @@ config X86
125125 select RTC_LIB
126126 select HAVE_DEBUG_STACKOVERFLOW
127127 select HAVE_IRQ_EXIT_ON_IRQ_STACK if X86_64
128+ select HAVE_CC_STACKPROTECTOR
128129
129130config INSTRUCTION_DECODER
130131 def_bool y
@@ -1617,22 +1618,6 @@ config SECCOMP
16171618
16181619 If unsure, say Y. Only embedded should say N here.
16191620
1620- config CC_STACKPROTECTOR
1621- bool "Enable -fstack-protector buffer overflow detection"
1622- ---help---
1623- This option turns on the -fstack-protector GCC feature. This
1624- feature puts, at the beginning of functions, a canary value on
1625- the stack just before the return address, and validates
1626- the value just before actually returning. Stack based buffer
1627- overflows (that need to overwrite this return address) now also
1628- overwrite the canary, which gets detected and the attack is then
1629- neutralized via a kernel panic.
1630-
1631- This feature requires gcc version 4.2 or above, or a distribution
1632- gcc with the feature backported. Older versions are automatically
1633- detected and for those versions, this configuration option is
1634- ignored. (and a warning is printed during bootup)
1635-
16361621source kernel/Kconfig.hz
16371622
16381623config KEXEC
Original file line number Diff line number Diff line change 8989 KBUILD_CFLAGS += -maccumulate-outgoing-args
9090endif
9191
92+ # Make sure compiler does not have buggy stack-protector support.
9293ifdef CONFIG_CC_STACKPROTECTOR
9394 cc_has_sp := $(srctree)/scripts/gcc-x86_$(BITS)-has-stack-protector.sh
94- ifeq ($(shell $(CONFIG_SHELL) $(cc_has_sp) $(CC) $(KBUILD_CPPFLAGS) $(biarch)),y)
95- stackp-y := -fstack-protector
96- KBUILD_CFLAGS += $(stackp-y )
97- else
98- $(warning stack protector enabled but no compiler support)
95+ ifneq ($(shell $(CONFIG_SHELL) $(cc_has_sp) $(CC) $(KBUILD_CPPFLAGS) $(biarch)),y)
96+ $(warning stack-protector enabled but compiler support broken)
9997 endif
10098endif
10199
You can’t perform that action at this time.
0 commit comments