From: Masahiro Yamada <yamada.masahiro@socionext.com>
To: Kees Cook <keescook@chromium.org>
Cc: linux-kbuild <linux-kbuild@vger.kernel.org>,
Linus Torvalds <torvalds@linux-foundation.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Andrew Morton <akpm@linux-foundation.org>,
Nicolas Pitre <nicolas.pitre@linaro.org>,
"Luis R . Rodriguez" <mcgrof@suse.com>,
Randy Dunlap <rdunlap@infradead.org>,
Ulf Magnusson <ulfalizer@gmail.com>,
Sam Ravnborg <sam@ravnborg.org>,
Michal Marek <michal.lkml@markovi.net>,
Martin Schwidefsky <schwidefsky@de.ibm.com>,
Pavel Machek <pavel@ucw.cz>,
linux-s390 <linux-s390@vger.kernel.org>,
Jiri Kosina <jkosina@suse.cz>,
LKML <linux-kernel@vger.kernel.org>
Subject: Re: [RFC PATCH 7/7] Test stackprotector options in Kconfig to kill CC_STACKPROTECTOR_AUTO
Date: Fri, 9 Feb 2018 13:13:43 +0900 [thread overview]
Message-ID: <CAK7LNAQiY7rixHGbuLynRFKUeCDon4dMS+LdxSD4o2SbSp7Kbg@mail.gmail.com> (raw)
In-Reply-To: <CAGXu5jJ02qRCcqTK_M9sFtekizz+0WoHBCBKF_mh-A870eg6eg@mail.gmail.com>
2018-02-09 3:30 GMT+09:00 Kees Cook <keescook@chromium.org>:
> On Fri, Feb 9, 2018 at 3:19 AM, Masahiro Yamada
> <yamada.masahiro@socionext.com> wrote:
>> Add CC_HAS_STACKPROTECTOR(_STRONG) and proper dependency.
>>
>> I re-arranged the choice values, _STRONG, _REGULAR, _NONE in this order
>> because the default of choice is the first visible symbol.
>> [...]
>> +# is this necessary?
>> +#ifeq ($(CONFIG_CC_STACKPROTECTOR_NONE),y)
>> +#KBUILD_CFLAGS += -fno-stack-protector
>> +#endif
>
> Yes, and also in the case of a broken stack protector, because some
> compilers enable stack protector by default, so if we've selected it
> to be NONE or detected it as broken, we need to force it off in the
> compiler.
>
>> +# TODO: run scripts/gcc-$(SRCARCH)_$(BITS)-has-stack-protector.sh from Kconfig
>
> FWIW, this is the part that I got stuck on.
> gcc-$(SRCARCH)_$(BITS)-has-stack-protector.sh depends on the KBUILD
> flags that got built up and detected up to this point in the Makefile,
> so I couldn't find a way to run it out of Kconfig since it didn't know
> what the KBUILD flags were yet.
SRCARCH is fixed when loading Kconfig files.
BITS is derived from CONFIG_64BIT.
config 64BIT
bool "64-bit kernel" if ARCH = "x86"
default ARCH != "i386"
---help---
Say yes to build a 64-bit kernel - formerly known as x86_64
Say no to build a 32-bit kernel - formerly known as i386
This is a more difficult part because users can toggle this option
from menuconfig, etc.
If this option is changed, the compiler options must be re-computed,
i.e. system() must be called again.
This is missing in my first draft.
I have not checked how slow it is.
>> +
>> ifeq ($(cc-name),clang)
>> KBUILD_CPPFLAGS += $(call cc-option,-Qunused-arguments,)
>> KBUILD_CFLAGS += $(call cc-disable-warning, unused-variable)
>> diff --git a/arch/Kconfig b/arch/Kconfig
>> index 76c0b54..50723d8 100644
>> --- a/arch/Kconfig
>> +++ b/arch/Kconfig
>> @@ -538,10 +538,20 @@ config HAVE_CC_STACKPROTECTOR
>> - its compiler supports the -fstack-protector option
>> - it has implemented a stack canary (e.g. __stack_chk_guard)
>>
>> +config CC_HAS_STACKPROTECTOR
>> + bool
>> + option shell="$CC -Werror -fstack-protector -c -x c /dev/null"
>> +
>> +config CC_HAS_STACKPROTECTOR_STRONG
>> + bool
>> + option shell="$CC -Werror -fstack-protector-strong -c -x c /dev/null"
>
> I'm nervous we'll get tripped up here, since $CC may not include the
> right $(KBUILD_CPPFLAGS) and $(CC_OPTION_CFLAGS) as in cc-option, both
> of which are calculated during the Makefile run. But maybe it won't be
> a problem in actual use.
Right, I had noticed this is a problem, but not implemented yet.
At least, some basic compiler options must be imported into Kconfig.
Especially this is a problem for clang.
One clang executable is built with lots of
architecture back-ends.
So,
CLANG_TARGET := --target=$(notdir $(CROSS_COMPILE:%-=%))
etc. is mandatory.
If I remember correctly, there existed some options
that depend on others.
I am not sure about the stackprotector case.
>> +
>> +config CC_STACKPROTECTOR
>> + bool
>> +
>> choice
>> prompt "Stack Protector buffer overflow detection"
>> depends on HAVE_CC_STACKPROTECTOR
>> - default CC_STACKPROTECTOR_AUTO
>> help
>> This option turns on the "stack-protector" GCC feature. This
>> feature puts, at the beginning of functions, a canary value on
>> @@ -551,26 +561,10 @@ choice
>> overwrite the canary, which gets detected and the attack is then
>> neutralized via a kernel panic.
>>
>> -config CC_STACKPROTECTOR_NONE
>> - bool "None"
>> - help
>> - Disable "stack-protector" GCC feature.
>> -
>> -config CC_STACKPROTECTOR_REGULAR
>> - bool "Regular"
>> - help
>> - Functions will have the stack-protector canary logic added if they
>> - have an 8-byte or larger character array on the stack.
>> -
>> - This feature requires gcc version 4.2 or above, or a distribution
>> - gcc with the feature backported ("-fstack-protector").
>> -
>> - On an x86 "defconfig" build, this feature adds canary checks to
>> - about 3% of all kernel functions, which increases kernel code size
>> - by about 0.3%.
>> -
>> config CC_STACKPROTECTOR_STRONG
>> bool "Strong"
>> + depends on CC_HAS_STACKPROTECTOR_STRONG
>> + select CC_STACKPROTECTOR
>> help
>> Functions will have the stack-protector canary logic added in any
>> of the following conditions:
>> @@ -588,11 +582,25 @@ config CC_STACKPROTECTOR_STRONG
>> about 20% of all kernel functions, which increases the kernel code
>> size by about 2%.
>>
>> -config CC_STACKPROTECTOR_AUTO
>> - bool "Automatic"
>> +config CC_STACKPROTECTOR_REGULAR
>> + bool "Regular"
>> + depends on CC_HAS_STACKPROTECTOR
>> + select CC_STACKPROTECTOR
>> + help
>> + Functions will have the stack-protector canary logic added if they
>> + have an 8-byte or larger character array on the stack.
>> +
>> + This feature requires gcc version 4.2 or above, or a distribution
>> + gcc with the feature backported ("-fstack-protector").
>> +
>> + On an x86 "defconfig" build, this feature adds canary checks to
>> + about 3% of all kernel functions, which increases kernel code size
>> + by about 0.3%.
>> +
>> +config CC_STACKPROTECTOR_NONE
>> + bool "None"
>> help
>> - If the compiler supports it, the best available stack-protector
>> - option will be chosen.
>> + Disable "stack-protector" GCC feature.
>>
>> endchoice
>
> I continue to love the idea, but we can't know a given ssp option is
> _working_ until we run the test script, which may depend on compiler
> flags. Regardless, I'll give this series a try and see if I can fix
> anything I trip over. I've got a lot of notes on testing after getting
> ..._AUTO working. Whatever happens, I hugely prefer having the
> automatic selection possible in the Kconfig! Thanks for working on
> this! :)
Yes, your help is appreciated.
We will find more TODO items during trial and error. :)
--
Best Regards
Masahiro Yamada
next prev parent reply other threads:[~2018-02-09 4:13 UTC|newest]
Thread overview: 86+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-08 16:19 [RFC PATCH 0/7] Kconfig: add new special property shell= to test compiler options in Kconfig Masahiro Yamada
2018-02-08 16:19 ` [RFC PATCH 1/7] kbuild: remove kbuild cache Masahiro Yamada
2018-02-08 16:19 ` [RFC PATCH 2/7] kconfig: add xrealloc() helper Masahiro Yamada
2018-02-08 16:19 ` [RFC PATCH 3/7] kconfig: remove const qualifier from sym_expand_string_value() Masahiro Yamada
2018-02-08 16:19 ` [RFC PATCH 4/7] kconfig: support new special property shell= Masahiro Yamada
2018-02-09 5:30 ` Ulf Magnusson
2018-02-09 9:19 ` Masahiro Yamada
2018-02-09 12:46 ` Ulf Magnusson
2018-02-09 20:46 ` Kees Cook
2018-02-10 5:48 ` Ulf Magnusson
2018-02-10 7:12 ` Masahiro Yamada
2018-02-10 7:49 ` Ulf Magnusson
2018-02-10 8:05 ` Ulf Magnusson
2018-02-10 8:55 ` Ulf Magnusson
2018-02-10 9:21 ` Ulf Magnusson
2018-02-10 18:05 ` Randy Dunlap
2018-02-11 2:00 ` Kevin Easton
2018-02-10 19:23 ` Kees Cook
2018-02-10 20:08 ` Linus Torvalds
2018-02-11 4:13 ` Kees Cook
2018-02-11 4:46 ` Linus Torvalds
2018-02-11 7:28 ` Linus Torvalds
2018-02-11 10:34 ` Ulf Magnusson
2018-02-11 17:56 ` Kees Cook
2018-02-11 18:13 ` Linus Torvalds
2018-02-11 19:39 ` Kees Cook
2018-02-11 19:53 ` Linus Torvalds
2018-02-11 20:06 ` Linus Torvalds
2018-02-11 21:10 ` Arnd Bergmann
2018-02-11 21:19 ` Kees Cook
2018-02-11 21:50 ` Linus Torvalds
2018-02-12 10:44 ` Arnd Bergmann
2018-02-11 22:29 ` Geert Uytterhoeven
2018-02-15 23:38 ` [RFC PATCH 4/7] kconfig: support new special property shell Palmer Dabbelt
2018-02-11 21:11 ` [RFC PATCH 4/7] kconfig: support new special property shell= Kees Cook
2018-02-11 19:42 ` Linus Torvalds
2018-02-12 8:26 ` Peter Zijlstra
2018-02-12 10:27 ` Thomas Gleixner
2018-02-12 11:52 ` Peter Zijlstra
2018-02-12 16:19 ` David Woodhouse
2018-02-12 16:56 ` Kees Cook
2018-02-12 17:05 ` Peter Zijlstra
2018-02-12 17:33 ` Kees Cook
2018-02-12 17:36 ` David Woodhouse
2018-02-12 17:37 ` Kees Cook
2018-02-12 17:00 ` Peter Zijlstra
2018-02-11 18:34 ` Ulf Magnusson
2018-02-11 21:05 ` Kees Cook
2018-02-11 21:35 ` Ulf Magnusson
2018-02-11 20:29 ` Ulf Magnusson
2018-02-11 20:42 ` Ulf Magnusson
2018-02-12 12:54 ` Ulf Magnusson
2018-02-12 14:21 ` Masahiro Yamada
2018-02-12 14:23 ` Masahiro Yamada
2018-02-12 14:32 ` Ulf Magnusson
2018-02-12 14:29 ` Ulf Magnusson
2018-02-12 14:53 ` Ulf Magnusson
2018-02-12 15:22 ` Masahiro Yamada
2018-02-12 15:35 ` Ulf Magnusson
2018-02-11 21:22 ` Ulf Magnusson
2018-02-12 14:39 ` Masahiro Yamada
2018-02-12 15:24 ` Kees Cook
2018-02-12 23:48 ` Randy Dunlap
2018-02-13 1:41 ` Masahiro Yamada
2018-02-13 1:53 ` Randy Dunlap
2018-02-13 8:35 ` Arnd Bergmann
2018-02-13 8:59 ` Masahiro Yamada
2018-02-12 10:44 ` Masahiro Yamada
2018-02-12 11:44 ` Ulf Magnusson
2018-02-12 11:49 ` Ulf Magnusson
2018-02-12 13:53 ` Masahiro Yamada
2018-02-12 14:13 ` Ulf Magnusson
2018-02-12 15:46 ` Kees Cook
2018-02-12 16:10 ` Masahiro Yamada
2018-02-13 8:55 ` Ulf Magnusson
2018-02-11 16:54 ` Kees Cook
2018-02-08 16:19 ` [RFC PATCH 5/7] kconfig: invoke silentoldconfig when compiler is updated Masahiro Yamada
2018-02-08 17:19 ` Masahiro Yamada
2018-02-08 17:45 ` Linus Torvalds
2018-02-08 16:19 ` [RFC PATCH 6/7] kconfig: add basic environments to evaluate C flags in Kconfig Masahiro Yamada
2018-02-08 16:19 ` [RFC PATCH 7/7] Test stackprotector options in Kconfig to kill CC_STACKPROTECTOR_AUTO Masahiro Yamada
2018-02-08 18:30 ` Kees Cook
2018-02-09 4:13 ` Masahiro Yamada [this message]
2018-02-08 16:43 ` [RFC PATCH 0/7] Kconfig: add new special property shell= to test compiler options in Kconfig Greg Kroah-Hartman
2018-02-08 17:19 ` Linus Torvalds
2018-02-08 17:39 ` Masahiro Yamada
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAK7LNAQiY7rixHGbuLynRFKUeCDon4dMS+LdxSD4o2SbSp7Kbg@mail.gmail.com \
--to=yamada.masahiro@socionext.com \
--cc=akpm@linux-foundation.org \
--cc=gregkh@linuxfoundation.org \
--cc=jkosina@suse.cz \
--cc=keescook@chromium.org \
--cc=linux-kbuild@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=mcgrof@suse.com \
--cc=michal.lkml@markovi.net \
--cc=nicolas.pitre@linaro.org \
--cc=pavel@ucw.cz \
--cc=rdunlap@infradead.org \
--cc=sam@ravnborg.org \
--cc=schwidefsky@de.ibm.com \
--cc=torvalds@linux-foundation.org \
--cc=ulfalizer@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).