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: 10312519 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 15A3760353 for ; Wed, 28 Mar 2018 08:36:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 028D52866D for ; Wed, 28 Mar 2018 08:36:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EAEA229CAF; Wed, 28 Mar 2018 08:36:32 +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=-1.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_SBL autolearn=no version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 69B0D2866D for ; Wed, 28 Mar 2018 08:36:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=msDCOyODpAWRIySW9aTZR36IW8OLneC7hefee9SNmBk=; b=of2 3ACOS5nl63ES1VhHSnbzTohis8NXBgLz/Hi1LpXY3U0WEnkCB/eZWD+y/rZFPsSO1+gt3/YFD0r7+ EB0dubkjONWJ7ZqJ03pK2MrUdbCt+evye81ByJNUb+rsLhYb3slkFj3q0x6Yss88OGOUhadNRVV2O G8DL6C+cBkM6rDPqsRX9eY1ObWd5SVaGnn6nRRjQRtuIft6BY9UJ0bbJDU4k9Cs7/6sSi9QsunJU0 AyIx4Qo+zjP2r1RYfMiA+wqHMBTXQzPlGyZetkithA6tjKipB2yDXvSF/5kEoP9uGthqlzQ9FCBMI gmrSjScXLHHg0BTb7S3gDOgKy96sfHg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1f16ZB-0007JQ-TH; Wed, 28 Mar 2018 08:36:21 +0000 Received: from mail-pf0-x241.google.com ([2607:f8b0:400e:c00::241]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1f16Z8-0007Gk-ED for linux-arm-kernel@lists.infradead.org; Wed, 28 Mar 2018 08:36:20 +0000 Received: by mail-pf0-x241.google.com with SMTP id q9so718055pff.1 for ; 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=UJ+5CagZsZuXGNGv+djPvSoO0J3Hjk8ZAA6G+W8AtvhfM/nm9+BEIpNXFQRpl0MPaQ ZJkTcc8ROKmZ7VzW3JfsJt1Z5kxTNPFtYt5cJnZHucGVZgtD97yLanVnluCMW5Y+iYEZ GniI+Pv1BfFVkJB8+glZjM6LU1rZrLzU4Z+snKjuQf0j9rSns9FhgOx5Vsjxy4WBCejK tLi259IK/CZFQVe3+Fxi23VgG1lsDZoWrphqaXF4OGD6k6n0GciVoDKSTya2zZt/ziIT 9n3UcSDVZAfrV6/T3WuUFXbFqiZIuwK49vXepXNA1eOS3LTIoOqZo0+HkT8ivEYwEs49 7X1A== X-Gm-Message-State: AElRT7HIZZ0Vq2w0jAA3uvfkGm/+lVpVM3l6khnrkpPPXax59LzlthvB OEbmUUfH+j4aXdFs5p+1bMnW3Q== 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 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180328_013618_479279_7810012D X-CRM114-Status: GOOD ( 11.60 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-mips@linux-mips.org, Rich Felker , Russell King , Yoshinori Sato , linux-sh@vger.kernel.org, linux-kernel@vger.kernel.org, Ralf Baechle , linux-mm@kvack.org, stable@vger.kernel.org, Huacai Chen , James Hogan , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.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(-) 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