From mboxrd@z Thu Jan 1 00:00:00 1970 From: Kees Cook Date: Mon, 02 Oct 2017 19:20:05 +0000 Subject: [PATCH 1/3] sh/boot: Add static stack-protector to pre-kernel Message-Id: <1506972007-80614-2-git-send-email-keescook@chromium.org> List-Id: References: <1506972007-80614-1-git-send-email-keescook@chromium.org> In-Reply-To: <1506972007-80614-1-git-send-email-keescook@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: Andrew Morton Cc: Kees Cook , Yoshinori Sato , Rich Felker , linux-sh@vger.kernel.org, Masahiro Yamada , Michal Marek , Ingo Molnar , "David S. Miller" , Nicholas Piggin , Al Viro , Laura Abbott , linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-hardening@lists.openwall.com The sh decompressor code triggers stack-protector code generation when using CONFIG_CC_STACKPROTECTOR_STRONG. As done for arm and mips, add a simple static stack-protector canary. As this wasn't protected before, the risk of using a weak canary is minimized. Once the kernel is actually up, a better canary is chosen. Cc: Yoshinori Sato Cc: Rich Felker Cc: linux-sh@vger.kernel.org Signed-off-by: Kees Cook --- arch/sh/boot/compressed/misc.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/arch/sh/boot/compressed/misc.c b/arch/sh/boot/compressed/misc.c index ae1dfdb0013b..f4bdc5d00c04 100644 --- a/arch/sh/boot/compressed/misc.c +++ b/arch/sh/boot/compressed/misc.c @@ -103,6 +103,18 @@ static void error(char *x) while(1); /* Halt */ } +unsigned long __stack_chk_guard; + +void __stack_chk_guard_setup(void) +{ + __stack_chk_guard = 0x000a0dff; +} + +void __stack_chk_fail(void) +{ + error("stack-protector: Kernel stack is corrupted\n"); +} + #ifdef CONFIG_SUPERH64 #define stackalign 8 #else @@ -117,6 +129,8 @@ void decompress_kernel(void) { unsigned long output_addr; + __stack_chk_guard_setup(); + #ifdef CONFIG_SUPERH64 output_addr = (CONFIG_MEMORY_START + 0x2000); #else -- 2.7.4 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751500AbdJBTUS (ORCPT ); Mon, 2 Oct 2017 15:20:18 -0400 Received: from mail-pf0-f173.google.com ([209.85.192.173]:57165 "EHLO mail-pf0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751102AbdJBTUP (ORCPT ); Mon, 2 Oct 2017 15:20:15 -0400 X-Google-Smtp-Source: AOwi7QDd4Y7lR4m1ULrhwMMZta70KnhtFGJ5sGtgXZB0NiFbaw4G0NkPQp3yaGjZvVhRfAlQe8yI7g== From: Kees Cook To: Andrew Morton Cc: Kees Cook , Yoshinori Sato , Rich Felker , linux-sh@vger.kernel.org, Masahiro Yamada , Michal Marek , Ingo Molnar , "David S. Miller" , Nicholas Piggin , Al Viro , Laura Abbott , linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-hardening@lists.openwall.com Subject: [PATCH 1/3] sh/boot: Add static stack-protector to pre-kernel Date: Mon, 2 Oct 2017 12:20:05 -0700 Message-Id: <1506972007-80614-2-git-send-email-keescook@chromium.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1506972007-80614-1-git-send-email-keescook@chromium.org> References: <1506972007-80614-1-git-send-email-keescook@chromium.org> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The sh decompressor code triggers stack-protector code generation when using CONFIG_CC_STACKPROTECTOR_STRONG. As done for arm and mips, add a simple static stack-protector canary. As this wasn't protected before, the risk of using a weak canary is minimized. Once the kernel is actually up, a better canary is chosen. Cc: Yoshinori Sato Cc: Rich Felker Cc: linux-sh@vger.kernel.org Signed-off-by: Kees Cook --- arch/sh/boot/compressed/misc.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/arch/sh/boot/compressed/misc.c b/arch/sh/boot/compressed/misc.c index ae1dfdb0013b..f4bdc5d00c04 100644 --- a/arch/sh/boot/compressed/misc.c +++ b/arch/sh/boot/compressed/misc.c @@ -103,6 +103,18 @@ static void error(char *x) while(1); /* Halt */ } +unsigned long __stack_chk_guard; + +void __stack_chk_guard_setup(void) +{ + __stack_chk_guard = 0x000a0dff; +} + +void __stack_chk_fail(void) +{ + error("stack-protector: Kernel stack is corrupted\n"); +} + #ifdef CONFIG_SUPERH64 #define stackalign 8 #else @@ -117,6 +129,8 @@ void decompress_kernel(void) { unsigned long output_addr; + __stack_chk_guard_setup(); + #ifdef CONFIG_SUPERH64 output_addr = (CONFIG_MEMORY_START + 0x2000); #else -- 2.7.4 From mboxrd@z Thu Jan 1 00:00:00 1970 From: Kees Cook Date: Mon, 2 Oct 2017 12:20:05 -0700 Message-Id: <1506972007-80614-2-git-send-email-keescook@chromium.org> In-Reply-To: <1506972007-80614-1-git-send-email-keescook@chromium.org> References: <1506972007-80614-1-git-send-email-keescook@chromium.org> Subject: [kernel-hardening] [PATCH 1/3] sh/boot: Add static stack-protector to pre-kernel To: Andrew Morton Cc: Kees Cook , Yoshinori Sato , Rich Felker , linux-sh@vger.kernel.org, Masahiro Yamada , Michal Marek , Ingo Molnar , "David S. Miller" , Nicholas Piggin , Al Viro , Laura Abbott , linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-hardening@lists.openwall.com List-ID: The sh decompressor code triggers stack-protector code generation when using CONFIG_CC_STACKPROTECTOR_STRONG. As done for arm and mips, add a simple static stack-protector canary. As this wasn't protected before, the risk of using a weak canary is minimized. Once the kernel is actually up, a better canary is chosen. Cc: Yoshinori Sato Cc: Rich Felker Cc: linux-sh@vger.kernel.org Signed-off-by: Kees Cook --- arch/sh/boot/compressed/misc.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/arch/sh/boot/compressed/misc.c b/arch/sh/boot/compressed/misc.c index ae1dfdb0013b..f4bdc5d00c04 100644 --- a/arch/sh/boot/compressed/misc.c +++ b/arch/sh/boot/compressed/misc.c @@ -103,6 +103,18 @@ static void error(char *x) while(1); /* Halt */ } +unsigned long __stack_chk_guard; + +void __stack_chk_guard_setup(void) +{ + __stack_chk_guard = 0x000a0dff; +} + +void __stack_chk_fail(void) +{ + error("stack-protector: Kernel stack is corrupted\n"); +} + #ifdef CONFIG_SUPERH64 #define stackalign 8 #else @@ -117,6 +129,8 @@ void decompress_kernel(void) { unsigned long output_addr; + __stack_chk_guard_setup(); + #ifdef CONFIG_SUPERH64 output_addr = (CONFIG_MEMORY_START + 0x2000); #else -- 2.7.4