From patchwork Wed Mar 28 08:38:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Huacai Chen X-Patchwork-Id: 10312515 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 35C6660325 for ; Wed, 28 Mar 2018 08:36:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 223BD2866D for ; Wed, 28 Mar 2018 08:36:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1679A29CAF; Wed, 28 Mar 2018 08:36:12 +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.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SBL, 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 D441F2866D for ; Wed, 28 Mar 2018 08:36:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751241AbeC1IgK (ORCPT ); Wed, 28 Mar 2018 04:36:10 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:43471 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751072AbeC1IgH (ORCPT ); Wed, 28 Mar 2018 04:36:07 -0400 Received: by mail-pf0-f196.google.com with SMTP id j2so706431pff.10; Wed, 28 Mar 2018 01:36:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id; bh=AAS2cm9vITDO+Vm+0YhMN+xBJrUz645LdenuzRantAE=; b=KkRGUcpLbfecjB/Xi2Y0mI7ZG+8cOkUD6w9uL3hdqTSdkVoD160dKGZ2yek0x7uk9K NVuvLtFSeFl13UWCUQyTm56XiqSFM5HFmLwRSmWpcrz0jbN6D5ii7/1QkD+1huXmlkzf fqiL89kICBVwJdxNpTzkpYcnuSSmZmTgqRE1oJ0jkPebGRE82ZygaEojsMAd7yFvGckx mRVcnWyJSWaI93qL1EOkQY2OhDWYd+PSktGavQ3cOkU+hzilS1dtMxeD8srgdsZ120CR oiw9nKgU2LtUg+myK7HJ7YXDeQuVD+epkxYCrbs0VlF2ibrKO4g1ktIFt5wofUODqDPm KnLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id; bh=AAS2cm9vITDO+Vm+0YhMN+xBJrUz645LdenuzRantAE=; b=YAM50O/QIjkJzJ6Hn6+cCe9rzLkDPazG1DltF891UIk9S9SJRNFo/VhKmPB5jnnihi lxypEeVytwjSaNBKn7qn2/0moJGjYzEoyP0mK7YBrbn5me+YHJOwrBHacJ1gU66hjafl oYfKz1hQ3bZkFTOuDr63i37vigYLNuLKRuidl+L1KjmN6Oc3Jc4X7Xs7LGHT8nfcgCDD Rr+Ih4kLdE7vqjf+7D30zHMRJi1qPcOlq9Mh0WiZUwRyj7tJIQ6mPy0J3Re8S4Fp5npb 5HI5nF8SddfIMI65LIi82M/ic5PuXeswGVkkgJYc9o6pLrqckzW7SHvm8yYhL36HEiig 87OQ== X-Gm-Message-State: AElRT7FLhhdKkbyVMA9cbIniHltoNCIAoHlcB7MlyDaoeRCAflqVsI/L AHuCK/7rqRopWLUQHqYb6d8= X-Google-Smtp-Source: AIpwx4/1c+jq9VXM7GuSYMhy2pNr40eOF5nVGOrQg3UaQV8FtTzExX96uV2AFc09k3lLTivlum7CDA== X-Received: by 10.99.115.84 with SMTP id d20mr1912235pgn.362.1522226167145; Wed, 28 Mar 2018 01:36:07 -0700 (PDT) Received: from software.domain.org ([172.247.34.138]) by smtp.gmail.com with ESMTPSA id u9sm5530949pgb.27.2018.03.28.01.36.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 28 Mar 2018 01:36:05 -0700 (PDT) From: Huacai Chen To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Ralf Baechle , James Hogan , linux-mips@linux-mips.org, Russell King , linux-arm-kernel@lists.infradead.org, Yoshinori Sato , Rich Felker , linux-sh@vger.kernel.org, Huacai Chen , stable@vger.kernel.org Subject: [PATCH V4] ZBOOT: fix stack protector in compressed boot phase Date: Wed, 28 Mar 2018 16:38:16 +0800 Message-Id: <1522226296-3091-1-git-send-email-chenhc@lemote.com> X-Mailer: git-send-email 2.7.0 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 Call __stack_chk_guard_setup() in decompress_kernel() is too late that stack checking always fails for decompress_kernel() itself. So remove __stack_chk_guard_setup() and initialize __stack_chk_guard before we call decompress_kernel(). Original code comes from ARM but also used for MIPS and SH, so fix them together. If without this fix, compressed booting of these archs will fail because stack checking is enabled by default (>=4.16). V1 -> V2: Fix build on ARM. V2 -> V3: Fix build on SuperH. V3 -> V4: Initialize __stack_chk_guard in C code as a constant. Cc: stable@vger.kernel.org Signed-off-by: Huacai Chen --- arch/arm/boot/compressed/head.S | 4 ++++ arch/arm/boot/compressed/misc.c | 7 ------- arch/mips/boot/compressed/decompress.c | 7 ------- arch/mips/boot/compressed/head.S | 4 ++++ arch/sh/boot/compressed/head_32.S | 8 ++++++++ arch/sh/boot/compressed/head_64.S | 4 ++++ arch/sh/boot/compressed/misc.c | 7 ------- 7 files changed, 20 insertions(+), 21 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-sh" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/arch/arm/boot/compressed/misc.c b/arch/arm/boot/compressed/misc.c index 16a8a80..e8fe51f 100644 --- a/arch/arm/boot/compressed/misc.c +++ b/arch/arm/boot/compressed/misc.c @@ -128,12 +128,7 @@ asmlinkage void __div0(void) error("Attempting division by 0!"); } -unsigned long __stack_chk_guard; - -void __stack_chk_guard_setup(void) -{ - __stack_chk_guard = 0x000a0dff; -} +const unsigned long __stack_chk_guard = 0x000a0dff; void __stack_chk_fail(void) { @@ -150,8 +145,6 @@ decompress_kernel(unsigned long output_start, unsigned long free_mem_ptr_p, { int ret; - __stack_chk_guard_setup(); - output_data = (unsigned char *)output_start; free_mem_ptr = free_mem_ptr_p; free_mem_end_ptr = free_mem_ptr_end_p; diff --git a/arch/mips/boot/compressed/decompress.c b/arch/mips/boot/compressed/decompress.c index fdf99e9..81df904 100644 --- a/arch/mips/boot/compressed/decompress.c +++ b/arch/mips/boot/compressed/decompress.c @@ -76,12 +76,7 @@ void error(char *x) #include "../../../../lib/decompress_unxz.c" #endif -unsigned long __stack_chk_guard; - -void __stack_chk_guard_setup(void) -{ - __stack_chk_guard = 0x000a0dff; -} +const unsigned long __stack_chk_guard = 0x000a0dff; void __stack_chk_fail(void) { @@ -92,8 +87,6 @@ void decompress_kernel(unsigned long boot_heap_start) { unsigned long zimage_start, zimage_size; - __stack_chk_guard_setup(); - zimage_start = (unsigned long)(&__image_begin); zimage_size = (unsigned long)(&__image_end) - (unsigned long)(&__image_begin); diff --git a/arch/sh/boot/compressed/misc.c b/arch/sh/boot/compressed/misc.c index 627ce8e..c15cac9 100644 --- a/arch/sh/boot/compressed/misc.c +++ b/arch/sh/boot/compressed/misc.c @@ -104,12 +104,7 @@ static void error(char *x) while(1); /* Halt */ } -unsigned long __stack_chk_guard; - -void __stack_chk_guard_setup(void) -{ - __stack_chk_guard = 0x000a0dff; -} +const unsigned long __stack_chk_guard = 0x000a0dff; void __stack_chk_fail(void) { @@ -130,8 +125,6 @@ void decompress_kernel(void) { unsigned long output_addr; - __stack_chk_guard_setup(); - #ifdef CONFIG_SUPERH64 output_addr = (CONFIG_MEMORY_START + 0x2000); #else