Received: by 2002:ac2:464d:0:0:0:0:0 with SMTP id s13csp2997395lfo; Mon, 30 May 2022 07:48:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwQDtPwOrdyA4y2O8PiaPbqdosKEhXGn2vpqfFnc4D1s7NXX4YoKsRAg4DnIm8GhIVvy546 X-Received: by 2002:aa7:dd48:0:b0:42a:f46f:6b0d with SMTP id o8-20020aa7dd48000000b0042af46f6b0dmr58096859edw.406.1653922105295; Mon, 30 May 2022 07:48:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653922105; cv=none; d=google.com; s=arc-20160816; b=Wgwa9n8VDKaiCsIwc/u0tsxVb+soR4bmCcfNAanBNKQ/P4L99v1vYZIOVQNrFY66VX qos/hAOIrNw26OfvVeQm+VkUgm6Eht/rXsaiSX+bqLmFYzysO9cPsB9LP6ffLZn5Drga 1MZ1+NipOTOiGLOzCkVGptEznORQfVJI6lkzMyo7rosbzA02aqgPAPK7KW6MKwWMyT7c z7sJHFbiOP1ziQvegyMfop1vBhDo8BnWC2zSd32G3EXt2HIpodvcU8vxmBLvxCnN2kHt KSzukJqbtmSeId0isJfVB7pQrFKn3ICS+4JMGr/JK3+eKfE/9j7vLctMDC3fSLefGZV+ S0LA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=vw7Jt9ul9F0FMDGWgi5H8H5vRTxg3Mgr811/HqBHgtw=; b=Z4aFzeKbSJIzyaDEay/T4lPVNOJLZ3NriXyZnvGs+s/vebWXZeDjYpi7EVC/4RA/Pk qbqZXn5Poija/30w/Rsnn5rNmgigcVNMJj5jCqRnWY/WMoN9nn/Wmcw1Sbk4A1VaXUnf IB8SBOiijjaaaeT9Qg8kHpjt36/LV2CvhNU/hzmY8OC+F2RYWwa9uvO3oGk5sgmhe3Zo YVkYv0bUhyAKbFeGd8EeDTG0az9qABcCGo6mOl501ftpFvPiRaa7bFeBVeCWe+1N/sO/ rANiIR1eAJhPxMn7XgT/jbBWi41ndUMWHL7hJGLD/U0i9HrE9Nr9MLJj30ZZA7Cv22lD lDgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=dGCGnNIM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d13-20020a50ea8d000000b0042acd0e4ce7si7563541edo.174.2022.05.30.07.47.58; Mon, 30 May 2022 07:48:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=dGCGnNIM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240811AbiE3OU2 (ORCPT + 99 others); Mon, 30 May 2022 10:20:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48560 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240733AbiE3OQW (ORCPT ); Mon, 30 May 2022 10:16:22 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF2C58D695; Mon, 30 May 2022 06:43:48 -0700 (PDT) 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 D2D45B80AE8; Mon, 30 May 2022 13:43:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 52701C385B8; Mon, 30 May 2022 13:43:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1653918222; bh=mkH+eDG1BW8aP4WRDNcQ5PhFkB9evQgyXJcnlgsnMxU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dGCGnNIMJ4ny52+lERu/tcrYDmwrxD3BTlqtmRV6EA/AxF95INPS+Izf6boBuelEK DO7yE1zl2ddmZEWjdy6YFbO4gSH3HUVdSoIrav/BpzYkR1QVJzjQ4JrQodAkbAGmLM uYH8ZdeHwmX8lhXaxySKbJoKaOAVju26xtqtJDGhDh1dAhfW6a72NNBKawpLd3/eSC 4xSKRiOcGUoWS4Y2sb6HxHoEjIZY1StWo/TzhVw39A1Lt34OGTOiJYlpsS4kGeGUHW EylRSIGNFSSBl3jpaBOJdJHJQufcUG02R4Xm5p2V1W5FimN0rlJbIxdO0yhQQkvQ7r x4J43Bro0AZVw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Ard Biesheuvel , Russell King , Sasha Levin , linux@armlinux.org.uk, linus.walleij@linaro.org, nico@fluxnic.net, keithpac@amazon.com, arnd@arndb.de, linux-arm-kernel@lists.infradead.org Subject: [PATCH AUTOSEL 5.15 100/109] ARM: 9201/1: spectre-bhb: rely on linker to emit cross-section literal loads Date: Mon, 30 May 2022 09:38:16 -0400 Message-Id: <20220530133825.1933431-100-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220530133825.1933431-1-sashal@kernel.org> References: <20220530133825.1933431-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ard Biesheuvel [ Upstream commit ad12c2f1587c6ec9b52ff226f438955bfae6ad89 ] The assembler does not permit 'LDR PC, ' when the symbol lives in a different section, which is why we have been relying on rather fragile open-coded arithmetic to load the address of the vector_swi routine into the program counter using a single LDR instruction in the SWI slot in the vector table. The literal was moved to a different section to in commit 19accfd373847 ("ARM: move vector stubs") to ensure that the vector stubs page does not need to be mapped readable for user space, which is the case for the vector page itself, as it carries the kuser helpers as well. So the cross-section literal load is open-coded, and this relies on the address of vector_swi to be at the very start of the vector stubs page, and we won't notice if we got it wrong until booting the kernel and see it break. Fortunately, it was guaranteed to break, so this was fragile but not problematic. Now that we have added two other variants of the vector table, we have 3 occurrences of the same trick, and so the size of our ISA/compiler/CPU validation space has tripled, in a way that may cause regressions to only be observed once booting the image in question on a CPU that exercises a particular vector table. So let's switch to true cross section references, and let the linker fix them up like it fixes up all the other cross section references in the vector page. Signed-off-by: Ard Biesheuvel Signed-off-by: Russell King (Oracle) Signed-off-by: Sasha Levin --- arch/arm/kernel/entry-armv.S | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S index 68261a83b7ad..01c5b3aee22f 100644 --- a/arch/arm/kernel/entry-armv.S +++ b/arch/arm/kernel/entry-armv.S @@ -1069,10 +1069,15 @@ ENDPROC(vector_bhb_bpiall_\name) .endm .section .stubs, "ax", %progbits - @ This must be the first word + @ These need to remain at the start of the section so that + @ they are in range of the 'SWI' entries in the vector tables + @ located 4k down. +.L__vector_swi: .word vector_swi #ifdef CONFIG_HARDEN_BRANCH_HISTORY +.L__vector_bhb_loop8_swi: .word vector_bhb_loop8_swi +.L__vector_bhb_bpiall_swi: .word vector_bhb_bpiall_swi #endif @@ -1215,10 +1220,11 @@ vector_addrexcptn: .globl vector_fiq .section .vectors, "ax", %progbits -.L__vectors_start: W(b) vector_rst W(b) vector_und - W(ldr) pc, .L__vectors_start + 0x1000 +ARM( .reloc ., R_ARM_LDR_PC_G0, .L__vector_swi ) +THUMB( .reloc ., R_ARM_THM_PC12, .L__vector_swi ) + W(ldr) pc, . W(b) vector_pabt W(b) vector_dabt W(b) vector_addrexcptn @@ -1227,10 +1233,11 @@ vector_addrexcptn: #ifdef CONFIG_HARDEN_BRANCH_HISTORY .section .vectors.bhb.loop8, "ax", %progbits -.L__vectors_bhb_loop8_start: W(b) vector_rst W(b) vector_bhb_loop8_und - W(ldr) pc, .L__vectors_bhb_loop8_start + 0x1004 +ARM( .reloc ., R_ARM_LDR_PC_G0, .L__vector_bhb_loop8_swi ) +THUMB( .reloc ., R_ARM_THM_PC12, .L__vector_bhb_loop8_swi ) + W(ldr) pc, . W(b) vector_bhb_loop8_pabt W(b) vector_bhb_loop8_dabt W(b) vector_addrexcptn @@ -1238,10 +1245,11 @@ vector_addrexcptn: W(b) vector_bhb_loop8_fiq .section .vectors.bhb.bpiall, "ax", %progbits -.L__vectors_bhb_bpiall_start: W(b) vector_rst W(b) vector_bhb_bpiall_und - W(ldr) pc, .L__vectors_bhb_bpiall_start + 0x1008 +ARM( .reloc ., R_ARM_LDR_PC_G0, .L__vector_bhb_bpiall_swi ) +THUMB( .reloc ., R_ARM_THM_PC12, .L__vector_bhb_bpiall_swi ) + W(ldr) pc, . W(b) vector_bhb_bpiall_pabt W(b) vector_bhb_bpiall_dabt W(b) vector_addrexcptn -- 2.35.1