Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp5439506ybh; Wed, 7 Aug 2019 06:06:23 -0700 (PDT) X-Google-Smtp-Source: APXvYqzbwtZ0xI4MgQPXvoPYIKfr7NX1Jk5tytMs1OeAUissa6s4hAYAiorOpPa/y4cCuD9YqVIm X-Received: by 2002:a17:902:be0a:: with SMTP id r10mr7667474pls.51.1565183182945; Wed, 07 Aug 2019 06:06:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565183182; cv=none; d=google.com; s=arc-20160816; b=OwHLwusL7QoMhI7IYXt2J60XiJ5HVpBsh4JsNrv2I6JOkpaQYy6Gopn2vlLnrXMt6d /w5QSsF4uLSaCVLMGZSS5eIq3fuuNCrn1ZbV+Ry2Qubm5+uSc5MMMeBvsZxIHEFCjtw+ fYhtuqn/B2uFzgJCG6bzi9zsFBIIcFeSptXMplTgnWQgtm+SPNpGfatNAFbwS5fNn1He qK8GRAiM+tXXYYzzajkbP8KZDhHWOVqfKSd9SrvTOnf9l8xO3Rklus1CcLOdZZh3Rr4v sD/Uu4ptOu80CQ7e0L4PsrL2N/FlXZBSaPB4BhEQbrkT4k9Mv6z7gyRfB/vdibDcgE7p XqRg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from; bh=qXsnIH9o/9QF0ILfNUc2OXfLLYIn4ziUvsC1jbYrkS8=; b=h41Ygs8XSH3x9Pz/bfY8qPzHtc0gITIQkqHJUBhmX1F5mXEe16NFB/dkErKdGE/nqG /vTwZ3bbBbHGcI34Ddk1dQ6in1A+myPAh9Kk/0wdAqlCZTVnLSgxHhtCAMP25XwXK0BX aYqsUt9jZJwE3sgLDvqlW7guqg/rJh7lN+VRBr/CoLEHYhgxDbE73zD7MrXCpYonP4/t nBAiFAxGYGwfNbiCvEv6gvN7Qm1pfedlfKzZiKyG0q7n0TEaDJQFxsW4wv0E5VYfaHIY q1cD4NPAJgxtVZFVKvz6njHKTF/PeGZ4kxCwkGb5+xKumIYpsTzewep6GtllwRd8NJUB QecA== 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 l3si17521699pju.85.2019.08.07.06.06.05; Wed, 07 Aug 2019 06:06:22 -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 S2388121AbfHGNEM (ORCPT + 99 others); Wed, 7 Aug 2019 09:04:12 -0400 Received: from ozlabs.org ([203.11.71.1]:44327 "EHLO ozlabs.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388115AbfHGNEM (ORCPT ); Wed, 7 Aug 2019 09:04:12 -0400 Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.ozlabs.org (Postfix) with ESMTPSA id 463Wt146ZRz9sNy; Wed, 7 Aug 2019 23:04:09 +1000 (AEST) From: Michael Ellerman To: Jason Yan , linuxppc-dev@lists.ozlabs.org, diana.craciun@nxp.com, christophe.leroy@c-s.fr, 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, Jason Yan Subject: Re: [PATCH v5 06/10] powerpc/fsl_booke/32: implement KASLR infrastructure In-Reply-To: <20190807065706.11411-7-yanaijie@huawei.com> References: <20190807065706.11411-1-yanaijie@huawei.com> <20190807065706.11411-7-yanaijie@huawei.com> Date: Wed, 07 Aug 2019 23:04:05 +1000 Message-ID: <87wofpt9dm.fsf@concordia.ellerman.id.au> MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Jason Yan writes: > This patch add support to boot kernel from places other than KERNELBASE. > Since CONFIG_RELOCATABLE has already supported, what we need to do is > map or copy kernel to a proper place and relocate. Freescale Book-E > parts expect lowmem to be mapped by fixed TLB entries(TLB1). The TLB1 > entries are not suitable to map the kernel directly in a randomized > region, so we chose to copy the kernel to a proper place and restart to > relocate. So to be 100% clear you are randomising the location of the kernel in virtual and physical space, by the same amount, and retaining the 1:1 linear mapping. > diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig > index 77f6ebf97113..755378887912 100644 > --- a/arch/powerpc/Kconfig > +++ b/arch/powerpc/Kconfig > @@ -548,6 +548,17 @@ config RELOCATABLE > setting can still be useful to bootwrappers that need to know the > load address of the kernel (eg. u-boot/mkimage). > > +config RANDOMIZE_BASE > + bool "Randomize the address of the kernel image" > + depends on (FSL_BOOKE && FLATMEM && PPC32) > + select RELOCATABLE I think this should depend on RELOCATABLE, rather than selecting it. > diff --git a/arch/powerpc/kernel/kaslr_booke.c b/arch/powerpc/kernel/kaslr_booke.c > new file mode 100644 > index 000000000000..30f84c0321b2 > --- /dev/null > +++ b/arch/powerpc/kernel/kaslr_booke.c > @@ -0,0 +1,84 @@ > +// SPDX-License-Identifier: GPL-2.0-only > +/* > + * Copyright (C) 2019 Jason Yan > + * > + * This program is free software; you can redistribute it and/or modify > + * it under the terms of the GNU General Public License version 2 as > + * published by the Free Software Foundation. You don't need that paragraph now that you have the SPDX tag. Rather than using a '//' comment followed by a single line block comment you can format it as: // SPDX-License-Identifier: GPL-2.0-only // // Copyright (C) 2019 Jason Yan > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include Do you really need all those headers? > +extern int is_second_reloc; That should be in a header. Any reason why it isn't a bool? cheers