From patchwork Mon Mar 12 02:04:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Huacai Chen X-Patchwork-Id: 10274999 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 1099660233 for ; Mon, 12 Mar 2018 02:02:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 00CAF28D28 for ; Mon, 12 Mar 2018 02:02:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E971E28D2D; Mon, 12 Mar 2018 02:02:52 +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 5542A28D28 for ; Mon, 12 Mar 2018 02:02:52 +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=wZrGKEQgWr92c7Zg8NM4hpSMgZHnOqVJmbzLFK+uXmw=; b=PvE +XqzUm+xqNnYY4m6ePl3PYKFW/8K4nVJraD/yt8Rux+yxzDGgFJ9pwQQUXvrHmY3NnXsek/0kY4Ps 8iLWCrkZvU6tcHTSO1ihFOhijHoNmNQCU7/k32JuP5V7rW9cy0iTIOaRT40E1fQnSG/8lmLwTlETe FeuiZZUtxaLXSFLp4AwetHk0ELYxqbzxYIzxZ2Wz+9/wrKj2hN1DfdOQ70fP3UOxP1YeI8Btazd40 WuYpQFUT7zYVYVreDx5YRPBcSE/+qyZDYZoMv/yl/nxvoTixxpaYB2b+xT7xo262EZFRV+Fsy8HsV jjier5yQdFr3uXQQ7Djch3sXAR8DlZg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1evCnY-0006VT-1e; Mon, 12 Mar 2018 02:02:48 +0000 Received: from mail-pl0-x244.google.com ([2607:f8b0:400e:c01::244]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1evCnT-0006Tn-3b for linux-arm-kernel@lists.infradead.org; Mon, 12 Mar 2018 02:02:45 +0000 Received: by mail-pl0-x244.google.com with SMTP id c11-v6so8498151plo.0 for ; Sun, 11 Mar 2018 19:02:31 -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=MFIDtUr/Kn1dn/r/qzotSMa5WuYQqNv14xsckZ/fSJ8=; b=uJE7VJRDj35zDBYhigUMNVJ4sDHPjF2iEoSN8V1XkkVbh+2qe83cC/JX/ymNIeLT7L 8GtmPvZBsUojJ+/Ex3PTvkOuv06tQIGI8Pt7tdZx4BYFeXcybPy7RERl92BiPVEDvGj3 zBh5kRcXbD06EuU7Na+dc0x0/0ztgSRMkaCWmNKrt7CGyPwRXPkNvxxsJkihHnLH5TgR Tp5qtuGW1P1Haq+Gb2tkwxWBxCqd1ggpfXyf/Mls4xW5aRhoshL2isp0wyUhXX0iW7YL TERp9mYfi7ZxsmC/UE1HBWl/MitArUAY5W55wKwYaWhgS0nXgH4/Dfyq/KSulwgwKc60 iXow== 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=MFIDtUr/Kn1dn/r/qzotSMa5WuYQqNv14xsckZ/fSJ8=; b=GJQVB4m7A4Qt0g+FUGWTt8m0AaJfEdzCOOq740Fha/12OKUPiiKvRX6voSbNnrISxZ oKzubP3TaLq7/FZClfdVj2tVpmJuufqbxeRbFhAwZCTgajMn/CC5tYKmANZlOAYBF7+Y CN0VMd+2dxniG5jAEG+prOPsBN7nclStD/XRp5vzfTkVg16qxIWZEcbO3QUywlypHpk6 dV0oXQ/RtstpIN9cI1pK9MGdvfyjx0gbJGmgWtwTyoxXidQJUGk5wz2YBNRhL59Wh/2P Pe9a3YT11d1ly261MR8pYAEDamERlFvpWp4PO4GMR+zjjar+cahknXU5prh5cI6iz1ML cXkw== X-Gm-Message-State: AElRT7EUi53VZPl4eBO9UGmhdLKkR6A1/aYdYuUBjHHoiiQ5Rnm+KYZw HptjE7Ma2kUsX37MCI3kQEE= X-Google-Smtp-Source: AG47ELuWcL3AW8nEXKYfgRZ6AphkpwoaHIu92OifbQ1iyp5a2HLfwsTHrjmtmHehnM8FaS0WsbUOfA== X-Received: by 2002:a17:902:6d0f:: with SMTP id s15-v6mr6630074plk.375.1520820151523; Sun, 11 Mar 2018 19:02:31 -0700 (PDT) Received: from software.domain.org ([172.247.34.138]) by smtp.gmail.com with ESMTPSA id z4sm10684911pgb.4.2018.03.11.19.02.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 11 Mar 2018 19:02:30 -0700 (PDT) From: Huacai Chen To: Andrew Morton Subject: [PATCH V2] ZBOOT: fix stack protector in compressed boot phase Date: Mon, 12 Mar 2018 10:04:17 +0800 Message-Id: <1520820258-19225-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-20180311_190243_309868_3B300762 X-CRM114-Status: GOOD ( 11.34 ) 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). V2: Fix build on ARM. 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 | 4 ++++ arch/sh/boot/compressed/head_64.S | 4 ++++ arch/sh/boot/compressed/misc.c | 7 ------- 7 files changed, 16 insertions(+), 21 deletions(-) diff --git a/arch/arm/boot/compressed/head.S b/arch/arm/boot/compressed/head.S index 45c8823..bae1fc6 100644 --- a/arch/arm/boot/compressed/head.S +++ b/arch/arm/boot/compressed/head.S @@ -547,6 +547,10 @@ not_relocated: mov r0, #0 bic r4, r4, #1 blne cache_on + ldr r0, =__stack_chk_guard + ldr r1, =0x000a0dff + str r1, [r0] + /* * The C runtime environment should now be setup sufficiently. * Set up some pointers, and start decompressing. diff --git a/arch/arm/boot/compressed/misc.c b/arch/arm/boot/compressed/misc.c index 16a8a80..e518ef5 100644 --- a/arch/arm/boot/compressed/misc.c +++ b/arch/arm/boot/compressed/misc.c @@ -130,11 +130,6 @@ asmlinkage void __div0(void) 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"); @@ -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..5ba431c 100644 --- a/arch/mips/boot/compressed/decompress.c +++ b/arch/mips/boot/compressed/decompress.c @@ -78,11 +78,6 @@ void error(char *x) 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"); @@ -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/mips/boot/compressed/head.S b/arch/mips/boot/compressed/head.S index 409cb48..00d0ee0 100644 --- a/arch/mips/boot/compressed/head.S +++ b/arch/mips/boot/compressed/head.S @@ -32,6 +32,10 @@ start: bne a2, a0, 1b addiu a0, a0, 4 + PTR_LA a0, __stack_chk_guard + PTR_LI a1, 0x000a0dff + sw a1, 0(a0) + PTR_LA a0, (.heap) /* heap address */ PTR_LA sp, (.stack + 8192) /* stack address */ diff --git a/arch/sh/boot/compressed/head_32.S b/arch/sh/boot/compressed/head_32.S index 7bb1681..a3fdb05 100644 --- a/arch/sh/boot/compressed/head_32.S +++ b/arch/sh/boot/compressed/head_32.S @@ -76,6 +76,10 @@ l1: mov.l init_stack_addr, r0 mov.l @r0, r15 + mov.l __stack_chk_guard, r0 + mov #0x000a0dff, r1 + mov.l r1, @r0 + /* Decompress the kernel */ mov.l decompress_kernel_addr, r0 jsr @r0 diff --git a/arch/sh/boot/compressed/head_64.S b/arch/sh/boot/compressed/head_64.S index 9993113..8b4d540 100644 --- a/arch/sh/boot/compressed/head_64.S +++ b/arch/sh/boot/compressed/head_64.S @@ -132,6 +132,10 @@ startup: addi r22, 4, r22 bne r22, r23, tr1 + movi datalabel __stack_chk_guard, r0 + movi 0x000a0dff, r1 + st.l r0, 0, r1 + /* * Decompress the kernel. */ diff --git a/arch/sh/boot/compressed/misc.c b/arch/sh/boot/compressed/misc.c index 627ce8e..fe4c079 100644 --- a/arch/sh/boot/compressed/misc.c +++ b/arch/sh/boot/compressed/misc.c @@ -106,11 +106,6 @@ static void error(char *x) 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"); @@ -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