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: 9981165 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 CF2956029B for ; Mon, 2 Oct 2017 19:20:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C0BE928867 for ; Mon, 2 Oct 2017 19:20:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B525A288D8; Mon, 2 Oct 2017 19:20:19 +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 47AC228867 for ; Mon, 2 Oct 2017 19:20:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751336AbdJBTUQ (ORCPT ); Mon, 2 Oct 2017 15:20:16 -0400 Received: from mail-pf0-f179.google.com ([209.85.192.179]:50456 "EHLO mail-pf0-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751250AbdJBTUP (ORCPT ); Mon, 2 Oct 2017 15:20:15 -0400 Received: by mail-pf0-f179.google.com with SMTP id m63so3363058pfk.7 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=ORPSW/4QMqIKIrEC9gZ5Wf4YZSpIht6E4b0TCTQFcD8/rr3LJw0/qdB8KzTK0x8Tpc 6BFlDsnEjbFVY+dlUCCXVlSY0Mycz0DAGkJzyM9Nclb19sbGVOQek7A4t35Ge8sqFGkN SCCcGxT/99yp5xMi5lnrZECttQPH+9iIt3iQ5Mf1l6UIAsD76wc0NLQF7IGrFQ5LsaO9 wUykUB3KqKBy1awhTuaiTXE/jCnKRTvPyvjOPK6B54vCFS5vGZZsMhhqFOMpOH17Dpa8 o4wZCrDd3shMyGTOFIDMdRufLe0RY0zslfod0bmUTVOpBlusDPcvPdRoRAnXdx7SkLhu voyw== X-Gm-Message-State: AMCzsaURM5ea5S2jVJ9qLkFKzjiXuSOTPwS4/BBkmUxRoIom2Hoxp22u QdeK6ao03T7VAL/9hsn1NCfMew== 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-sh-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sh@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