From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 72A5CC4167B for ; Thu, 30 Nov 2023 05:24:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:From:References:Cc:To: Subject:MIME-Version:Date:Message-ID:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=1aUTDmzAllYAMp8WFtwlC4WeNpCmHeFj+vv9Tv92rP4=; b=f8BIJ7fnw9fVo0 yBcG40TEc06TlwlYhirt3HhiPHEGVV18r9vTcELWNosczmQD/RHH9xjl+yy+plqzR26sziDZ6pXJ7 L8oR0nk8/Y84UrGka0VGgVaCXWvGboRwf3y/3vs4QkUDfModa5NaW9Sg7C3wrBoo3FuwN3EdkTeeS yqbAyCuWuHdg5UegeblUeLkuOWRBxgLclP8XOm51KxDrMekPVD2MlejC2uJULCqmR1gnzwVitkrCa OQETmr1EDK58SxsjKMNgHBvHd56O6J2CF1TPUGsKm31butvRrjNfK/iP9Dq4BubgCAG5YobmTkdPf Ncu/9Keba50C1yTKPvow==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1r8ZWZ-009xkD-2Z; Thu, 30 Nov 2023 05:23:43 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1r8ZWW-009xhb-0B for linux-arm-kernel@lists.infradead.org; Thu, 30 Nov 2023 05:23:42 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 47F9B1042; Wed, 29 Nov 2023 21:24:20 -0800 (PST) Received: from [10.162.41.8] (a077893.blr.arm.com [10.162.41.8]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id EE18D3F5A1; Wed, 29 Nov 2023 21:23:30 -0800 (PST) Message-ID: Date: Thu, 30 Nov 2023 10:53:28 +0530 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v6 02/41] arm64: mm: Take potential load offset into account when KASLR is off Content-Language: en-US To: Ard Biesheuvel , linux-arm-kernel@lists.infradead.org Cc: Ard Biesheuvel , Catalin Marinas , Will Deacon , Marc Zyngier , Mark Rutland , Ryan Roberts , Kees Cook References: <20231129111555.3594833-43-ardb@google.com> <20231129111555.3594833-45-ardb@google.com> From: Anshuman Khandual In-Reply-To: <20231129111555.3594833-45-ardb@google.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231129_212340_189784_99DAD24B X-CRM114-Status: GOOD ( 27.61 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 11/29/23 16:45, Ard Biesheuvel wrote: > From: Ard Biesheuvel > > We enable CONFIG_RELOCATABLE even when CONFIG_RANDOMIZE_BASE is > disabled, and this permits the loader (i.e., EFI) to place the kernel Indeed, could validate this out via defconfig based build and boot. > anywhere in physical memory as long as the base address is 64k aligned. > > This means that the 'KASLR' case described in the header that defines > the size of the statically allocated page tables could take effect even > when CONFIG_RANDMIZE_BASE=n. So check for CONFIG_RELOCATABLE instead. Makes sense. > > Signed-off-by: Ard Biesheuvel > --- > arch/arm64/include/asm/kernel-pgtable.h | 27 +++++--------------- > 1 file changed, 6 insertions(+), 21 deletions(-) > > diff --git a/arch/arm64/include/asm/kernel-pgtable.h b/arch/arm64/include/asm/kernel-pgtable.h > index 85d26143faa5..83ddb14b95a5 100644 > --- a/arch/arm64/include/asm/kernel-pgtable.h > +++ b/arch/arm64/include/asm/kernel-pgtable.h > @@ -37,27 +37,12 @@ > > > /* > - * If KASLR is enabled, then an offset K is added to the kernel address > - * space. The bottom 21 bits of this offset are zero to guarantee 2MB > - * alignment for PA and VA. > - * > - * For each pagetable level of the swapper, we know that the shift will > - * be larger than 21 (for the 4KB granule case we use section maps thus > - * the smallest shift is actually 30) thus there is the possibility that > - * KASLR can increase the number of pagetable entries by 1, so we make > - * room for this extra entry. > - * > - * Note KASLR cannot increase the number of required entries for a level > - * by more than one because it increments both the virtual start and end > - * addresses equally (the extra entry comes from the case where the end > - * address is just pushed over a boundary and the start address isn't). > + * A relocatable kernel may execute from an address that differs from the one at > + * which it was linked. In the worst case, its runtime placement may intersect > + * with two adjacent PGDIR entries, which means that an additional page table > + * may be needed at each subordinate level. > */ This is a better explanation. > - > -#ifdef CONFIG_RANDOMIZE_BASE > -#define EARLY_KASLR (1) > -#else > -#define EARLY_KASLR (0) > -#endif > +#define EXTRA_PAGE __is_defined(CONFIG_RELOCATABLE) EXTRA_INIT_DIR_PAGE instead ? Just to have some more context. > > #define SPAN_NR_ENTRIES(vstart, vend, shift) \ > ((((vend) - 1) >> (shift)) - ((vstart) >> (shift)) + 1) > @@ -83,7 +68,7 @@ > + EARLY_PGDS((vstart), (vend), add) /* each PGDIR needs a next level page table */ \ > + EARLY_PUDS((vstart), (vend), add) /* each PUD needs a next level page table */ \ > + EARLY_PMDS((vstart), (vend), add)) /* each PMD needs a next level page table */ > -#define INIT_DIR_SIZE (PAGE_SIZE * EARLY_PAGES(KIMAGE_VADDR, _end, EARLY_KASLR)) > +#define INIT_DIR_SIZE (PAGE_SIZE * EARLY_PAGES(KIMAGE_VADDR, _end, EXTRA_PAGE)) > > /* the initial ID map may need two extra pages if it needs to be extended */ > #if VA_BITS < 48 Regardless Reviewed-by: Anshuman Khandual _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel