All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kees Cook <keescook@chromium.org>
To: Greg KH <greg@kroah.com>
Cc: Masahiro Yamada <yamada.masahiro@socionext.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Michal Marek <mmarek@suse.com>, Ingo Molnar <mingo@kernel.org>,
	Laura Abbott <labbott@redhat.com>,
	Nicholas Piggin <npiggin@gmail.com>,
	Al Viro <viro@zeniv.linux.org.uk>,
	Linux Kbuild mailing list <linux-kbuild@vger.kernel.org>,
	Yoshinori Sato <ysato@users.sourceforge.jp>,
	Rich Felker <dalias@libc.org>,
	"David S. Miller" <davem@davemloft.net>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	linux-sh <linux-sh@vger.kernel.org>,
	"kernel-hardening@lists.openwall.com"
	<kernel-hardening@lists.openwall.com>,
	Mark Rutland <mark.rutland@arm.com>
Subject: Re: [kernel-hardening] Re: [PATCH 2/3] Makefile: Move stackprotector availability out of Kconfig
Date: Wed, 04 Oct 2017 16:22:24 +0000	[thread overview]
Message-ID: <CAGXu5jKqt=DgMVKS8znL05scbXdxRhgkaf7D5ipYA3Q=csLB5A@mail.gmail.com> (raw)
In-Reply-To: <20171004151312.GA20938@kroah.com>

On Wed, Oct 4, 2017 at 8:13 AM, Greg KH <greg@kroah.com> wrote:
> On Wed, Oct 04, 2017 at 11:33:38PM +0900, Masahiro Yamada wrote:
>> Hi Kees,
>>
>>
>> 2017-10-03 4:20 GMT+09:00 Kees Cook <keescook@chromium.org>:
>> > Various portions of the kernel, especially per-architecture pieces,
>> > need to know if the compiler is building it with the stack protector.
>> > This was done in the arch/Kconfig with 'select', but this doesn't
>> > allow a way to do auto-detected compiler support. In preparation for
>> > creating an on-if-available default, move the logic for the definition of
>> > CONFIG_CC_STACKPROTECTOR into the Makefile.
>> >
>> > Cc: Masahiro Yamada <yamada.masahiro@socionext.com>
>> > Cc: Michal Marek <mmarek@suse.com>
>> > Cc: Andrew Morton <akpm@linux-foundation.org>
>> > Cc: Ingo Molnar <mingo@kernel.org>
>> > Cc: Laura Abbott <labbott@redhat.com>
>> > Cc: Nicholas Piggin <npiggin@gmail.com>
>> > Cc: Al Viro <viro@zeniv.linux.org.uk>
>> > Cc: linux-kbuild@vger.kernel.org
>> > Signed-off-by: Kees Cook <keescook@chromium.org>
>> > ---
>> >  Makefile     | 7 +++++--
>> >  arch/Kconfig | 8 --------
>> >  2 files changed, 5 insertions(+), 10 deletions(-)
>> >
>> > diff --git a/Makefile b/Makefile
>> > index d1119941261c..e122a9cf0399 100644
>> > --- a/Makefile
>> > +++ b/Makefile
>> > @@ -688,8 +688,11 @@ else
>> >    stackp-flag := $(call cc-option, -fno-stack-protector)
>> >  endif
>> >  endif
>> > -# Find arch-specific stack protector compiler sanity-checking script.
>> > -ifdef CONFIG_CC_STACKPROTECTOR
>> > +ifdef stackp-name
>> > +  # If the stack protector has been selected, inform the rest of the build.
>> > +  KBUILD_CFLAGS += -DCONFIG_CC_STACKPROTECTOR
>> > +  KBUILD_AFLAGS += -DCONFIG_CC_STACKPROTECTOR
>> > +  # Find arch-specific stack protector compiler sanity-checking script.
>> >    stackp-path := $(srctree)/scripts/gcc-$(SRCARCH)_$(BITS)-has-stack-protector.sh
>> >    stackp-check := $(wildcard $(stackp-path))
>> >  endif
>>
>>
>> I have not tested this series,
>> but I think this commit is bad (with the follow-up patch applied).
>>
>>
>> I thought of this scenario:
>>
>> [1] Kernel is configured with CONFIG_CC_STACKPROTECTOR_AUTO
>>
>> [2] Kernel is built with a compiler without stack protector support.
>>
>> [3] CONFIG_CC_STACKPROTECTOR is not defined,
>>     so __stack_chk_fail() is not compiled.
>>
>> [4] Out-of-tree modules are compiled with a compiler with
>>     stack protector support.
>>     __stack_chk_fail() is inserted to functions of the modules.
>
> We don't ever support the system of loading a module built with anything
> other than the _exact_ same compiler than the kernel was.  So this will
> not happen (well, if someone tries it, they get to keep the pieces their
> kernel image is now in...)
>
>> [5] insmod fails because reference to __stack_chk_fail()
>>     can not be resolved.
>
> Even nicer, we failed "cleanly" :)
>
> This isn't a real-world issue, sorry.

