From patchwork Mon Oct 2 19:20:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 9981169 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 84E036029B for ; Mon, 2 Oct 2017 19:20:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 782CE288D8 for ; Mon, 2 Oct 2017 19:20:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6CCE428929; Mon, 2 Oct 2017 19:20:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from mother.openwall.net (mother.openwall.net [195.42.179.200]) by mail.wl.linuxfoundation.org (Postfix) with SMTP id 7DD19288DC for ; Mon, 2 Oct 2017 19:20:29 +0000 (UTC) Received: (qmail 28625 invoked by uid 550); 2 Oct 2017 19:20:27 -0000 Mailing-List: contact kernel-hardening-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Delivered-To: mailing list kernel-hardening@lists.openwall.com Received: (qmail 28596 invoked from network); 2 Oct 2017 19:20:26 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=3rZ1n9U+Op1KV7UnYXsC4gcAcVwIaWxxd0B5Fv1rtfw=; b=dTi1GKnTPAUdoe9QvJ6T7672FWX65DqrOCWoeW+DbJfTYXXcEBXYbJaadRUEzuFEa0 wVtGze6mlYEnXVvqU9McNJlD28HzFOpBcr/YWYgvjk7yr36Uqbb+j6rXyGSzgFZvBTXm o+dzL+z7DZB+v5pDslhh+gs2Rb7FCLFK35hTE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=3rZ1n9U+Op1KV7UnYXsC4gcAcVwIaWxxd0B5Fv1rtfw=; b=fgyC9+w4F1UnsF9kHstGdsi/70EHE6JVyKfOSXvD1IRgVHCuDM2DLqJpAKZPNOb0eE Yso6ZtnigRSEVEAaN9bYLcYK2y3R9pUuKiS8PK15AI8LPrrXkTbC8fdOjaAxLm2QoaXZ ArDkSzyVI5AIwKAEj2wtA72LgnTEVpOnSTFVPp5uETeukffs4zEkUj7XrSzBtIygAbxv 6nSxZkPqBSMlHX3hV+x/ryA+HEUUl6pcqG3GrRGkAi5M43/9kgmAePDxrw7rSVbf3QL9 DLLxkqWHLD+0ZiA9zaMQ5/kA3ZFo1GuSKDSHIfLH/IZVk9dMnqmwN/NGuPefa98O7yS6 lQoA== X-Gm-Message-State: AMCzsaUGtphJf/wk3Q4yL6I0a75sEYJSNEQFbcsY/PxexiDc4nepIOJF xQHo88wzwldAR1cc98Iq9tnOyg== X-Google-Smtp-Source: AOwi7QDd4Y7lR4m1ULrhwMMZta70KnhtFGJ5sGtgXZB0NiFbaw4G0NkPQp3yaGjZvVhRfAlQe8yI7g== X-Received: by 10.98.233.10 with SMTP id j10mr7802653pfh.317.1506972014688; Mon, 02 Oct 2017 12:20:14 -0700 (PDT) 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 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> Subject: [kernel-hardening] [PATCH 1/3] sh/boot: Add static stack-protector to pre-kernel X-Virus-Scanned: ClamAV using ClamSMTP 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