aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKees Cook <keescook@chromium.org>2013-12-19 14:35:58 -0500
committerIngo Molnar <mingo@kernel.org>2013-12-20 03:38:40 -0500
commit19952a92037e752f9d3bbbad552d596f9a56e146 (patch)
tree8a1930b4775cb17865c03faf55eafdd7b97be8ba
parentb0031f227e47919797dc0e1c1990f3ef151ff0cc (diff)
stackprotector: Unify the HAVE_CC_STACKPROTECTOR logic between architectures
Instead of duplicating the CC_STACKPROTECTOR Kconfig and Makefile logic in each architecture, switch to using HAVE_CC_STACKPROTECTOR and keep everything in one place. This retains the x86-specific bug verification scripts. Signed-off-by: Kees Cook <keescook@chromium.org> Cc: Arjan van de Ven <arjan@linux.intel.com> Cc: Michal Marek <mmarek@suse.cz> Cc: Russell King <linux@arm.linux.org.uk> Cc: Ralf Baechle <ralf@linux-mips.org> Cc: Paul Mundt <lethal@linux-sh.org> Cc: James Hogan <james.hogan@imgtec.com> Cc: Stephen Rothwell <sfr@canb.auug.org.au> Cc: Shawn Guo <shawn.guo@linaro.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: linux-arm-kernel@lists.infradead.org Cc: linux-mips@linux-mips.org Cc: linux-arch@vger.kernel.org Link: http://lkml.kernel.org/r/1387481759-14535-2-git-send-email-keescook@chromium.org Signed-off-by: Ingo Molnar <mingo@kernel.org>
-rw-r--r--Makefile14
-rw-r--r--arch/Kconfig22
-rw-r--r--arch/arm/Kconfig13
-rw-r--r--arch/arm/Makefile4
-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
10 files changed, 40 insertions, 75 deletions
diff --git a/Makefile b/Makefile
index 858a147fd836..84fb5cd092d2 100644
--- a/Makefile
+++ b/Makefile
@@ -595,10 +595,18 @@ 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
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
606 # Force off for distro compilers that enable stack protector by default.
607 stackp-flag := $(call cc-option, -fno-stack-protector)
601endif 608endif
609KBUILD_CFLAGS += $(stackp-flag)
602 610
603# This warning generated too much noise in a regular build. 611# This warning generated too much noise in a regular build.
604# Use make W=1 to enable this warning (see scripts/Makefile.build) 612# Use make W=1 to enable this warning (see scripts/Makefile.build)
diff --git a/arch/Kconfig b/arch/Kconfig
index f1cf895c040f..24e026d83072 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -336,6 +336,28 @@ 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 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
339config HAVE_CONTEXT_TRACKING 361config HAVE_CONTEXT_TRACKING
340 bool 362 bool
341 help 363 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/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