If we wanted a slightly different failure, we could simply add the
stack protection feature to the VERMAGIC_STRING define:

diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
index af6c03f7f986..300163aba666 100644
--- a/include/linux/vermagic.h
+++ b/include/linux/vermagic.h
@@ -30,11 +30,19 @@
 #else
 #define MODULE_RANDSTRUCT_PLUGIN
 #endif
+#if defined(__SSP__)
+#define MODULE_STACKPROTECTOR "stack-protector "
+#elif define (__SSP_STRONG__)
+#define MODULE_STACKPROTECTOR "stack-protector-strong "
+#else
+#define MODULE_STACKPROTECTOR ""
+#endif

 #define VERMAGIC_STRING                                                \
        UTS_RELEASE " "                                                 \
        MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT                     \
        MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS       \
        MODULE_ARCH_VERMAGIC                                            \
+       MODULE_STACKPROTECTOR                                           \
        MODULE_RANDSTRUCT_PLUGIN


Do you want me to send this patch, or should we allow it to fail with
the "missing reference" (which may actually be more expressive...) I
think the way it is right now is better, but I'm open to either.

-Kees

-- 
Kees Cook
Pixel Security

WARNING: multiple messages have this Message-ID (diff)
From: Kees Cook <keescook@chromium.org>
To: Greg KH <greg@kroah.com>
Cc: Masahiro Yamada <yamada.masahiro@socionext.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Michal Marek <mmarek@suse.com>, Ingo Molnar <mingo@kernel.org>,
	Laura Abbott <labbott@redhat.com>,
	Nicholas Piggin <npiggin@gmail.com>,
	Al Viro <viro@zeniv.linux.org.uk>,
	Linux Kbuild mailing list <linux-kbuild@vger.kernel.org>,
	Yoshinori Sato <ysato@users.sourceforge.jp>,
	Rich Felker <dalias@libc.org>,
	"David S. Miller" <davem@davemloft.net>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	linux-sh <linux-sh@vger.kernel.org>,
	"kernel-hardening@lists.openwall.com" 
	<kernel-hardening@lists.openwall.com>,
	Mark Rutland <mark.rutland@arm.com>
Subject: Re: [kernel-hardening] Re: [PATCH 2/3] Makefile: Move stackprotector availability out of Kconfig
Date: Wed, 4 Oct 2017 09:22:24 -0700	[thread overview]
Message-ID: <CAGXu5jKqt=DgMVKS8znL05scbXdxRhgkaf7D5ipYA3Q=csLB5A@mail.gmail.com> (raw)
In-Reply-To: <20171004151312.GA20938@kroah.com>

