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 25DC7C64ED6 for ; Tue, 28 Feb 2023 11:03:58 +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:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=2INfPlK1TCaWjNyv8DRkis3BeuXkV5sJlkNxB17rX1o=; b=SyixAAQXczkONq FB5BaHmohzXoXFeflRLxtROEdO8xLUb2/FqhIVZ4gqpabf7sld045ctmjGvdsjbZpkRWCHyelJTD6 FskWDo4yctuDqluiz4RkPp15BC/nzUiWZZeibMaTjBfoF3rn33qsZKNnwRDaFVGm14jq9q/9zzq9o L/3SWiokAjBcLVQMPV2RGwoWSFQSa7uhKvqV8APdnixegUOy/y1QNM9qRAg8TDzpqoCnfmQTuy28O 6PWLhKttwjER1Utocw0fjYR3gvMkXg8H7q4+RclEnKvvrx/FQqwIZC1qA+gKVJcbw68p6SVacex6d 4476UzMHtR1fsKzGOgEQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pWxl8-00CsAe-3g; Tue, 28 Feb 2023 11:03:02 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pWxkD-00Crjo-Sc for linux-arm-kernel@lists.infradead.org; Tue, 28 Feb 2023 11:02:07 +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 B2E93C14; Tue, 28 Feb 2023 03:02:43 -0800 (PST) Received: from FVFF77S0Q05N (unknown [10.57.17.252]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 49DF53F881; Tue, 28 Feb 2023 03:01:59 -0800 (PST) Date: Tue, 28 Feb 2023 11:01:56 +0000 From: Mark Rutland To: Ard Biesheuvel Cc: linux-arm-kernel@lists.infradead.org, linux-efi@vger.kernel.org, will@kernel.org, catalin.marinas@arm.com, maz@kernel.org, broonie@kernel.org Subject: Re: [PATCH] arm64: kaslr: don't pretend KASLR is enabled if offset < MIN_KIMG_ALIGN Message-ID: References: <20230223204101.1500373-1-ardb@kernel.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20230223204101.1500373-1-ardb@kernel.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230228_030206_064986_14580380 X-CRM114-Status: GOOD ( 28.39 ) 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 Thu, Feb 23, 2023 at 09:41:01PM +0100, Ard Biesheuvel wrote: > Our virtual KASLR displacement is a randomly chosen multiple of > 2 MiB plus an offset that is equal to the physical placement modulo 2 > MiB. This arrangement ensures that we can always use 2 MiB block > mappings (or contiguous PTE mappings for 16k or 64k pages) to map the > kernel. > > This means that a KASLR offset of less than 2 MiB is simply the product > of this physical displacement, and no randomization has actually taken > place. Currently, we use 'kaslr_offset() > 0' to decide whether or not > randomization has occurred, and so we misidentify this case. > Fix this, by correctly identifying the case where the virtual > displacement is a result of the physical displacement only. > > Signed-off-by: Ard Biesheuvel Acked-by: Mark Rutland Mark. > --- > I have sent out the same patch with a much shorter commit log as part of > my LPA2 series before, but I only realized today that this is likely to > fix most occurrences of the issue where a single 10g vmalloc() call > break subsequent module loading, so I am reposting it in isolation. > > arch/arm64/include/asm/memory.h | 11 +++++++++++ > arch/arm64/kernel/cpufeature.c | 2 +- > arch/arm64/kernel/kaslr.c | 2 +- > 3 files changed, 13 insertions(+), 2 deletions(-) > > diff --git a/arch/arm64/include/asm/memory.h b/arch/arm64/include/asm/memory.h > index 9dd08cd339c3f028..78e5163836a0ab95 100644 > --- a/arch/arm64/include/asm/memory.h > +++ b/arch/arm64/include/asm/memory.h > @@ -180,6 +180,7 @@ > #include > #include > #include > +#include > #include > > #if VA_BITS > 48 > @@ -203,6 +204,16 @@ static inline unsigned long kaslr_offset(void) > return kimage_vaddr - KIMAGE_VADDR; > } > > +static inline bool kaslr_enabled(void) > +{ > + /* > + * The KASLR offset modulo MIN_KIMG_ALIGN is taken from the physical > + * placement of the image rather than from the seed, so a displacement > + * of less than MIN_KIMG_ALIGN means that no seed was provided. > + */ > + return kaslr_offset() >= MIN_KIMG_ALIGN; > +} > + > /* > * Allow all memory at the discovery stage. We will clip it later. > */ > diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c > index 45a42cf2191c36c3..5643a9ca502af207 100644 > --- a/arch/arm64/kernel/cpufeature.c > +++ b/arch/arm64/kernel/cpufeature.c > @@ -1633,7 +1633,7 @@ bool kaslr_requires_kpti(void) > return false; > } > > - return kaslr_offset() > 0; > + return kaslr_enabled(); > } > > static bool __meltdown_safe = true; > diff --git a/arch/arm64/kernel/kaslr.c b/arch/arm64/kernel/kaslr.c > index 325455d16dbcb31a..e7477f21a4c9d062 100644 > --- a/arch/arm64/kernel/kaslr.c > +++ b/arch/arm64/kernel/kaslr.c > @@ -41,7 +41,7 @@ static int __init kaslr_init(void) > return 0; > } > > - if (!kaslr_offset()) { > + if (!kaslr_enabled()) { > pr_warn("KASLR disabled due to lack of seed\n"); > return 0; > } > -- > 2.39.1 > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel