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: 9981181 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 8F39E6029B for ; Mon, 2 Oct 2017 19:21:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8176728867 for ; Mon, 2 Oct 2017 19:21:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 76441288DC; Mon, 2 Oct 2017 19:21:08 +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=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0828228867 for ; Mon, 2 Oct 2017 19:21:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751345AbdJBTUQ (ORCPT ); Mon, 2 Oct 2017 15:20:16 -0400 Received: from mail-pf0-f169.google.com ([209.85.192.169]:52007 "EHLO mail-pf0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751255AbdJBTUP (ORCPT ); Mon, 2 Oct 2017 15:20:15 -0400 Received: by mail-pf0-f169.google.com with SMTP id n14so1468808pfh.8 for ; Mon, 02 Oct 2017 12:20:14 -0700 (PDT) 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=EHwAMRO+s6f9GK1HIvOi/rMg0hxXfj/rksWLLvNRuQFeVRCbceOegavUVtR41e21je NagojTwNAvEEd3bLrTjk9j+DJ78NbuarHg4rZgdXdi4yLFySGw4xR3L+sZJYdOAdCy2x i2ToWnBSn+OQkOP44Ef6hVCwdghghYsJm+rpabfGRLO7owM6AeqlXJNATNY430g3YjnQ fxdXByRcCJNY2lTxpo0XP1SIt2+Vg3vrAYbIXG9q0teJawMdq2Q6o6zPV91ywbdjMYMK ASzk0/eIILlyeKpU6lhDkaRdFMRjb/87cdOc/zasSqRCjji3H3OJ2gNWWvLKTRMEOl9x 5jww== X-Gm-Message-State: AMCzsaUUOgtlxjwHkhRy4Zy13Y4ea/mGtDTRf9rs1/km931b4o1fvp7l BSoLm3zkfWgv6DUGpPi2OfVAow== 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) Received: from www.outflux.net (173-164-112-133-Oregon.hfc.comcastbusiness.net. [173.164.112.133]) by smtp.gmail.com with ESMTPSA id r11sm18571916pfg.180.2017.10.02.12.20.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 02 Oct 2017 12:20:12 -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 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-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org 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