On Wed, Oct 4, 2017 at 8:13 AM, Greg KH <greg@kroah.com> wrote:
> On Wed, Oct 04, 2017 at 11:33:38PM +0900, Masahiro Yamada wrote:
>> Hi Kees,
>>
>>
>> 2017-10-03 4:20 GMT+09:00 Kees Cook <keescook@chromium.org>:
>> > Various portions of the kernel, especially per-architecture pieces,
>> > need to know if the compiler is building it with the stack protector.
>> > This was done in the arch/Kconfig with 'select', but this doesn't
>> > allow a way to do auto-detected compiler support. In preparation for
>> > creating an on-if-available default, move the logic for the definition of
>> > CONFIG_CC_STACKPROTECTOR into the Makefile.
>> >
>> > Cc: Masahiro Yamada <yamada.masahiro@socionext.com>
>> > Cc: Michal Marek <mmarek@suse.com>
>> > Cc: Andrew Morton <akpm@linux-foundation.org>
>> > Cc: Ingo Molnar <mingo@kernel.org>
>> > Cc: Laura Abbott <labbott@redhat.com>
>> > Cc: Nicholas Piggin <npiggin@gmail.com>
>> > Cc: Al Viro <viro@zeniv.linux.org.uk>
>> > Cc: linux-kbuild@vger.kernel.org
>> > Signed-off-by: Kees Cook <keescook@chromium.org>
>> > ---
>> >  Makefile     | 7 +++++--
>> >  arch/Kconfig | 8 --------
>> >  2 files changed, 5 insertions(+), 10 deletions(-)
>> >
>> > diff --git a/Makefile b/Makefile
>> > index d1119941261c..e122a9cf0399 100644
>> > --- a/Makefile
>> > +++ b/Makefile
>> > @@ -688,8 +688,11 @@ else
>> >    stackp-flag := $(call cc-option, -fno-stack-protector)
>> >  endif
>> >  endif
>> > -# Find arch-specific stack protector compiler sanity-checking script.
>> > -ifdef CONFIG_CC_STACKPROTECTOR
>> > +ifdef stackp-name
>> > +  # If the stack protector has been selected, inform the rest of the build.
>> > +  KBUILD_CFLAGS += -DCONFIG_CC_STACKPROTECTOR
>> > +  KBUILD_AFLAGS += -DCONFIG_CC_STACKPROTECTOR
>> > +  # Find arch-specific stack protector compiler sanity-checking script.
>> >    stackp-path := $(srctree)/scripts/gcc-$(SRCARCH)_$(BITS)-has-stack-protector.sh
>> >    stackp-check := $(wildcard $(stackp-path))
>> >  endif
>>
>>
>> I have not tested this series,
>> but I think this commit is bad (with the follow-up patch applied).
>>
>>
>> I thought of this scenario:
>>
>> [1] Kernel is configured with CONFIG_CC_STACKPROTECTOR_AUTO
>>
>> [2] Kernel is built with a compiler without stack protector support.
>>
>> [3] CONFIG_CC_STACKPROTECTOR is not defined,
>>     so __stack_chk_fail() is not compiled.
>>
>> [4] Out-of-tree modules are compiled with a compiler with
>>     stack protector support.
>>     __stack_chk_fail() is inserted to functions of the modules.
>
> We don't ever support the system of loading a module built with anything
> other than the _exact_ same compiler than the kernel was.  So this will
> not happen (well, if someone tries it, they get to keep the pieces their
> kernel image is now in...)
>
>> [5] insmod fails because reference to __stack_chk_fail()
>>     can not be resolved.
>
> Even nicer, we failed "cleanly" :)
>
> This isn't a real-world issue, sorry.

If we wanted a slightly different failure, we could simply add the
stack protection feature to the VERMAGIC_STRING define:

diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
index af6c03f7f986..300163aba666 100644
--- a/include/linux/vermagic.h
+++ b/include/linux/vermagic.h
@@ -30,11 +30,19 @@
 #else
 #define MODULE_RANDSTRUCT_PLUGIN
 #endif
+#if defined(__SSP__)
+#define MODULE_STACKPROTECTOR "stack-protector "
+#elif define (__SSP_STRONG__)
+#define MODULE_STACKPROTECTOR "stack-protector-strong "
+#else
+#define MODULE_STACKPROTECTOR ""
+#endif

 #define VERMAGIC_STRING                                                \
        UTS_RELEASE " "                                                 \
        MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT                     \
        MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS       \
        MODULE_ARCH_VERMAGIC                                            \
+       MODULE_STACKPROTECTOR                                           \
        MODULE_RANDSTRUCT_PLUGIN


Do you want me to send this patch, or should we allow it to fail with
the "missing reference" (which may actually be more expressive...) I
think the way it is right now is better, but I'm open to either.

-Kees

-- 
Kees Cook
Pixel Security

