From patchwork Mon Jun 13 14:45:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 12879633 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 D8B52C433EF for ; Mon, 13 Jun 2022 14:53:24 +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:References:In-Reply-To: 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: List-Owner; bh=0na1JXYJb0hMsIzwR4+ChgZrwo7vP/7hI/WgsnuEt+0=; b=d5AD1it0rrKJ5u 10OW5xEUIhfzA40gYXqK6LZ/AS2Occ3MaNjl6BpDWrw9h9+pMHHubXWJDRIYwcTwoQy+0i6cBRlBh IXg65Ylf9XNccQkEaY5RIEJyjQ+1It0k4ppOh2WMvoi07bYWz1B50X6IFoausY2wJUn1dMLZhTvt6 TaQYVT/o6bCI/iM/ddGwJjDeYGX6owUVO30eDQcO1+CnU2j10/YItjd2Rq2SS7FFsAqwaYTIqKSnx oTN+IMjCpLvYVQnWexw6pNkbjbrop2+fbm66caeggJIjIhN8z7OHkkBiM/7HUIBDyt/OkpHj378l5 9ss7gdY6OSiKZe4TiZPA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1o0lQH-004JYf-E5; Mon, 13 Jun 2022 14:52:09 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1o0lKu-004GY5-RB for linux-arm-kernel@lists.infradead.org; Mon, 13 Jun 2022 14:46:38 +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 dfw.source.kernel.org (Postfix) with ESMTPS id 56CB361376; Mon, 13 Jun 2022 14:46:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B816DC341C5; Mon, 13 Jun 2022 14:46:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1655131595; bh=Sebmph6142BXBlJPI/sJ5wvh1+uaiXRSU83+rxfrjl4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pxPRRL8aFRarWImRiHvYiTjNFvq3Paxmk+Qiz31oKxvVoX1SSypdKqVmgVUtFitrp 7Zmr6cRcR1UfQQLWbfq0iZqxDmzuBTqpMlIavOznfQah8EMHOid6/JWs4zRCjfwM3E lmbNhNEvsLbGhKBKYWDp/knwR94NAnfS4BoNg2AHg8KRq0Srs6msA0PTQpSd0iGsqf s3qrhlz3uw7LDWX9PKHNV3maJBl8G6/CTAMYPqu2Nc+vrlGwiOV+U1HJIwqlUPwoPB 322jV+VgbXH0Dg+zjSqYdjSuzamY+ZnNDTGf6bD/tf7mhyVQtQHMbzSlfSvKfNyYSb GLfQn3B3VMKHg== From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Cc: linux-hardening@vger.kernel.org, Ard Biesheuvel , Marc Zyngier , Will Deacon , Mark Rutland , Kees Cook , Catalin Marinas , Mark Brown , Anshuman Khandual Subject: [PATCH v4 13/26] arm64: head: use relative references to the RELA and RELR tables Date: Mon, 13 Jun 2022 16:45:37 +0200 Message-Id: <20220613144550.3760857-14-ardb@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220613144550.3760857-1-ardb@kernel.org> References: <20220613144550.3760857-1-ardb@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2627; h=from:subject; bh=Sebmph6142BXBlJPI/sJ5wvh1+uaiXRSU83+rxfrjl4=; b=owEB7QES/pANAwAKAcNPIjmS2Y8kAcsmYgBip02GLq2FHYMY0bvVRisFO4eIi6ViFcZXouW0CQuT eMSeBImJAbMEAAEKAB0WIQT72WJ8QGnJQhU3VynDTyI5ktmPJAUCYqdNhgAKCRDDTyI5ktmPJBUmDA DCM1DXqu6J9f5nYdjb6VqpzoGn2cklxv38hiVT7jUJAC94MMa9agfQemdishg25BOt6b3hdGhKZ5LY m7PnuIY2SUCaTLqgGtWl/yVx4eiQA8HEwO/WecrF1arlRfh212NXV8rgFEfA6vywC20a8yzoUP4pP4 8XIrNqnCD5/pjLRajCGHj5WjGbCWODfsYPS4oqBuQghAGJ91wW0Nc6u533vFYZ0Zgr5VPQ9TK8SeTx UjJmUurH0z/8b8wQ3xBz9fujBQunnqA8WMDOCyxo9331dg0fagInwt/1zlJOf3sX4IGR82JSAWhdWG CxczFfVrGv6T+2qWimzVA6yLbkTe6moba2NsMR3wZkWB54gsPJZMmBMc5xk4ZEogCeyS+d2eSA0Bvu ZVzBoAgvgsBbUl9Z6bAVRp3FltMLrkCJkRLllf0Q3oLms6QkvJwfpT6seVW2skasl+hsZFy1Qlra6Q 34pcG8YxvYDD1N/Wj5DBNpJsaAyY7hZVd6+8Spfd6OS34= 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-20220613_074636_994087_C8DC27E4 X-CRM114-Status: GOOD ( 15.87 ) 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 Formerly, we had to access the RELA and RELR tables via the kernel mapping that was being relocated, and so deriving the start and end addresses using ADRP/ADD references was not possible, as the relocation code runs from the ID map. Now that we map the entire kernel image via the ID map, we can simplify this, and just load the entries via the ID map as well. Signed-off-by: Ard Biesheuvel --- arch/arm64/kernel/head.S | 13 ++++--------- arch/arm64/kernel/vmlinux.lds.S | 12 ++++-------- 2 files changed, 8 insertions(+), 17 deletions(-) diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S index 93734c91a29a..f1497f7b4da0 100644 --- a/arch/arm64/kernel/head.S +++ b/arch/arm64/kernel/head.S @@ -757,13 +757,10 @@ SYM_FUNC_START_LOCAL(__relocate_kernel) * Iterate over each entry in the relocation table, and apply the * relocations in place. */ - ldr w9, =__rela_offset // offset to reloc table - ldr w10, =__rela_size // size of reloc table - + adr_l x9, __rela_start + adr_l x10, __rela_end mov_q x11, KIMAGE_VADDR // default virtual offset add x11, x11, x23 // actual virtual offset - add x9, x9, x11 // __va(.rela) - add x10, x9, x10 // __va(.rela) + sizeof(.rela) 0: cmp x9, x10 b.hs 1f @@ -813,10 +810,8 @@ SYM_FUNC_START_LOCAL(__relocate_kernel) * __relocate_kernel is called twice with non-zero displacements (i.e. * if there is both a physical misalignment and a KASLR displacement). */ - ldr w9, =__relr_offset // offset to reloc table - ldr w10, =__relr_size // size of reloc table - add x9, x9, x11 // __va(.relr) - add x10, x9, x10 // __va(.relr) + sizeof(.relr) + adr_l x9, __relr_start + adr_l x10, __relr_end sub x15, x23, x24 // delta from previous offset cbz x15, 7f // nothing to do if unchanged diff --git a/arch/arm64/kernel/vmlinux.lds.S b/arch/arm64/kernel/vmlinux.lds.S index 0ce3a7c9f8c4..45131e354e27 100644 --- a/arch/arm64/kernel/vmlinux.lds.S +++ b/arch/arm64/kernel/vmlinux.lds.S @@ -257,21 +257,17 @@ SECTIONS HYPERVISOR_RELOC_SECTION .rela.dyn : ALIGN(8) { + __rela_start = .; *(.rela .rela*) + __rela_end = .; } - __rela_offset = ABSOLUTE(ADDR(.rela.dyn) - KIMAGE_VADDR); - __rela_size = SIZEOF(.rela.dyn); - -#ifdef CONFIG_RELR .relr.dyn : ALIGN(8) { + __relr_start = .; *(.relr.dyn) + __relr_end = .; } - __relr_offset = ABSOLUTE(ADDR(.relr.dyn) - KIMAGE_VADDR); - __relr_size = SIZEOF(.relr.dyn); -#endif - . = ALIGN(SEGMENT_ALIGN); __initdata_end = .; __init_end = .;