From patchwork Wed Mar 28 08:48:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Huacai Chen X-Patchwork-Id: 10312539 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 D152B605B4 for ; Wed, 28 Mar 2018 08:47:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C03F329E0A for ; Wed, 28 Mar 2018 08:47:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B492D29E6A; Wed, 28 Mar 2018 08:47:10 +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 5CA0329E4E for ; Wed, 28 Mar 2018 08:47:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752568AbeC1Iqx (ORCPT ); Wed, 28 Mar 2018 04:46:53 -0400 Received: from mail-pg0-f65.google.com ([74.125.83.65]:33174 "EHLO mail-pg0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751166AbeC1Iqu (ORCPT ); Wed, 28 Mar 2018 04:46:50 -0400 Received: by mail-pg0-f65.google.com with SMTP id i194so696791pgd.0; Wed, 28 Mar 2018 01:46:50 -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=8GZGcSurecrsTVxb6yqZqI1ILcYj7HVhPQ9TN4Nh43A=; b=SXqdOjdvtctW2nug/LNl6b8sLXH4HC+0QjP1KzTIiotDtE7fLnq0vuv1b2BevqOyQw HD49bBqj7ofE+iuLSSNCI2RZuSJLQ7hcumdQnFxX37qAHWiF37Wvt63m2kqvTujNidkl oC5S5GlH3kB4Se9d5b3ygkgvaUfdpXlPy8kxbermUMGrOc1hH19mH+5nu3pgl/N1CS/0 cL4rzwL9XFjy/bxU/UnSr21rhBEMK3AujX9vkj4CUI41QlBaXnMv+VfFqU6znVQp8Ikr 9TMq+G38ZJBxwqfGSyQ+7XzbSxTxqkcZy7WdA0CDU33fPxU662z3o466F5GgFiQ8b9Ce 2zig== 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=8GZGcSurecrsTVxb6yqZqI1ILcYj7HVhPQ9TN4Nh43A=; b=TBylv0M8/85sX1E4lt04X7VqUcj3oy1Q81kbXHAZDQzVTdnU2XMSO8ueJ3aEmcBbpm /ZgcwFLUOdXOBBW2YZ4CJaWUE6+SsUguO1Z7CR3lEhlIQE/bRqCAyMw+Pu5kxfKg87ZJ 076V2sOy5XPGsNnff9gku1SrIBEkD3TpuAXkWyJbUIyCtlY/GjModWwVP5a4D+d9Zbma e2UD9oTPFwzPTtVewatHctUdyAqbbR+BmgLXBz+mZvXnHCUSrlWLjRrP1TO4bxgnEb9F BNA9VFImqy8HUdBlfiyIyva/88Q50WdiXxhep5El9QTPRwka8qPgA0WutqeV26ipg2o+ sGlQ== X-Gm-Message-State: AElRT7EJ/xMOrx3ssO8N4LRrXX0VFHo3rxhasrizCTXXhwkOUn8jhgBJ d0Tiu9rDlnBtcyOTGQxFDks= X-Google-Smtp-Source: AIpwx48SvZNB4jyj+PD3m9/aAdKaemhU/kkK1WiQNLrkyJdYSx0e1kXisr32kYr0r6hWEgKTzY/qag== X-Received: by 10.98.237.12 with SMTP id u12mr2246898pfh.72.1522226809854; Wed, 28 Mar 2018 01:46:49 -0700 (PDT) Received: from software.domain.org ([172.247.34.138]) by smtp.gmail.com with ESMTPSA id z67sm5907759pgb.69.2018.03.28.01.46.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 28 Mar 2018 01:46:49 -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 Resend] ZBOOT: fix stack protector in compressed boot phase Date: Wed, 28 Mar 2018 16:48:53 +0800 Message-Id: <1522226933-29317-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 Acked-by: James Hogan Acked-by: Kees Cook Acked-by: Rich Felker --- 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..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