WARNING: multiple messages have this Message-ID (diff)
From: Kees Cook <keescook@chromium.org>
To: Greg KH <greg@kroah.com>
Cc: Masahiro Yamada <yamada.masahiro@socionext.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Michal Marek <mmarek@suse.com>, Ingo Molnar <mingo@kernel.org>,
	Laura Abbott <labbott@redhat.com>,
	Nicholas Piggin <npiggin@gmail.com>,
	Al Viro <viro@zeniv.linux.org.uk>,
	Linux Kbuild mailing list <linux-kbuild@vger.kernel.org>,
	Yoshinori Sato <ysato@users.sourceforge.jp>,
	Rich Felker <dalias@libc.org>,
	"David S. Miller" <davem@davemloft.net>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	linux-sh <linux-sh@vger.kernel.org>,
	"kernel-hardening@lists.openwall.com"
	<kernel-hardening@lists.openwall.com>,
	Mark Rutland <mark.rutland@arm.com>
Subject: Re: [kernel-hardening] Re: [PATCH 2/3] Makefile: Move stackprotector availability out of Kconfig
Date: Wed, 4 Oct 2017 09:22:24 -0700	[thread overview]
Message-ID: <CAGXu5jKqt=DgMVKS8znL05scbXdxRhgkaf7D5ipYA3Q=csLB5A@mail.gmail.com> (raw)
In-Reply-To: <20171004151312.GA20938@kroah.com>

On Wed, Oct 4, 2017 at 8:13 AM, Greg KH <greg@kroah.com> wrote:
> On Wed, Oct 04, 2017 at 11:33:38PM +0900, Masahiro Yamada wrote:
>> Hi Kees,
>>
>>
>> 2017-10-03 4:20 GMT+09:00 Kees Cook <keescook@chromium.org>:
>> > Various portions of the kernel, especially per-architecture pieces,
>> > need to know if the compiler is building it with the stack protector.
>> > This was done in the arch/Kconfig with 'select', but this doesn't
>> > allow a way to do auto-detected compiler support. In preparation for
>> > creating an on-if-available default, move the logic for the definition of
>> > CONFIG_CC_STACKPROTECTOR into the Makefile.
>> >
>> > Cc: Masahiro Yamada <yamada.masahiro@socionext.com>
>> > Cc: Michal Marek <mmarek@suse.com>
>> > Cc: Andrew Morton <akpm@linux-foundation.org>
>> > Cc: Ingo Molnar <mingo@kernel.org>
>> > Cc: Laura Abbott <labbott@redhat.com>
>> > Cc: Nicholas Piggin <npiggin@gmail.com>
>> > Cc: Al Viro <viro@zeniv.linux.org.uk>
>> > Cc: linux-kbuild@vger.kernel.org
>> > Signed-off-by: Kees Cook <keescook@chromium.org>
>> > ---
>> >  Makefile     | 7 +++++--
>> >  arch/Kconfig | 8 --------
>> >  2 files changed, 5 insertions(+), 10 deletions(-)
>> >
>> > diff --git a/Makefile b/Makefile
>> > index d1119941261c..e122a9cf0399 100644
>> > --- a/Makefile
>> > +++ b/Makefile
>> > @@ -688,8 +688,11 @@ else
>> >    stackp-flag := $(call cc-option, -fno-stack-protector)
>> >  endif
>> >  endif
>> > -# Find arch-specific stack protector compiler sanity-checking script.
>> > -ifdef CONFIG_CC_STACKPROTECTOR
>> > +ifdef stackp-name
>> > +  # If the stack protector has been selected, inform the rest of the build.
>> > +  KBUILD_CFLAGS += -DCONFIG_CC_STACKPROTECTOR
>> > +  KBUILD_AFLAGS += -DCONFIG_CC_STACKPROTECTOR
>> > +  # Find arch-specific stack protector compiler sanity-checking script.
>> >    stackp-path := $(srctree)/scripts/gcc-$(SRCARCH)_$(BITS)-has-stack-protector.sh
>> >    stackp-check := $(wildcard $(stackp-path))
>> >  endif
>>
>>
>> I have not tested this series,
>> but I think this commit is bad (with the follow-up patch applied).
>>
>>
>> I thought of this scenario:
>>
>> [1] Kernel is configured with CONFIG_CC_STACKPROTECTOR_AUTO
>>
>> [2] Kernel is built with a compiler without stack protector support.
>>
>> [3] CONFIG_CC_STACKPROTECTOR is not defined,
>>     so __stack_chk_fail() is not compiled.
>>
>> [4] Out-of-tree modules are compiled with a compiler with
>>     stack protector support.
>>     __stack_chk_fail() is inserted to functions of the modules.
>
> We don't ever support the system of loading a module built with anything
> other than the _exact_ same compiler than the kernel was.  So this will
> not happen (well, if someone tries it, they get to keep the pieces their
> kernel image is now in...)
>
>> [5] insmod fails because reference to __stack_chk_fail()
>>     can not be resolved.
>
> Even nicer, we failed "cleanly" :)
>
> This isn't a real-world issue, sorry.

