From patchwork Sat Aug 27 07:09:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 12956834 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 B588DC0502C for ; Sat, 27 Aug 2022 07:10:50 +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:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=LK4v5qh/meDvkt+M4L4RmuFKSuHEfcawfm/c3uaBTAg=; b=Rz5jsWes1WNQ/6 4DEsBLM56ODj1Nix9HzRW/hHT3GuhhS51fSX3/BtLfz//+x9PtXZgLg5YygglCxku4wBLYV0dGbL4 RDBhloxzWIqYWZIZrBNMo7yO9745DcCkHeB2thu27N/G9trjVpnnDTZ3BzhMbFA95rJmRdsG6OHMP RYKClTIuxTiBPtkeLUMzmofadUblXmddEt7vJTy4o3mFEP+XgsWlginzYwYEVpgvzSXwrvbn6aEcc ULQw9FYEgulSoPAU0gK3K6pWVNsI90X8zEK4A2hMUREg4nbQL7ssFlJBNc5WYRdh/Kl0c5y1sf3yo QM+hJN7SXOD3KXPla1fg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oRpwe-004ktM-Vq; Sat, 27 Aug 2022 07:09:29 +0000 Received: from ams.source.kernel.org ([145.40.68.75]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oRpwc-004km0-4p for linux-arm-kernel@lists.infradead.org; Sat, 27 Aug 2022 07:09:27 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 9EAC7B82B8D; Sat, 27 Aug 2022 07:09:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B50FDC433D7; Sat, 27 Aug 2022 07:09:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1661584162; bh=arBX6XdcvDyFgVvMwINUrqorjgeptwQGAj9G+BmQEck=; h=From:To:Cc:Subject:Date:From; b=RaSJLbjTtlfQ0ZdSbVos6C83fkB4bDnUkya5SxHFkaqOXcl/lATBs7YK0zDKL4qIK Yda6iuCcQ9eR4cRpOsF/pOtBZY0VMnWlWJzz3dU/Wlzg0OGXF2TmoNrqlpAV6a+o6V vaaNzOgTR4FzQuK912wMs1ufWXjnd3GWlravT1msdBYcKFS4yWOIO27StqYMrCXF4P HdR9TJ/O2Vc73RM4BqiChn7Iv4BvCCtQf4CnE/Z7HuaySbI1uW4UB1kSQlSlFFd73i XIs7N1wt1PAOP4s9K8YVIYEwBzdn600o/px70Q2emvrCSq/OsUl3OrWLxrCHITd0lh e17NXr2LwJpSg== From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Cc: will@kernel.org, catalin.marinas@arm.com, maz@kernel.org, mark.rutland@arm.com, mpatocka@redhat.com, Ard Biesheuvel Subject: [PATCH] arm64: head: Ignore bogus KASLR displacement on non-relocatable kernels Date: Sat, 27 Aug 2022 09:09:04 +0200 Message-Id: <20220827070904.2216989-1-ardb@kernel.org> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1592; i=ardb@kernel.org; h=from:subject; bh=arBX6XdcvDyFgVvMwINUrqorjgeptwQGAj9G+BmQEck=; b=owEB7QES/pANAwAKAcNPIjmS2Y8kAcsmYgBjCcMPfPMS8bV8RM+9/6Z3xBtuT8EZzl9CnBaUZ6Ul ZWF5lpiJAbMEAAEKAB0WIQT72WJ8QGnJQhU3VynDTyI5ktmPJAUCYwnDDwAKCRDDTyI5ktmPJAQmDA CuAGCCxyF84MwqixJ0norCU+S74r5zJx5HWGfoaxyPf4gnrBisYbp5sznpSLrYkjXPhxTGE25Do6Kp Fy9Dsd2oBfXzVpbk3dfW07IB6Fen1WHBpgvaNP6qyEfVBIPVYx5S1VYFBTSWgLWDBX4+CacOzf80MQ bQY7+tJ1zHbrG8y76wt53hxjrC3Ii+jurZIFbzcP0rP3n77j8wleIevc+3zvtGuvq9woO10a2JWRzV u4Cl38uQiVYtAj90VuefI7Id+3HFMgNNj/+G2slB6qTMAd9GMMwiPy+5wDigZnp9w/J6lT651HkuNw vqVYrTW4A5CBFBklafNZBTMVP4oCmsaKGOiWzmof9jEkYgi4BESUCnFyXwW2DOZpo5/i0y5/gQrwI9 ZyXEDeg0yDCfQghxwqR9CoUUGeF5p7G5BuDlHu1vntcsf/DdwEaVBD0NcRz83VI6dhYtXcjtQvtBtu nIq0qzt40tATVNS25ccVZ+/1tzPfVfqDmCxQ+vdhYen84= X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220827_000926_377517_D6242299 X-CRM114-Status: GOOD ( 13.01 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Even non-KASLR kernels can be built as relocatable, to work around broken bootloaders that violate the rules regarding physical placement of the kernel image - in this case, the physical offset modulo 2 MiB is used as the KASLR offset, and all absolute symbol references are fixed up in the usual way. This workaround is enabled by default. CONFIG_RELOCATABLE can also be disabled entirely, in which case the relocation code and the code that captures the offset are omitted from the build. However, since commit aacd149b6238 ("arm64: head: avoid relocating the kernel twice for KASLR"), this code got out of sync, and we still add the offset to the kernel virtual address before populating the page tables even though we never capture it. This means we add a bogus value instead, breaking the boot entirely. Fixes: aacd149b6238 ("arm64: head: avoid relocating the kernel twice for KASLR") Signed-off-by: Ard Biesheuvel Tested-by: Mikulas Patocka --- arch/arm64/kernel/head.S | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S index cefe6a73ee54..814b6587ccb7 100644 --- a/arch/arm64/kernel/head.S +++ b/arch/arm64/kernel/head.S @@ -371,7 +371,9 @@ SYM_FUNC_END(create_idmap) SYM_FUNC_START_LOCAL(create_kernel_mapping) adrp x0, init_pg_dir mov_q x5, KIMAGE_VADDR // compile time __va(_text) +#ifdef CONFIG_RELOCATABLE add x5, x5, x23 // add KASLR displacement +#endif adrp x6, _end // runtime __pa(_end) adrp x3, _text // runtime __pa(_text) sub x6, x6, x3 // _end - _text