Received: by 10.213.65.68 with SMTP id h4csp214316imn; Wed, 28 Mar 2018 02:04:09 -0700 (PDT) X-Google-Smtp-Source: AIpwx48vmL7MI0qZj5PuRZZkGlAQb0yUyXxOljws/RV0bKrrpJ6WobMc0SBlDnI+aHG9zGgB1RQo X-Received: by 2002:a17:902:594c:: with SMTP id e12-v6mr2845120plj.53.1522227849642; Wed, 28 Mar 2018 02:04:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522227849; cv=none; d=google.com; s=arc-20160816; b=sRdUwC3XCKfKLF10ZZMDqisYmDXTuazxpo4tCrQhd9WG7kuLIMHVBAgP++8Ik9JImy XNGaZ6NWUMfx6/vckvZYbYBGJPE33uZrmZbdOdwxhjCtVtFjw0CZmgy7pkNu4ouQpzdR FZcS2vzr3vJATzwlzNyc5QxhZY3Pbm+zQNRsMNTMLqP+rMCuVimIgqPmGEkGJ5KCxyVy yAMzb5F2B1xLYpCbikcnPxrt460P4ZNwCO4lxBSeRj8AZaL4tL/FPkwICCpJjgZfjD4V z77C8pogTC8+Sw7U2EXDHMHRWRUjupLB9Ot64FyLDmJ7wYYRKPp+TYO/bqwl3NFXaVFb Mqzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=8GZGcSurecrsTVxb6yqZqI1ILcYj7HVhPQ9TN4Nh43A=; b=yDj2WUOc+UYP4+HamgafmCqA/cmZxNCzQlwS5LmoIQN9VEZI0VzibPRj9NtLfbdVH8 9wt2ObHjdWnbbRAScmFZZq0tKc83XNCpcbqnmH8N2r2orIox2kzXoxo//O14dAYRPAHP 6ZAQSa5z9lOv1Mje/sxyUfFilXJuzNDgWRDpkYNAcv3nE0iwfoOt8yiBgNy4y90DI8QC VWqg7ryqDgYbqRtqH8CuPz0CdPIGj6nFi2b5HYwOD5bQGWn8w+fGqSLVG9dMUzHJ0Y2k udlpFH3vcOlN/1Fjs2DPqJPmFCwMtdFZK3Nl/FcsF11Q9oGl42zvI/MqKfcWT7xpLZ1p rkAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=SXqdOjdv; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a60-v6si3121179pli.13.2018.03.28.02.03.55; Wed, 28 Mar 2018 02:04:09 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=SXqdOjdv; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752758AbeC1Iqx (ORCPT + 99 others); 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-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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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/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 -- 2.7.0