File tree Expand file tree Collapse file tree 10 files changed +40
-75
lines changed Expand file tree Collapse file tree 10 files changed +40
-75
lines changed Original file line number Diff line number Diff line change @@ -595,10 +595,18 @@ ifneq ($(CONFIG_FRAME_WARN),0)
595
595
KBUILD_CFLAGS += $(call cc-option,-Wframe-larger-than=${CONFIG_FRAME_WARN})
596
596
endif
597
597
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)
601
608
endif
609
+ KBUILD_CFLAGS += $(stackp-flag )
602
610
603
611
# This warning generated too much noise in a regular build.
604
612
# 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
336
336
337
337
See Documentation/prctl/seccomp_filter.txt for details.
338
338
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
+
339
361
config HAVE_CONTEXT_TRACKING
340
362
bool
341
363
help
Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ config ARM
30
30
select HAVE_BPF_JIT
31
31
select HAVE_CONTEXT_TRACKING
32
32
select HAVE_C_RECORDMCOUNT
33
+ select HAVE_CC_STACKPROTECTOR
33
34
select HAVE_DEBUG_KMEMLEAK
34
35
select HAVE_DMA_API_DEBUG
35
36
select HAVE_DMA_ATTRS
@@ -1856,18 +1857,6 @@ config SECCOMP
1856
1857
and the task is only allowed to execute a few safe syscalls
1857
1858
defined by each seccomp mode.
1858
1859
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
-
1871
1860
config SWIOTLB
1872
1861
def_bool y
1873
1862
Original file line number Diff line number Diff line change @@ -40,10 +40,6 @@ ifeq ($(CONFIG_FRAME_POINTER),y)
40
40
KBUILD_CFLAGS +=-fno-omit-frame-pointer -mapcs -mno-sched-prolog
41
41
endif
42
42
43
- ifeq ($(CONFIG_CC_STACKPROTECTOR ) ,y)
44
- KBUILD_CFLAGS +=-fstack-protector
45
- endif
46
-
47
43
ifeq ($(CONFIG_CPU_BIG_ENDIAN ) ,y)
48
44
KBUILD_CPPFLAGS += -mbig-endian
49
45
AS += -EB
Original file line number Diff line number Diff line change @@ -47,6 +47,7 @@ config MIPS
47
47
select MODULES_USE_ELF_RELA if MODULES && 64BIT
48
48
select CLONE_BACKWARDS
49
49
select HAVE_DEBUG_STACKOVERFLOW
50
+ select HAVE_CC_STACKPROTECTOR
50
51
51
52
menu "Machine selection"
52
53
@@ -2322,19 +2323,6 @@ config SECCOMP
2322
2323
2323
2324
If unsure, say Y. Only embedded should say N here.
2324
2325
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
-
2338
2326
config USE_OF
2339
2327
bool
2340
2328
select OF
Original file line number Diff line number Diff line change @@ -232,10 +232,6 @@ bootvars-y = VMLINUX_LOAD_ADDRESS=$(load-y) \
232
232
233
233
LDFLAGS += -m $(ld-emul )
234
234
235
- ifdef CONFIG_CC_STACKPROTECTOR
236
- KBUILD_CFLAGS += -fstack-protector
237
- endif
238
-
239
235
ifdef CONFIG_MIPS
240
236
CHECKFLAGS += $(shell $(CC ) $(KBUILD_CFLAGS ) -dM -E -x c /dev/null | \
241
237
egrep -vw '__GNUC_(|MINOR_|PATCHLEVEL_) _' | \
Original file line number Diff line number Diff line change @@ -66,6 +66,7 @@ config SUPERH32
66
66
select PERF_EVENTS
67
67
select ARCH_HIBERNATION_POSSIBLE if MMU
68
68
select SPARSE_IRQ
69
+ select HAVE_CC_STACKPROTECTOR
69
70
70
71
config SUPERH64
71
72
def_bool ARCH = "sh64"
@@ -695,20 +696,6 @@ config SECCOMP
695
696
696
697
If unsure, say N.
697
698
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
-
712
699
config SMP
713
700
bool "Symmetric multi-processing support"
714
701
depends on SYS_SUPPORTS_SMP
Original file line number Diff line number Diff line change @@ -199,10 +199,6 @@ ifeq ($(CONFIG_DWARF_UNWINDER),y)
199
199
KBUILD_CFLAGS += -fasynchronous-unwind-tables
200
200
endif
201
201
202
- ifeq ($(CONFIG_CC_STACKPROTECTOR ) ,y)
203
- KBUILD_CFLAGS += -fstack-protector
204
- endif
205
-
206
202
libs-$(CONFIG_SUPERH32) := arch/sh/lib/ $(libs-y )
207
203
libs-$(CONFIG_SUPERH64) := arch/sh/lib64/ $(libs-y )
208
204
Original file line number Diff line number Diff line change @@ -125,6 +125,7 @@ config X86
125
125
select RTC_LIB
126
126
select HAVE_DEBUG_STACKOVERFLOW
127
127
select HAVE_IRQ_EXIT_ON_IRQ_STACK if X86_64
128
+ select HAVE_CC_STACKPROTECTOR
128
129
129
130
config INSTRUCTION_DECODER
130
131
def_bool y
@@ -1617,22 +1618,6 @@ config SECCOMP
1617
1618
1618
1619
If unsure, say Y. Only embedded should say N here.
1619
1620
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
-
1636
1621
source kernel/Kconfig.hz
1637
1622
1638
1623
config KEXEC
Original file line number Diff line number Diff line change 89
89
KBUILD_CFLAGS += -maccumulate-outgoing-args
90
90
endif
91
91
92
+ # Make sure compiler does not have buggy stack-protector support.
92
93
ifdef CONFIG_CC_STACKPROTECTOR
93
94
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)
99
97
endif
100
98
endif
101
99
You can’t perform that action at this time.
0 commit comments