If we wanted a slightly different failure, we could simply add the
stack protection feature to the VERMAGIC_STRING define:

diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
index af6c03f7f986..300163aba666 100644
--- a/include/linux/vermagic.h
+++ b/include/linux/vermagic.h
@@ -30,11 +30,19 @@
 #else
 #define MODULE_RANDSTRUCT_PLUGIN
 #endif
+#if defined(__SSP__)
+#define MODULE_STACKPROTECTOR "stack-protector "
+#elif define (__SSP_STRONG__)
+#define MODULE_STACKPROTECTOR "stack-protector-strong "
+#else
+#define MODULE_STACKPROTECTOR ""
+#endif

 #define VERMAGIC_STRING                                                \
        UTS_RELEASE " "                                                 \
        MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT                     \
        MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS       \
        MODULE_ARCH_VERMAGIC                                            \
+       MODULE_STACKPROTECTOR                                           \
        MODULE_RANDSTRUCT_PLUGIN


Do you want me to send this patch, or should we allow it to fail with
the "missing reference" (which may actually be more expressive...) I
think the way it is right now is better, but I'm open to either.

-Kees

-- 
Kees Cook
Pixel Security

  reply	other threads:[~2017-10-04 16:22 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-02 19:20 [PATCH 0/3] Makefile: Introduce CONFIG_CC_STACKPROTECTOR_AUTO Kees Cook
2017-10-02 19:20 ` [kernel-hardening] " Kees Cook
2017-10-02 19:20 ` Kees Cook
2017-10-02 19:20 ` [PATCH 1/3] sh/boot: Add static stack-protector to pre-kernel Kees Cook
2017-10-02 19:20   ` [kernel-hardening] " Kees Cook
2017-10-02 19:20   ` Kees Cook
2017-10-02 19:20 ` [PATCH 2/3] Makefile: Move stackprotector availability out of Kconfig Kees Cook
2017-10-02 19:20   ` [kernel-hardening] " Kees Cook
2017-10-02 19:20   ` Kees Cook
2017-10-04 14:33   ` Masahiro Yamada
2017-10-04 14:33     ` [kernel-hardening] " Masahiro Yamada
2017-10-04 14:33     ` Masahiro Yamada
2017-10-04 15:13     ` [kernel-hardening] " Greg KH
2017-10-04 15:13       ` Greg KH
2017-10-04 16:22       ` Kees Cook [this message]
2017-10-04 16:22         ` Kees Cook
2017-10-04 16:22         ` Kees Cook
2017-10-04 17:15         ` Greg KH
2017-10-04 17:15           ` Greg KH
2017-10-04 17:15           ` Greg KH
2017-10-02 19:20 ` [PATCH 3/3] Makefile: Introduce CONFIG_CC_STACKPROTECTOR_AUTO Kees Cook
2017-10-02 19:20   ` [kernel-hardening] " Kees Cook
2017-10-02 19:20   ` Kees Cook
2017-10-03 10:04 ` [kernel-hardening] [PATCH 0/3] " Mark Rutland
2017-10-03 10:04   ` Mark Rutland
2017-10-03 15:51   ` Kees Cook
2017-10-03 15:51     ` Kees Cook
2017-10-03 15:51     ` Kees Cook

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='CAGXu5jKqt=DgMVKS8znL05scbXdxRhgkaf7D5ipYA3Q=csLB5A@mail.gmail.com' \
    --to=keescook@chromium.org \
    --cc=akpm@linux-foundation.org \
    --cc=dalias@libc.org \
    --cc=davem@davemloft.net \
    --cc=greg@kroah.com \
    --cc=kernel-hardening@lists.openwall.com \
    --cc=labbott@redhat.com \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sh@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@kernel.org \
    --cc=mmarek@suse.com \
    --cc=npiggin@gmail.com \
    --cc=viro@zeniv.linux.org.uk \
    --cc=yamada.masahiro@socionext.com \
    --cc=ysato@users.sourceforge.jp \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.