aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile20
-rw-r--r--arch/Kconfig67
-rw-r--r--arch/arm/Kconfig13
-rw-r--r--arch/arm/Makefile4
-rw-r--r--arch/arm/boot/compressed/misc.c14
-rw-r--r--arch/mips/Kconfig14
-rw-r--r--arch/mips/Makefile4
-rw-r--r--arch/sh/Kconfig15
-rw-r--r--arch/sh/Makefile4
-rw-r--r--arch/x86/Kconfig17
-rw-r--r--arch/x86/Makefile8
11 files changed, 105 insertions, 75 deletions
diff --git a/Makefile b/Makefile
index b8b7f74696b4..455fd484b20e 100644
--- a/Makefile
+++ b/Makefile
@@ -595,10 +595,24 @@ ifneq ($(CONFIG_FRAME_WARN),0)
595KBUILD_CFLAGS += $(call cc-option,-Wframe-larger-than=${CONFIG_FRAME_WARN}) 595KBUILD_CFLAGS += $(call cc-option,-Wframe-larger-than=${CONFIG_FRAME_WARN})
596endif 596endif
597 597
598# Force gcc to behave correct even for buggy distributions 598# Handle stack protector mode.
599ifndef CONFIG_CC_STACKPROTECTOR 599ifdef CONFIG_CC_STACKPROTECTOR_REGULAR
600KBUILD_CFLAGS += $(call cc-option, -fno-stack-protector) 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
605else ifdef CONFIG_CC_STACKPROTECTOR_STRONG
606 stackp-flag := -fstack-protector-strong
607 ifeq ($(call cc-option, $(stackp-flag)),)
608 $(warning Cannot use CONFIG_CC_STACKPROTECTOR_STRONG: \
609 -fstack-protector-strong not supported by compiler)
610 endif
611else
612 # Force off for distro compilers that enable stack protector by default.
613 stackp-flag := $(call cc-option, -fno-stack-protector)
601endif 614endif
615KBUILD_CFLAGS += $(stackp-flag)
602 616
603# This warning generated too much noise in a regular build. 617# This warning generated too much noise in a regular build.
604# Use make W=1 to enable this warning (see scripts/Makefile.build) 618# Use make W=1 to enable this warning (see scripts/Makefile.build)
diff --git a/arch/Kconfig b/arch/Kconfig
index f1cf895c040f..80bbb8ccd0d1 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -336,6 +336,73 @@ config SECCOMP_FILTER
336 336
337 See Documentation/prctl/seccomp_filter.txt for details. 337 See Documentation/prctl/seccomp_filter.txt for details.
338 338
339config 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
346config CC_STACKPROTECTOR
347 def_bool n
348 help
349 Set when a stack-protector mode is enabled, so that the build
350 can enable kernel-side support for the GCC feature.
351
352choice
353 prompt "Stack Protector buffer overflow detection"
354 depends on HAVE_CC_STACKPROTECTOR
355 default CC_STACKPROTECTOR_NONE
356 help
357 This option turns on the "stack-protector" GCC feature. This
358 feature puts, at the beginning of functions, a canary value on
359 the stack just before the return address, and validates
360 the value just before actually returning. Stack based buffer
361 overflows (that need to overwrite this return address) now also
362 overwrite the canary, which gets detected and the attack is then
363 neutralized via a kernel panic.
364
365config CC_STACKPROTECTOR_NONE
366 bool "None"
367 help
368 Disable "stack-protector" GCC feature.
369
370config CC_STACKPROTECTOR_REGULAR
371 bool "Regular"
372 select CC_STACKPROTECTOR
373 help
374 Functions will have the stack-protector canary logic added if they
375 have an 8-byte or larger character array on the stack.
376
377 This feature requires gcc version 4.2 or above, or a distribution
378 gcc with the feature backported ("-fstack-protector").
379
380 On an x86 "defconfig" build, this feature adds canary checks to
381 about 3% of all kernel functions, which increases kernel code size
382 by about 0.3%.
383
384config CC_STACKPROTECTOR_STRONG
385 bool "Strong"
386 select CC_STACKPROTECTOR
387 help
388 Functions will have the stack-protector canary logic added in any
389 of the following conditions:
390
391 - local variable's address used as part of the right hand side of an
392 assignment or function argument
393 - local variable is an array (or union containing an array),
394 regardless of array type or length
395 - uses register local variables
396
397 This feature requires gcc version 4.9 or above, or a distribution
398 gcc with the feature backported ("-fstack-protector-strong").
399
400 On an x86 "defconfig" build, this feature adds canary checks to
401 about 20% of all kernel functions, which increases the kernel code
402 size by about 2%.
403
404endchoice
405
339config HAVE_CONTEXT_TRACKING 406config HAVE_CONTEXT_TRACKING
340 bool 407 bool
341 help 408 help
diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index c1f1a7eee953..9c909fc29272 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -30,6 +30,7 @@ config ARM
30 select HAVE_BPF_JIT 30 select HAVE_BPF_JIT
31 select HAVE_CONTEXT_TRACKING 31 select HAVE_CONTEXT_TRACKING
32 select HAVE_C_RECORDMCOUNT 32 select HAVE_C_RECORDMCOUNT
33 select HAVE_CC_STACKPROTECTOR
33 select HAVE_DEBUG_KMEMLEAK 34 select HAVE_DEBUG_KMEMLEAK
34 select HAVE_DMA_API_DEBUG 35 select HAVE_DMA_API_DEBUG
35 select HAVE_DMA_ATTRS 36 select HAVE_DMA_ATTRS
@@ -1856,18 +1857,6 @@ config SECCOMP
1856 and the task is only allowed to execute a few safe syscalls 1857 and the task is only allowed to execute a few safe syscalls
1857 defined by each seccomp mode. 1858 defined by each seccomp mode.
1858 1859
1859config 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
1871config SWIOTLB 1860config SWIOTLB
1872 def_bool y 1861 def_bool y
1873 1862
diff --git a/arch/arm/Makefile b/arch/arm/Makefile
index c99b1086d83d..55b4255ad6ed 100644
--- a/arch/arm/Makefile
+++ b/arch/arm/Makefile
@@ -40,10 +40,6 @@ ifeq ($(CONFIG_FRAME_POINTER),y)
40KBUILD_CFLAGS +=-fno-omit-frame-pointer -mapcs -mno-sched-prolog 40KBUILD_CFLAGS +=-fno-omit-frame-pointer -mapcs -mno-sched-prolog
41endif 41endif
42 42
43ifeq ($(CONFIG_CC_STACKPROTECTOR),y)
44KBUILD_CFLAGS +=-fstack-protector
45endif
46
47ifeq ($(CONFIG_CPU_BIG_ENDIAN),y) 43ifeq ($(CONFIG_CPU_BIG_ENDIAN),y)
48KBUILD_CPPFLAGS += -mbig-endian 44KBUILD_CPPFLAGS += -mbig-endian
49AS += -EB 45AS += -EB
diff --git a/arch/arm/boot/compressed/misc.c b/arch/arm/boot/compressed/misc.c
index 31bd43b82095..d4f891f56996 100644
--- a/arch/arm/boot/compressed/misc.c
+++ b/arch/arm/boot/compressed/misc.c
@@ -127,6 +127,18 @@ asmlinkage void __div0(void)
127 error("Attempting division by 0!"); 127 error("Attempting division by 0!");
128} 128}
129 129
130unsigned long __stack_chk_guard;
131
132void __stack_chk_guard_setup(void)
133{
134 __stack_chk_guard = 0x000a0dff;
135}
136
137void __stack_chk_fail(void)
138{
139 error("stack-protector: Kernel stack is corrupted\n");
140}
141
130extern int do_decompress(u8 *input, int len, u8 *output, void (*error)(char *x)); 142extern int do_decompress(u8 *input, int len, u8 *output, void (*error)(char *x));
131 143
132 144
@@ -137,6 +149,8 @@ decompress_kernel(unsigned long output_start, unsigned long free_mem_ptr_p,
137{ 149{
138 int ret; 150 int ret;
139 151
152 __stack_chk_guard_setup();
153
140 output_data = (unsigned char *)output_start; 154 output_data = (unsigned char *)output_start;
141 free_mem_ptr = free_mem_ptr_p; 155 free_mem_ptr = free_mem_ptr_p;
142 free_mem_end_ptr = free_mem_ptr_end_p; 156 free_mem_end_ptr = free_mem_ptr_end_p;
diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
index 650de3976e7a..c93d92beb3d6 100644
--- a/arch/mips/Kconfig
+++ b/arch/mips/Kconfig
@@ -47,6 +47,7 @@ config MIPS
47 select MODULES_USE_ELF_RELA if MODULES && 64BIT 47 select MODULES_USE_ELF_RELA if MODULES && 64BIT
48 select CLONE_BACKWARDS 48 select CLONE_BACKWARDS
49 select HAVE_DEBUG_STACKOVERFLOW 49 select HAVE_DEBUG_STACKOVERFLOW
50 select HAVE_CC_STACKPROTECTOR
50 51
51menu "Machine selection" 52menu "Machine selection"
52 53
@@ -2322,19 +2323,6 @@ config SECCOMP
2322 2323
2323 If unsure, say Y. Only embedded should say N here. 2324 If unsure, say Y. Only embedded should say N here.
2324 2325
2325config 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
2338config USE_OF 2326config USE_OF
2339 bool 2327 bool
2340 select OF 2328 select OF
diff --git a/arch/mips/Makefile b/arch/mips/Makefile
index de300b993607..efe50787cd89 100644
--- a/arch/mips/Makefile
+++ b/arch/mips/Makefile
@@ -232,10 +232,6 @@ bootvars-y = VMLINUX_LOAD_ADDRESS=$(load-y) \
232 232
233LDFLAGS += -m $(ld-emul) 233LDFLAGS += -m $(ld-emul)
234 234
235ifdef CONFIG_CC_STACKPROTECTOR
236 KBUILD_CFLAGS += -fstack-protector
237endif
238
239ifdef CONFIG_MIPS 235ifdef CONFIG_MIPS
240CHECKFLAGS += $(shell $(CC) $(KBUILD_CFLAGS) -dM -E -x c /dev/null | \ 236CHECKFLAGS += $(shell $(CC) $(KBUILD_CFLAGS) -dM -E -x c /dev/null | \
241 egrep -vw '__GNUC_(|MINOR_|PATCHLEVEL_)_' | \ 237 egrep -vw '__GNUC_(|MINOR_|PATCHLEVEL_)_' | \
diff --git a/arch/sh/Kconfig b/arch/sh/Kconfig
index 9b0979f4df7a..ce298317a73e 100644
--- a/arch/sh/Kconfig
+++ b/arch/sh/Kconfig
@@ -66,6 +66,7 @@ config SUPERH32
66 select PERF_EVENTS 66 select PERF_EVENTS
67 select ARCH_HIBERNATION_POSSIBLE if MMU 67 select ARCH_HIBERNATION_POSSIBLE if MMU
68 select SPARSE_IRQ 68 select SPARSE_IRQ
69 select HAVE_CC_STACKPROTECTOR
69 70
70config SUPERH64 71config SUPERH64
71 def_bool ARCH = "sh64" 72 def_bool ARCH = "sh64"
@@ -695,20 +696,6 @@ config SECCOMP
695 696
696 If unsure, say N. 697 If unsure, say N.
697 698
698config 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
712config SMP 699config SMP
713 bool "Symmetric multi-processing support" 700 bool "Symmetric multi-processing support"
714 depends on SYS_SUPPORTS_SMP 701 depends on SYS_SUPPORTS_SMP
diff --git a/arch/sh/Makefile b/arch/sh/Makefile
index aed701c7b11b..d4d16e4be07c 100644
--- a/arch/sh/Makefile
+++ b/arch/sh/Makefile
@@ -199,10 +199,6 @@ ifeq ($(CONFIG_DWARF_UNWINDER),y)
199 KBUILD_CFLAGS += -fasynchronous-unwind-tables 199 KBUILD_CFLAGS += -fasynchronous-unwind-tables
200endif 200endif
201 201
202ifeq ($(CONFIG_CC_STACKPROTECTOR),y)
203 KBUILD_CFLAGS += -fstack-protector
204endif
205
206libs-$(CONFIG_SUPERH32) := arch/sh/lib/ $(libs-y) 202libs-$(CONFIG_SUPERH32) := arch/sh/lib/ $(libs-y)
207libs-$(CONFIG_SUPERH64) := arch/sh/lib64/ $(libs-y) 203libs-$(CONFIG_SUPERH64) := arch/sh/lib64/ $(libs-y)
208 204
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 0952ecd60eca..838e7c34dd60 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -125,6 +125,7 @@ config X86
125 select RTC_LIB 125 select RTC_LIB
126 select HAVE_DEBUG_STACKOVERFLOW 126 select HAVE_DEBUG_STACKOVERFLOW
127 select HAVE_IRQ_EXIT_ON_IRQ_STACK if X86_64 127 select HAVE_IRQ_EXIT_ON_IRQ_STACK if X86_64
128 select HAVE_CC_STACKPROTECTOR
128 129
129config INSTRUCTION_DECODER 130config INSTRUCTION_DECODER
130 def_bool y 131 def_bool y
@@ -1617,22 +1618,6 @@ config SECCOMP
1617 1618
1618 If unsure, say Y. Only embedded should say N here. 1619 If unsure, say Y. Only embedded should say N here.
1619 1620
1620config 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
1636source kernel/Kconfig.hz 1621source kernel/Kconfig.hz
1637 1622
1638config KEXEC 1623config KEXEC
diff --git a/arch/x86/Makefile b/arch/x86/Makefile
index 57d021507120..13b22e0f681d 100644
--- a/arch/x86/Makefile
+++ b/arch/x86/Makefile
@@ -89,13 +89,11 @@ else
89 KBUILD_CFLAGS += -maccumulate-outgoing-args 89 KBUILD_CFLAGS += -maccumulate-outgoing-args
90endif 90endif
91 91
92# Make sure compiler does not have buggy stack-protector support.
92ifdef CONFIG_CC_STACKPROTECTOR 93ifdef CONFIG_CC_STACKPROTECTOR
93 cc_has_sp := $(srctree)/scripts/gcc-x86_$(BITS)-has-stack-protector.sh 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 ifneq ($(shell $(CONFIG_SHELL) $(cc_has_sp) $(CC) $(KBUILD_CPPFLAGS) $(biarch)),y)
95 stackp-y := -fstack-protector 96 $(warning stack-protector enabled but compiler support broken)
96 KBUILD_CFLAGS += $(stackp-y)
97 else
98 $(warning stack protector enabled but no compiler support)
99 endif 97 endif
100endif 98endif
101 99