Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp36840pxb; Tue, 12 Apr 2022 16:06:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwK+oH9wpEsnLtBJydRH8F6CEUsy2OmPOcSj4k+0VzT/EoRAhdILPwUtMvMVfr9vTEu/HAe X-Received: by 2002:a05:6a00:814:b0:505:9fad:4240 with SMTP id m20-20020a056a00081400b005059fad4240mr18271607pfk.15.1649804792516; Tue, 12 Apr 2022 16:06:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649804792; cv=none; d=google.com; s=arc-20160816; b=M4rvaFvuYMR+z21AgwECm2F21FmdYGZZHx168pAgT2lBX7J8uOUCW3mWNqIVQWwKxo 4EhbFOgYkq1Xf89WPWiu+Aa7OI/EjYvqz19Ka82w/uHYbMASpMTRTqA0JuQ6wnIWS6EE IPE+h/Fu3dVVdSwcAu4UEKJ02v1+mkrEio0pjaylk970eOp0b3m1P6Hwk50xZ2v90r5T DrJepignd6LXplVgu0xKhMWLLBwZg6TaD/zofdiMMPuO3g+FbwACRRS9IOOP2eFLO+fh whREOfoWsIHbTWzxKnAWWF6+EnwIzBv+nLIQ7wYoddoVPCe3sXHfkE3yXhVex3rJO+8+ FYpg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=CSOphAyNX1M/7FZMKIVOoJQ57qee5+hwCTFJ0iNKbHo=; b=VhxDgXc7PSiOYx4PrJYQhdiFxss2MMeH9RDHpJWNzMiWa50pcxcV/HyLDhrgroUcpi Iy0dnqcRi7iWqlEJupFGtraHZFEV9SCQbUJiPFndukjzQzP+fmq45Dmqnc1N124cLhGZ FdKpKll187PDg6Nq77pXSHwqmDSg1lB5zlb4rsNbJZUGmcKLuKjZGywXFQf257zJEuVo ckrM+ObXiTNCfb3SNcSxCDglkgz/7T3RoCpylBV9qorjMB4ZUexcviLVGmyM2Ka8qHas tgwXgTbXQrCX+WX1932zerOhyPCBpBqSsFRLNzs/lxF22/8viY6KVrHn+2irREeI02vg rNJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=hz3lhBD7; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id l8-20020a056a0016c800b00505793705besi14139790pfc.182.2022.04.12.16.06.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Apr 2022 16:06:32 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=hz3lhBD7; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2FEB139BA4; Tue, 12 Apr 2022 14:48:41 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348351AbiDLFul (ORCPT + 99 others); Tue, 12 Apr 2022 01:50:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39738 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344379AbiDLFuj (ORCPT ); Tue, 12 Apr 2022 01:50:39 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A62FF28E21; Mon, 11 Apr 2022 22:48:22 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 2EBDA61862; Tue, 12 Apr 2022 05:48:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3C9C6C385A1; Tue, 12 Apr 2022 05:48:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649742501; bh=cgeRhs/ApvaNYGH9iK4LRCPUOGebM4VMdLU7Lqm3pX4=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=hz3lhBD7U6q5FzF5hZ/3QVxJefBQgc5VuY1K3mZ/TxI12pXAnzSmWMR6pJX2YHAuk USjdZPoISoZD1tms2GUZVMf9pGud1uouYQ5Lbe88j4pyfdcLHEy/MwDEti3CadZCcq PuMVteSKn7695NaXSUSg6ppHqhRDfIkmCleKZ3ms= Date: Tue, 12 Apr 2022 07:48:18 +0200 From: Greg KH To: James Morse Cc: linux-kernel@vger.kernel.org, stable@vger.kernel.org, Catalin Marinas Subject: Re: [stable:PATCH v4.9.309 40/43] arm64: Mitigate spectre style branch history side channels Message-ID: References: <0220406164217.1888053-1-james.morse@arm.com> <20220406164546.1888528-1-james.morse@arm.com> <20220406164546.1888528-40-james.morse@arm.com> <82b7cb2e-825a-0efc-daae-98aa556c5086@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <82b7cb2e-825a-0efc-daae-98aa556c5086@arm.com> X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 On Fri, Apr 08, 2022 at 05:56:34PM +0100, James Morse wrote: > Hi Greg, > > On 06/04/2022 17:45, James Morse wrote: > > commit 558c303c9734af5a813739cd284879227f7297d2 upstream. > > > > Speculation attacks against some high-performance processors can > > make use of branch history to influence future speculation. > > When taking an exception from user-space, a sequence of branches > > or a firmware call overwrites or invalidates the branch history. > > > > The sequence of branches is added to the vectors, and should appear > > before the first indirect branch. For systems using KPTI the sequence > > is added to the kpti trampoline where it has a free register as the exit > > from the trampoline is via a 'ret'. For systems not using KPTI, the same > > register tricks are used to free up a register in the vectors. > > > > For the firmware call, arch-workaround-3 clobbers 4 registers, so > > there is no choice but to save them to the EL1 stack. This only happens > > for entry from EL0, so if we take an exception due to the stack access, > > it will not become re-entrant. > > > > For KVM, the existing branch-predictor-hardening vectors are used. > > When a spectre version of these vectors is in use, the firmware call > > is sufficient to mitigate against Spectre-BHB. For the non-spectre > > versions, the sequence of branches is added to the indirect vector. > > > > diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig > > index 42719bd58046..6d12c3b78777 100644 > > --- a/arch/arm64/Kconfig > > +++ b/arch/arm64/Kconfig > > @@ -799,6 +799,16 @@ config ARM64_SSBD > > > > If unsure, say Y. > > > > +config MITIGATE_SPECTRE_BRANCH_HISTORY > > + bool "Mitigate Spectre style attacks against branch history" if EXPERT > > + default y > > + depends on HARDEN_BRANCH_PREDICTOR || !KVM > > + help > > + Speculation attacks against some high-performance processors can > > + make use of branch history to influence future speculation. > > + When taking an exception from user-space, a sequence of branches > > + or a firmware call overwrites the branch history. > > The build problem reported here[]0 is due to enabling CONFIG_EXPERT, and disabling > CONFIG_HARDEN_BRANCH_PREDICTOR and CONFIG_MITIGATE_SPECTRE_BRANCH_HISTORY: The harden_bp > stuff uses #ifdef all over the place, whereas the BHB bits use IS_ENABLED(). As there are > dependencies between the two, mixing them doesn't go well. > > The fix is a little noisy. The reason is the 'matches' support ought to be kept even if > the feature is disabled so that the sysfs files still report Vulnerable on affected > hardware, regardless of the Kconfig. > > ------------------------>%------------------------ > diff --git a/arch/arm64/kernel/cpu_errata.c b/arch/arm64/kernel/cpu_errata.c > index d6bc44a7d471..ae364d6b37ac 100644 > --- a/arch/arm64/kernel/cpu_errata.c > +++ b/arch/arm64/kernel/cpu_errata.c > @@ -561,7 +561,9 @@ const struct arm64_cpu_capabilities arm64_errata[] = { > .type = ARM64_CPUCAP_LOCAL_CPU_ERRATUM, > .capability = ARM64_SPECTRE_BHB, > .matches = is_spectre_bhb_affected, > +#ifdef CONFIG_MITIGATE_SPECTRE_BRANCH_HISTORY > .cpu_enable = spectre_bhb_enable_mitigation, > +#endif > }, > { > } > @@ -571,8 +573,8 @@ const struct arm64_cpu_capabilities arm64_errata[] = { > * We try to ensure that the mitigation state can never change as the result of > * onlining a late CPU. > */ > -static void update_mitigation_state(enum mitigation_state *oldp, > - enum mitigation_state new) > +static void __maybe_unused update_mitigation_state(enum mitigation_state *oldp, > + enum mitigation_state new) > { > enum mitigation_state state; > > @@ -708,7 +710,7 @@ static bool is_spectre_bhb_fw_affected(int scope) > return false; > } > > -static bool supports_ecbhb(int scope) > +static bool __maybe_unused supports_ecbhb(int scope) > { > u64 mmfr1; > > @@ -738,6 +740,7 @@ bool is_spectre_bhb_affected(const struct arm64_cpu_capabilities *entry, > return false; > } > > +#ifdef CONFIG_HARDEN_BRANCH_PREDICTOR > static void this_cpu_set_vectors(enum arm64_bp_harden_el1_vectors slot) > { > const char *v = arm64_get_bp_hardening_vector(slot); > @@ -812,7 +815,7 @@ static void kvm_setup_bhb_slot(const char *hyp_vecs_start) > #define __spectre_bhb_loop_k32_start NULL > > static void kvm_setup_bhb_slot(const char *hyp_vecs_start) { }; > -#endif > +#endif /* CONFIG_KVM */ > > static bool is_spectrev2_safe(void) > { > @@ -891,3 +894,4 @@ void __init spectre_bhb_patch_loop_iter(struct alt_instr *alt, > AARCH64_INSN_MOVEWIDE_ZERO); > *updptr++ = cpu_to_le32(insn); > } > +#endif /* CONFIG_HARDEN_BRANCH_PREDICTOR */ > ------------------------>%------------------------ > > > This version of the backport isn't affected by Will's report here: > https://lore.kernel.org/linux-arm-kernel/20220408120041.GB27685@willie-the-truck/ > as Kconfig describes that dependency as it was too hard to unpick with the helpers v4.9 has. Thanks for the fixup, now applied, and it passes my local testing here with the failed configuration. I'll push out a release and see if it breaks anyone :) greg k-h