From mboxrd@z Thu Jan 1 00:00:00 1970 From: Greg KH Date: Wed, 04 Oct 2017 15:13:12 +0000 Subject: Re: [kernel-hardening] Re: [PATCH 2/3] Makefile: Move stackprotector availability out of Kconfig Message-Id: <20171004151312.GA20938@kroah.com> List-Id: References: <1506972007-80614-1-git-send-email-keescook@chromium.org> <1506972007-80614-3-git-send-email-keescook@chromium.org> In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: Masahiro Yamada Cc: Kees Cook , Andrew Morton , Michal Marek , Ingo Molnar , Laura Abbott , Nicholas Piggin , Al Viro , Linux Kbuild mailing list , Yoshinori Sato , Rich Felker , "David S. Miller" , Linux Kernel Mailing List , linux-sh@vger.kernel.org, kernel-hardening@lists.openwall.com, Mark Rutland 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 : > > 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 > > Cc: Michal Marek > > Cc: Andrew Morton > > Cc: Ingo Molnar > > Cc: Laura Abbott > > Cc: Nicholas Piggin > > Cc: Al Viro > > Cc: linux-kbuild@vger.kernel.org > > Signed-off-by: Kees Cook > > --- > > 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. thanks, greg k-h From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752535AbdJDPNF (ORCPT ); Wed, 4 Oct 2017 11:13:05 -0400 Received: from out1-smtp.messagingengine.com ([66.111.4.25]:53947 "EHLO out1-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752473AbdJDPND (ORCPT ); Wed, 4 Oct 2017 11:13:03 -0400 X-ME-Sender: X-Sasl-enc: qM8mDzTkP5n9P4IUoTzDs9uE5EPHA1If8nv1HF4m7dvz 1507129982 Date: Wed, 4 Oct 2017 17:13:12 +0200 From: Greg KH To: Masahiro Yamada Cc: Kees Cook , Andrew Morton , Michal Marek , Ingo Molnar , Laura Abbott , Nicholas Piggin , Al Viro , Linux Kbuild mailing list , Yoshinori Sato , Rich Felker , "David S. Miller" , Linux Kernel Mailing List , linux-sh@vger.kernel.org, kernel-hardening@lists.openwall.com, Mark Rutland Subject: Re: [kernel-hardening] Re: [PATCH 2/3] Makefile: Move stackprotector availability out of Kconfig Message-ID: <20171004151312.GA20938@kroah.com> References: <1506972007-80614-1-git-send-email-keescook@chromium.org> <1506972007-80614-3-git-send-email-keescook@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.1 (2017-09-22) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 : > > 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 > > Cc: Michal Marek > > Cc: Andrew Morton > > Cc: Ingo Molnar > > Cc: Laura Abbott > > Cc: Nicholas Piggin > > Cc: Al Viro > > Cc: linux-kbuild@vger.kernel.org > > Signed-off-by: Kees Cook > > --- > > 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. thanks, greg k-h