Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp5819771ioo; Wed, 1 Jun 2022 13:17:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwlPQiKuKd33cxTZApHJdKT3IbhK4xqaP/iQ9rT760RR7HUJ0v6jjIvj//a+Yd9Ti4Q8910 X-Received: by 2002:a17:90b:1809:b0:1df:de43:e56 with SMTP id lw9-20020a17090b180900b001dfde430e56mr36482925pjb.135.1654114629109; Wed, 01 Jun 2022 13:17:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654114629; cv=none; d=google.com; s=arc-20160816; b=d5dACKjb/FBQ8/5DHr8S8IMV6c9H2dnIq87/P/L4m/wAGmOw1qWn1tbb5m6EPKyFZI /CR8wkHQDMNVwh27QLtciOuTJSMKoxtnstestz5IA5OdgpT7PWNpDPWamItiE3X7Bfdk fWvoCpcbPkqW3M6TfdKznh2wXUpEHlwzvdbYJNwfSvBoHTSvAkns+AmpDEtQnK6picNe M6ZkcDwdF+46w2hqjJXLi4NwSonaFIXBEbcpgioWVQgy43PeP5Peb53SELjccIv0va51 kkdhPwHsjzzv1aM5BNe14FyWSdOAX4W7RnVrUABNjpiEZcDcnLOqGTiy09Za7eAcmbmQ T9Jg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=e3JUorm9iFOITCfVv7GarXPOdYerVij2+9dUxPWI6oc=; b=QpXBmRKyH4lz9sT+X4mQ2vBLuyRTB3e5hzJI9h5nJvla078xAwwTNhG1WgT9xBOgJg T/xnMAW9aC3VIST87qlQ76qymrzwDki2FCcF42FDBoGPVvz7KoKAxMFPoTwmzf4DgFCL 4JgYL6rMCEtkCCFgio4wVYI6JxPDNmnrO16Lsy5ZEI9sIbKfy7Z/O8kfvajj1O6HptaX S75XHf+5OSiXw3XYqD14TSR3TGX8H0A5dKysiNNB7jC8UmBZrzWE83iEV3hIkldzGKmW kKecIXejoPikeB89tLcvhdM86NtJuhCIaFHmyepQHznmXJCl3g4NN3jymyc5LYYPy+13 E4ag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=gmaH3mIF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id ls14-20020a17090b350e00b001e0676bf470si9177323pjb.175.2022.06.01.13.17.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Jun 2022 13:17:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=gmaH3mIF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A3947245393; Wed, 1 Jun 2022 12:31:25 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242277AbiE3Ove (ORCPT + 99 others); Mon, 30 May 2022 10:51:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56164 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242607AbiE3ObW (ORCPT ); Mon, 30 May 2022 10:31: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 90B3312D1F6; Mon, 30 May 2022 06:53:13 -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 71619B80DE4; Mon, 30 May 2022 13:52:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 12E94C385B8; Mon, 30 May 2022 13:52:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1653918771; bh=IsjXNX3etQ7+7cakfgwWRPXIpl4UWGXScyzTt/MVUqg=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=gmaH3mIFU4FmgDP71ExoVahOisKwwldzyl5kh7bZJkrR1slATPxlY4oJLoN6/99cZ M5ClStirarAphpMUepI+OaddWCjYuWrFQU4gKHOeynCF/5HMANAsMwdQolRAyNo/E9 SM8bD+p1iVuEtD6CC9BEG2BRE1NKtQDJ3HR8IJvvGPXE3Eky/WEgPpZc5lWwpwPJIG wlQakuIG444+XK6c2lNstFEP+1ozWRcBMoGqH6pcErDKIaDXNmTHRdW3Tgp5NiwVDr /WJXnaKdTn+TyVkXB7U1XpfUaD6FcWS3N9HS+4kOhArWsQfgSuZGdKwgV4VqPisdV8 tz52au4ARPD/w== Received: by mail-oa1-f51.google.com with SMTP id 586e51a60fabf-f16a3e0529so14400895fac.2; Mon, 30 May 2022 06:52:51 -0700 (PDT) X-Gm-Message-State: AOAM530Sp+na4aQwyrlOPlBp4tY7hNV5YyZ9nILJRyAg7vlFYfiKPO7/ jAnNyU418SnKwPicdOAm7MGvE8HdIFw7uDeT6j0= X-Received: by 2002:a05:6870:eaa5:b0:da:b3f:2b45 with SMTP id s37-20020a056870eaa500b000da0b3f2b45mr10799165oap.228.1653918770217; Mon, 30 May 2022 06:52:50 -0700 (PDT) MIME-Version: 1.0 References: <20220530134701.1935933-1-sashal@kernel.org> <20220530134701.1935933-51-sashal@kernel.org> In-Reply-To: <20220530134701.1935933-51-sashal@kernel.org> From: Ard Biesheuvel Date: Mon, 30 May 2022 15:52:39 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH AUTOSEL 5.4 51/55] ARM: 9201/1: spectre-bhb: rely on linker to emit cross-section literal loads To: Sasha Levin Cc: Linux Kernel Mailing List , "# 3.4.x" , Russell King , Russell King , Linus Walleij , Nicolas Pitre , Keith Packard , Arnd Bergmann , Linux ARM Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 AUTONAK On Mon, 30 May 2022 at 15:49, Sasha Levin wrote: > > 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 8e8efe28d799..4d900c61a0f7 100644 > --- a/arch/arm/kernel/entry-armv.S > +++ b/arch/arm/kernel/entry-armv.S > @@ -1074,10 +1074,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 > > @@ -1220,10 +1225,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 > @@ -1232,10 +1238,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 > @@ -1243,10 +1250,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 >