Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp82732ybl; Fri, 9 Aug 2019 02:53:29 -0700 (PDT) X-Google-Smtp-Source: APXvYqyiXft7vEHk7Cu73/J16BdE3NIxiRdmKXOYIfqks87rc6Fkpuwi3f9UZo67mR3QXc0EhHxH X-Received: by 2002:a17:90a:e397:: with SMTP id b23mr8418089pjz.140.1565344409673; Fri, 09 Aug 2019 02:53:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565344409; cv=none; d=google.com; s=arc-20160816; b=omFjiens/28K9fQrye7ZDX5LaaICf3a1kyOUzPgbeAdB9DC5sVziaEygagfk/USqZf r6BPooXLsCkk6302TOhpE0FWJv/FL/JhBZ9a1wkTnTD/B2NM01R6nNLhGU2y4FWOSj8O vKu2NqXHtOaCNqGIcq44EHMShN8UXx8yBL/w88r44qabRQwdpqdN+LJtFJE+3Yu3haqY 2z5tfMr+D5ie99AWg4Bbnak6nMJ9Tz0r33nAWLH9Icl8SlCMh8QZf77H0yMmorDI7Irp 2iCwf20/PHkPSVx1tw6Rpf3LJpc7vUUZ+DLzQzjxskwkt2kGInkgtrfKmLL5KRP6ApZg DMsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=RGtUWCmN+RYLb5UK3vLcMs7kfAbUcStIuuzBrByha34=; b=y4UReFtlYEA8vcre/g9Byvlq4qhLG9Sv5Nes+rabqRwN/erkgGXlJVvcYbgEARSniV jSr3cgXZezaH9ZIq1R1GMVAtskvQr/UFl3Z6uJfTLK8X7Yk1VhKPY0UfL5udYiv/VH3z EVG3RehXNqVVHRK22xR/Txjqf17ADbOI2/L5BDvBtsYrEc1aDNLbxP+GLsRDnOin6NXy EJYvAaW3igpVTQiRZQcxQZFCug6hQ3VUqu0eQIv2xv8fO51fiKN490vzlnqhPSfBhOwL mAcWVQsbjH4cuLJQ36mNfotVQocw0zTRQqjgrMZyJ4yPG+TsT1EHxg4kyX6PCf3Fncsn jLnQ== 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 o20si19822318pgc.503.2019.08.09.02.53.14; Fri, 09 Aug 2019 02:53:29 -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 S2406291AbfHIJwT (ORCPT + 99 others); Fri, 9 Aug 2019 05:52:19 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:4228 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2406239AbfHIJwG (ORCPT ); Fri, 9 Aug 2019 05:52:06 -0400 Received: from DGGEMS403-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 5719051BC774892B962E; Fri, 9 Aug 2019 17:52:03 +0800 (CST) Received: from huawei.com (10.175.124.28) by DGGEMS403-HUB.china.huawei.com (10.3.19.203) with Microsoft SMTP Server id 14.3.439.0; Fri, 9 Aug 2019 17:51:55 +0800 From: Jason Yan To: , , , , , , , , CC: , , , , , , , Jason Yan Subject: [PATCH v6 08/12] powerpc/fsl_booke/kaslr: clear the original kernel if randomized Date: Fri, 9 Aug 2019 18:07:56 +0800 Message-ID: <20190809100800.5426-9-yanaijie@huawei.com> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190809100800.5426-1-yanaijie@huawei.com> References: <20190809100800.5426-1-yanaijie@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.175.124.28] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Reviewed-by: Diana Craciun Tested-by: Diana Craciun --- 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 51a0b3749724..9a360b6124ed 100644 --- a/arch/powerpc/kernel/kaslr_booke.c +++ b/arch/powerpc/kernel/kaslr_booke.c @@ -373,3 +373,14 @@ notrace void __init kaslr_early_init(void *dt_ptr, phys_addr_t size) reloc_kernel_entry(dt_ptr, kernstart_virt_addr); } + +void __init kaslr_late_init(void) +{ + /* If randomized, clear the original kernel */ + if (kernstart_virt_addr != KERNELBASE) { + unsigned long kernel_sz; + + kernel_sz = (unsigned long)_end - kernstart_virt_addr; + memzero_explicit((void *)KERNELBASE, kernel_sz); + } +} diff --git a/arch/powerpc/mm/mmu_decl.h b/arch/powerpc/mm/mmu_decl.h index 213997d69729..64b2ac8a5343 100644 --- a/arch/powerpc/mm/mmu_decl.h +++ b/arch/powerpc/mm/mmu_decl.h @@ -151,8 +151,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_late_init(void); #else static inline void kaslr_early_init(void *dt_ptr, phys_addr_t size) {} +static inline void kaslr_late_init(void) {} #endif struct tlbcam { diff --git a/arch/powerpc/mm/nohash/fsl_booke.c b/arch/powerpc/mm/nohash/fsl_booke.c index 2dc27cf88add..b4eb06ceb189 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_late_init(); return; } -- 2.17.2