Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3487310ybi; Mon, 29 Jul 2019 07:24:36 -0700 (PDT) X-Google-Smtp-Source: APXvYqzev1uIbTfgQNMCuZV576rBnwwj5M7jOZbxS5nD/zKJncQYIfrCokaWq/XJbThm1e2YBNMz X-Received: by 2002:a63:494d:: with SMTP id y13mr106343632pgk.109.1564410276247; Mon, 29 Jul 2019 07:24:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564410276; cv=none; d=google.com; s=arc-20160816; b=lzb919lUOU4lGmpcqPJyDxUu2emvijoX01EjdYGSCJtYnAegnp3VjzNvhctLsQ9K7X w18WjtLJCONk3OzlGdOtTSNcQc4V2WF7+CG/qrP27iYGoMDpIwoaz0KvlLCMcBezMBoG 4N7jEPN57QaCWNM7+Mk4uMGDMmPCaYdy9wWGN8+t6eZcbDkhHM8IU8w9+IMsaLRVwdVb /3p8qn3+geeNCmF7ow2LmJB+EmSJ6vAc6BfcZyicZkIp74VowU2GUJDwHIHm+lAtsjsw OOpoD0V2B7LOxN+/OJng0ewB9ot5KS2uqldLhqdJXI6gazhySXvermmJpZZ3jH/CMHty jr/A== 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; bh=F+GApdxZKWdj2b5XJ+C2+JndcnAz3HIE8GQf8lPcHos=; b=UUfZRr4zuhySCpet4kLpqQ89KOs/fPR6EVyaRBvRmd5rgs3sKKgdnD3dTA2Ma7LaGa Boa/VRZgLfLLaFbf6o9PPiWd2fbpeD59WxrTtUFlhQF2laU6tFHlhFKQWHaqsbA8TJQS iYwsNs0INEgynKKSpN8FW3q3w1HlxFS4ZPSnkpRssweAsjc8fLK7R9B4Nr4wcCvjNcni mgrUPRwMWslFHBRBXFNeUQa/FN+KH3rvi77ZHWyqSIEnJBIlLUz4SnsCaes1nvCx0ilx YwD+YhgKkuOoXxE691g/ZJEayP+o+fPm1ofwQgMy14ZUEIgEc00pW34n1kR7q+Spssim p5gA== ARC-Authentication-Results: i=1; mx.google.com; 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 l69si25955362plb.302.2019.07.29.07.24.20; Mon, 29 Jul 2019 07:24:36 -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; 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 S1727738AbfG2N71 (ORCPT + 99 others); Mon, 29 Jul 2019 09:59:27 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:33868 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726767AbfG2N71 (ORCPT ); Mon, 29 Jul 2019 09:59:27 -0400 Received: from DGGEMS403-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id AC2E8B87C8480C7DA8F3; Mon, 29 Jul 2019 21:43:42 +0800 (CST) Received: from [127.0.0.1] (10.177.96.203) by DGGEMS403-HUB.china.huawei.com (10.3.19.203) with Microsoft SMTP Server id 14.3.439.0; Mon, 29 Jul 2019 21:43:36 +0800 Subject: Re: [RFC PATCH 08/10] powerpc/fsl_booke/kaslr: clear the original kernel if randomized To: Christophe Leroy , , , , , , , , CC: , , , , , References: <20190717080621.40424-1-yanaijie@huawei.com> <20190717080621.40424-9-yanaijie@huawei.com> From: Jason Yan Message-ID: <704624a1-36b7-50d7-cf8d-2923b2a97367@huawei.com> Date: Mon, 29 Jul 2019 21:43:35 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.5.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-Originating-IP: [10.177.96.203] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2019/7/29 19:19, Christophe Leroy wrote: > > > Le 17/07/2019 à 10:06, 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 >> --- >>   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 90357f4bd313..00339c05879f 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; >> +        memset((void *)KERNELBASE, 0, kernel_sz); > > Why are we clearing ? Is that just to tidy up or is it of security > importance ? > If we leave it there, attackers can still find the kernel object very easy, it's still dangerous especially if without CONFIG_STRICT_KERNEL_RWX enabled. > If so, maybe memzero_explicit() should be used instead ? > OK >> +    } >> +} >> diff --git a/arch/powerpc/mm/mmu_decl.h b/arch/powerpc/mm/mmu_decl.h >> index 754ae1e69f92..9912ee598f9b 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 >>   extern void kaslr_early_init(void *dt_ptr, phys_addr_t size); >> +extern void kaslr_second_init(void); > > No new 'extern' please. > >>   #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; >>       } >> > > Christophe > > . >