Received: by 10.213.65.68 with SMTP id h4csp220425imn; Tue, 13 Mar 2018 01:57:09 -0700 (PDT) X-Google-Smtp-Source: AG47ELu2Ln7rUQh2mRLdnijbeWupTeFua9wmAwVGgFBhwc3fVmQWBVdaLcXinMbBafI34yzJa6lx X-Received: by 10.101.64.67 with SMTP id h3mr8815793pgp.200.1520931429462; Tue, 13 Mar 2018 01:57:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1520931429; cv=none; d=google.com; s=arc-20160816; b=yLh+AxvRrv6hi6+5lLfpySEYPIWispq0OyEvfyghYtY22Y0WifIpJOF0MWbEg829OW P9BwS2kj9HCFXtpK4+sz6yNaIEjnp6APkLFYysCWYHmzrFdpzUBW+e4WPc1MOxhAUWlK +0TkZqS3aRcIv/js1ZtYBmJamB2JZjbTjZ0KIMAhxLnhGbxFBa+jrfOTYLBkb3enlckK ZXIa2PsPniebAgR/czQVt3TYd2gNvFjNQAWDxF+VW6JOl7KzrKfIOt+MrErgQPdPqBcs N1ZSjoZaMouhrHNseQj7Ck7B3D+N0P+EWgzOaiONPHy4mJN8EdHchB0V8g85P026L+vI +1FQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=O77kUL2a+AMdQ7TlSitH2uSivsuI8670QlwCwdaFWts=; b=Io5VN2s4rqrR7IB3mS8sjIMlJdQjpOwEMHtAc+WrRiLYf90xZscZ4BFSw4j2N3H53O gsPgGDbS0wt2nhd1wd4cuOOrir2+qOTWr3H8e2bfIYTM5xNRe/J8S+mDtmKeoHCBb/4r 5grqejaU7AAJD8xm2H2AO4ayzqRk2vv4hcdH/6ZVC29iRl/E9O2ketRfk1SR00o9HGKB kWErRJw9xdXE2s3Bgo0+w27+G9Jpjcz8yyKVf2+OZP1p9wFLYko9rsKjyglmVBjsClym k5zZsjHY+Z6AzIf1kQ4pzQ4jVd64A8WGl5YY2oCVy//GtozILzylvrP4a6jOOZFcoVm9 Fu3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=ZbxYNDyx; 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 bb12-v6si7004367plb.164.2018.03.13.01.56.54; Tue, 13 Mar 2018 01:57: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=ZbxYNDyx; 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 S1752404AbeCMIz6 (ORCPT + 99 others); Tue, 13 Mar 2018 04:55:58 -0400 Received: from mail-io0-f195.google.com ([209.85.223.195]:45368 "EHLO mail-io0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752074AbeCMIzz (ORCPT ); Tue, 13 Mar 2018 04:55:55 -0400 Received: by mail-io0-f195.google.com with SMTP id m22so14787344iob.12; Tue, 13 Mar 2018 01:55:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=O77kUL2a+AMdQ7TlSitH2uSivsuI8670QlwCwdaFWts=; b=ZbxYNDyxi60X8phLTL0K51wyg5NxLmpen8qnwmnStbf69AcSgg1dP27uQjUmNRGQ2n H7UMgjSuwFw2lHxZDT8aPUOyi7Y2p8NdNxznd8ltNKADWaW0LlTqeoXuyFz/JfDmTA0l pk6mXt73QpqQbm2rarrn/rr+Q9pu72um4qbkc9Tds/aoIdnslGmXLeTIwI7XgmOhctDY CuWYOXVnRCLB4ujSWmHbHnjG2zJWcOiTzufWqBYfo8mHeSePyKMtXMb/371PdZXO5f93 ASNrhemrhJbOfL7pTR8Ja0q35sv7hp1m3og/u8OadXwWfIge+p1ApS+EwgHIlQZ5PlDi /hMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=O77kUL2a+AMdQ7TlSitH2uSivsuI8670QlwCwdaFWts=; b=MU389qeBvZ6zDSpV8UcuvHiutXX7EIiF6PN6U36hwDVAjGAQYylWgsgPzbc/h/mcHM LDWvmlmeiPalT0Fu3z6qCEOu2IwIsa1roc5/mbzEzAij9fJq0GlPoZrUdcyXVq67Y47C +efJD23qDnI2kzGQNxhHw8LZ151n5EKn3fhVEib9FHWzk8WMhr8aSAWM0fpp8OfUljg8 0omeEbRZ/PUBWxRQaJe13oDxrCZ/etnXeeYOzyUExkednxdLIz6wfXPZW0qsaVbmIRX7 FlTaP0qtZVm/vuLEa2XZ20zs7RVLHAY9CmFkSnVIgpALeZxEE1PVyAPN9pZ8E5ilT36c kOJw== X-Gm-Message-State: AElRT7GtgXhKUbC1qIvmz180WaX1FMA3OWlA56nmwD8iEKSs0RN2qoLQ hJQB1kkQtfvEtmkx7vp+E29QIT7/w7HBCJhk575AhA== X-Received: by 10.107.161.200 with SMTP id k191mr11368539ioe.270.1520931355013; Tue, 13 Mar 2018 01:55:55 -0700 (PDT) MIME-Version: 1.0 Received: by 10.107.187.195 with HTTP; Tue, 13 Mar 2018 01:55:53 -0700 (PDT) In-Reply-To: <1520820258-19225-1-git-send-email-chenhc@lemote.com> References: <1520820258-19225-1-git-send-email-chenhc@lemote.com> From: Huacai Chen Date: Tue, 13 Mar 2018 16:55:53 +0800 X-Google-Sender-Auth: CwX3XcGfYV0mAA9-6WR75NC1Lq4 Message-ID: Subject: Re: [PATCH V2] ZBOOT: fix stack protector in compressed boot phase To: Andrew Morton Cc: linux-mm@kvack.org, LKML , Ralf Baechle , James Hogan , Linux MIPS Mailing List , Russell King , linux-arm-kernel@lists.infradead.org, Yoshinori Sato , Rich Felker , linux-sh@vger.kernel.org, Huacai Chen , stable Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, Yoshinori, Rich and SuperH developers, I'm not familiar with SuperH assembly, but SuperH has the same bug obviously. Could you please fix that? Huacai On Mon, Mar 12, 2018 at 10:04 AM, Huacai Chen wrote: > 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 > -- > 2.7.0 >