From patchwork Mon Mar 5 06:18:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Huacai Chen X-Patchwork-Id: 10258167 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 8D9F260134 for ; Mon, 5 Mar 2018 06:17:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 77506286CC for ; Mon, 5 Mar 2018 06:17:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6B94628706; Mon, 5 Mar 2018 06:17:44 +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=unavailable 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 1812E286CC for ; Mon, 5 Mar 2018 06:17:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932522AbeCEGRa (ORCPT ); Mon, 5 Mar 2018 01:17:30 -0500 Received: from mail-pl0-f67.google.com ([209.85.160.67]:46383 "EHLO mail-pl0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751342AbeCEGR3 (ORCPT ); Mon, 5 Mar 2018 01:17:29 -0500 Received: by mail-pl0-f67.google.com with SMTP id y8-v6so9106055pll.13; Sun, 04 Mar 2018 22:17:29 -0800 (PST) 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=KGehzYkKKqzo+hnUP//aodr7AgGERwIf8u6K0mivxEE=; b=ItIUhJqLGsdpF7t7DOJ7/kFwGyS1RmqHP9G6eNNMfrUTGR8xQ9XRJYqubauFS+nER5 FyKI9DtRHaicZQmFQR7HuP81pHqf9o4fm7O66q8rew3xgcvS5PPERNljq0CtykwZbPwC 3ROMiFPvGD1ptNyIA8Hqhlc272gpWnb1S7dCwvx8ueScifsOguyrelsdrvrTsJLhUrrd 9d7Rxp147b53Jn0qpk35XcCliTfVMEbif6LGAyVN02NEth1lsv1UbnwE2ixcb6nGMmTe +OM9C+fp8RMMNOjzFuT96aVO3lQALL0wjQfTA0jyBbndvnSm9ISEs5YTqGTpyCYKykw7 fnpQ== 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=KGehzYkKKqzo+hnUP//aodr7AgGERwIf8u6K0mivxEE=; b=WoYQuFpDRmm6lwyqu8klt+Maj/VW2z9CFPNA3UlFVe4QTKDKyubregHtZYgcxYJxcA 8tq2gXuD+x2jlsxTgNfD1dmsJaq7J1P66Ji9nSG0OmArjqYRY/LhfVDKUbmZDvpKDGcx Iy5V3vRWdLFVlzZrC+K7zLCh9r+GRdGSHttBER9YF8RHl5apua+LnYANLjARLqSGAm9T DU6i6Q81JVAXq6pFNPYpyd9QX1Kn0+JMHNIdQXIPeCorbZir0hPYqWwJzsLG02APQ1aR 8ZPgBZVWJbnUhUIjSgs/ZJoYLyrhHFyUUrGDxLueLGhzKLxkGsUmxAJs8qiH+yxyFyVg JNlw== X-Gm-Message-State: APf1xPAwOYgeStp3Vn1eHbRrO0bUqqW4RSLmD163b4GKbeSyIoUSYbqg 5AvZRx+XRVpA4gY8U3CFuvY= X-Google-Smtp-Source: AG47ELsDGWRk7trRWpnT1w48RJ1vH90vwyIVx3UoINonP2qE2GSDxiEvEy5UYsqSw5qTvE2veunoDg== X-Received: by 2002:a17:902:5716:: with SMTP id k22-v6mr12321396pli.229.1520230648772; Sun, 04 Mar 2018 22:17:28 -0800 (PST) Received: from software.domain.org ([172.247.34.138]) by smtp.gmail.com with ESMTPSA id o82sm27211131pfj.163.2018.03.04.22.17.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 04 Mar 2018 22:17:27 -0800 (PST) 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] ZBOOT: fix stack protector in compressed boot phase Date: Mon, 5 Mar 2018 14:18:41 +0800 Message-Id: <1520230721-1839-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 at where we define it. 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). Cc: stable@vger.kernel.org Signed-off-by: Huacai Chen --- arch/arm/boot/compressed/misc.c | 9 +-------- arch/mips/boot/compressed/decompress.c | 9 +-------- arch/sh/boot/compressed/misc.c | 9 +-------- 3 files changed, 3 insertions(+), 24 deletions(-) diff --git a/arch/arm/boot/compressed/misc.c b/arch/arm/boot/compressed/misc.c index 16a8a80..43aca75 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; -} +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..0694b3f 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; -} +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..2c564c2 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; -} +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