Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp4777496ybi; Tue, 30 Jul 2019 08:00:56 -0700 (PDT) X-Google-Smtp-Source: APXvYqwz3BYLJ+Zz8Wc6GeJp+n9HQU0zSBP2XApnLadO56urmD+/vYBtgsKiM9Oz+Ux8yX2Cm2L/ X-Received: by 2002:a17:902:8203:: with SMTP id x3mr116554746pln.304.1564498856826; Tue, 30 Jul 2019 08:00:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564498856; cv=none; d=google.com; s=arc-20160816; b=wwytiEY1ebvtiUEf29tlDX7BiATJHoB74C3l6aEKPhY+gjOxyYxGYl51Yv55VuwzJ2 3mvpXGt1sssj1b9Qq4OCK0uGjQw5lf6QFPTbI4K0B8lu8kBNv9Dey13VjYUNhImQTg+x GwFhLvvocOGc3NPJ9ABL92b1keve6lBuhhS4pPYV0HT8BaLHZM5wgKlIsuY0gq1SlTmB AI2N+fgwmzEn4ZdYFxUrPti4ltp4pdMCM2dyyeUHWwT9Q9lRCwMNqRGLl3tpDmKqJB94 6PDGV0nDWupWWfniHn8m6P+FKdbPRYBA20kdo6c/h4t0Q3Cz1azCddoZiBsYtnYE0pol GiSA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=8Elcq5DvNm2PwJ3AEzgoFiT2sWRlD923ZYF11Klazfg=; b=sw81mXooRO/dGN7r+ERiYmGiW246hGJpjSPT8MzXhenHxSAf2162lexBXH3sPv7rHk 2PNitce3L93/X1ttBWb1vfGL8uXxDP4VSYQF9XpeciIIAwruekrgcJWHsv1dXhQE1yyU e009wWYKqPxYvwhUR+pwNo3sL9StaEQWWriK825/oH+MLinQ+mQ9f8Sei3lkiSfN6beo 7t/0DMmoWPzcMJMrm581Nbd+ZOX19Fy+rAGbB1yiFucxtH+41Br8y7u9GgIux9VGrKBZ AAFMsupUpbf+0b84os2LCHhOostH4LASEANj4huXc7qb4EGg6fAF8k7rwguPixTWRWwu LyNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=D9yvfTFg; 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 h4si30489922plt.30.2019.07.30.08.00.41; Tue, 30 Jul 2019 08:00:56 -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=pass header.i=@c-s.fr header.s=mail header.b=D9yvfTFg; 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 S1732067AbfG3Jrs (ORCPT + 99 others); Tue, 30 Jul 2019 05:47:48 -0400 Received: from pegase1.c-s.fr ([93.17.236.30]:62192 "EHLO pegase1.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731948AbfG3Jrk (ORCPT ); Tue, 30 Jul 2019 05:47:40 -0400 Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 45yWtx4J8rz9vBLV; Tue, 30 Jul 2019 11:47:37 +0200 (CEST) Authentication-Results: localhost; dkim=pass reason="1024-bit key; insecure key" header.d=c-s.fr header.i=@c-s.fr header.b=D9yvfTFg; dkim-adsp=pass; dkim-atps=neutral X-Virus-Scanned: Debian amavisd-new at c-s.fr Received: from pegase1.c-s.fr ([192.168.12.234]) by localhost (pegase1.c-s.fr [192.168.12.234]) (amavisd-new, port 10024) with ESMTP id 8iuiIZs2SoI6; Tue, 30 Jul 2019 11:47:37 +0200 (CEST) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase1.c-s.fr (Postfix) with ESMTP id 45yWtx37D2z9vBLN; Tue, 30 Jul 2019 11:47:37 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=c-s.fr; s=mail; t=1564480057; bh=8Elcq5DvNm2PwJ3AEzgoFiT2sWRlD923ZYF11Klazfg=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=D9yvfTFgfaMwYumReHctJgExqulPG0Dwg03sF4s8sufaJg+yAduTAZt8K7iWVJrl2 1RU9GUaDh63kKxC4/iTS8RBVoJChSQZQ1fBCeojBQmDX2cuhNVezgHvf7hh5oBBG3q axwEZCdn7ECTc4gNLkJxCGYcyi4XWH1xQQ5cH48g= Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id B83938B801; Tue, 30 Jul 2019 11:47:37 +0200 (CEST) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id qh6NCYNUGaNl; Tue, 30 Jul 2019 11:47:37 +0200 (CEST) Received: from [172.25.230.101] (po15451.idsi0.si.c-s.fr [172.25.230.101]) by messagerie.si.c-s.fr (Postfix) with ESMTP id EF2458B805; Tue, 30 Jul 2019 11:47:34 +0200 (CEST) Subject: Re: [PATCH v2 08/10] powerpc/fsl_booke/kaslr: clear the original kernel if randomized To: Jason Yan , mpe@ellerman.id.au, linuxppc-dev@lists.ozlabs.org, diana.craciun@nxp.com, benh@kernel.crashing.org, paulus@samba.org, npiggin@gmail.com, keescook@chromium.org, kernel-hardening@lists.openwall.com Cc: linux-kernel@vger.kernel.org, wangkefeng.wang@huawei.com, yebin10@huawei.com, thunder.leizhen@huawei.com, jingxiangfeng@huawei.com, fanchengyang@huawei.com, zhaohongjiang@huawei.com References: <20190730074225.39544-1-yanaijie@huawei.com> <20190730074225.39544-9-yanaijie@huawei.com> From: Christophe Leroy Message-ID: Date: Tue, 30 Jul 2019 11:47:34 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: <20190730074225.39544-9-yanaijie@huawei.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: fr Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Le 30/07/2019 à 09:42, Jason Yan a écrit : > The original kernel still exists in the memory, clear it now. > > Signed-off-by: Jason Yan > Cc: Diana Craciun > Cc: Michael Ellerman > Cc: Christophe Leroy > Cc: Benjamin Herrenschmidt > Cc: Paul Mackerras > Cc: Nicholas Piggin > Cc: Kees Cook Reviewed-by: Christophe Leroy Is kaslr_second_init() the best name ? What about kaslr_late_init() or kaslr_clear_early_kernel() or ... ? Christophe > --- > arch/powerpc/kernel/kaslr_booke.c | 11 +++++++++++ > arch/powerpc/mm/mmu_decl.h | 2 ++ > arch/powerpc/mm/nohash/fsl_booke.c | 1 + > 3 files changed, 14 insertions(+) > > diff --git a/arch/powerpc/kernel/kaslr_booke.c b/arch/powerpc/kernel/kaslr_booke.c > index 0bb02e45b928..f032ac119457 100644 > --- a/arch/powerpc/kernel/kaslr_booke.c > +++ b/arch/powerpc/kernel/kaslr_booke.c > @@ -412,3 +412,14 @@ notrace void __init kaslr_early_init(void *dt_ptr, phys_addr_t size) > > reloc_kernel_entry(dt_ptr, kimage_vaddr); > } > + > +void __init kaslr_second_init(void) > +{ > + /* If randomized, clear the original kernel */ > + if (kimage_vaddr != KERNELBASE) { > + unsigned long kernel_sz; > + > + kernel_sz = (unsigned long)_end - kimage_vaddr; > + memzero_explicit((void *)KERNELBASE, kernel_sz); > + } > +} > diff --git a/arch/powerpc/mm/mmu_decl.h b/arch/powerpc/mm/mmu_decl.h > index 9332772c8a66..550c8d742f88 100644 > --- a/arch/powerpc/mm/mmu_decl.h > +++ b/arch/powerpc/mm/mmu_decl.h > @@ -150,8 +150,10 @@ extern void loadcam_multi(int first_idx, int num, int tmp_idx); > > #ifdef CONFIG_RANDOMIZE_BASE > void kaslr_early_init(void *dt_ptr, phys_addr_t size); > +void kaslr_second_init(void); > #else > static inline void kaslr_early_init(void *dt_ptr, phys_addr_t size) {} > +static inline void kaslr_second_init(void) {} > #endif > > struct tlbcam { > diff --git a/arch/powerpc/mm/nohash/fsl_booke.c b/arch/powerpc/mm/nohash/fsl_booke.c > index 8d25a8dc965f..fa5a87f5c08e 100644 > --- a/arch/powerpc/mm/nohash/fsl_booke.c > +++ b/arch/powerpc/mm/nohash/fsl_booke.c > @@ -269,6 +269,7 @@ notrace void __init relocate_init(u64 dt_ptr, phys_addr_t start) > kernstart_addr = start; > if (is_second_reloc) { > virt_phys_offset = PAGE_OFFSET - memstart_addr; > + kaslr_second_init(); > return; > } > >