Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp1408716pxp; Thu, 17 Mar 2022 08:48:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwFSUeh1S0aqPG0DjT7ZzhvwW312g+mP2r3y24aqeFPAaOHST6aRzTKa01u+AEzUpEpSnYX X-Received: by 2002:a17:907:97c9:b0:6db:ab53:1fdf with SMTP id js9-20020a17090797c900b006dbab531fdfmr5169515ejc.406.1647532102012; Thu, 17 Mar 2022 08:48:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647532102; cv=none; d=google.com; s=arc-20160816; b=Mzf1K+gc3jFsd0IqwBy0MTyLrrNyXNUI7Vg3PHsEmtw88MJhIzsAaSM1uppiVrWx9h lRk9lmyNcP5g/IUoZ4dbNNzCS8yHkuge9Aft09rI1htSto+ZHSZuOS8uLermHWHBlfbW gzujBdj5vtuHI4JIatCLDZDEWNl1DLWnWUQ07Chg+ijQQfZ30d40Xi+60CNg1eGzmlOV 7P1kZb5Ou0rMnGgdnFKnwZOhVVfJ0xraYlt7ApLC/eGdJ09D9Fm+zaSQr+j0qkKY9HC5 cRCaOoKMMT2E31S9+11Zd+20eCETgcoft4qisrUGI0La8F5/fT8X86gObYZU27xSxoqa JJVw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Lcl25YHOGImPHIEWlyGl+QmZrgquyn2iisRWuUoqNvk=; b=IGCgpAJoIYsgKA7TaxKc3wdWPPALED4IPfeW6ULFZWvxPs+8nYk6luf/k4kvp2a4+r vEKXdLbrNeZwhV2THaIqkXeNvwxoiR1gmDN/xb64DbO0nQ5UumuH7v9/LTtqDzPM9YEn VHaAIbgH908oGpOBH6Sjn9WZwTrPIeolTXDixBiCn1lY7oS8vNVZfLhrjhTPAJliCheL pzZ7BxRgT2MEA0GslzBOmQnItWzeCkf8akRqmeJQ7XLotmSPdlKeQ2ztN00vg3M+VzC6 JFFC1Cej18JvYomwNLc0VZ8Jiiivf8jl5beyvaP7ZLGepK0HMz1EHKT7mWYLlzo91PjZ DQ2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=tVE+Giqf; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 1-20020a170906318100b006ae720209a5si3243449ejy.969.2022.03.17.08.47.56; Thu, 17 Mar 2022 08:48:21 -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=@linuxfoundation.org header.s=korg header.b=tVE+Giqf; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233755AbiCQMso (ORCPT + 99 others); Thu, 17 Mar 2022 08:48:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36518 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233787AbiCQMsh (ORCPT ); Thu, 17 Mar 2022 08:48:37 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3F6D51EE8EA; Thu, 17 Mar 2022 05:47:19 -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 sin.source.kernel.org (Postfix) with ESMTPS id EE431CE233E; Thu, 17 Mar 2022 12:47:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EAF14C340E9; Thu, 17 Mar 2022 12:47:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1647521236; bh=AETHo1UQ7hEY1aEu3XgN73Gbf+X406akpzbOfR5AL3g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tVE+Giqfbza8ESm2it740QXcH+zU0JeWYjNflZ7Gq8KvkfKj2AHQ3wOES/ini0dkI Sf3vLGRJsEkrQtAmZ0QjWg+Gi3kTYzLjnWNqwWNrroW/4t5axEQ6/BrYZDchs7M2b5 6PptQXkQFBP3aDdyDGunsqj2qhRJTmUtC8jqCYfU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Catalin Marinas , James Morse , Sasha Levin Subject: [PATCH 5.4 20/43] arm64: proton-pack: Report Spectre-BHB vulnerabilities as part of Spectre-v2 Date: Thu, 17 Mar 2022 13:45:31 +0100 Message-Id: <20220317124528.233620716@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220317124527.672236844@linuxfoundation.org> References: <20220317124527.672236844@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-8.6 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: James Morse commit dee435be76f4117410bbd90573a881fd33488f37 upstream. Speculation attacks against some high-performance processors can make use of branch history to influence future speculation as part of a spectre-v2 attack. This is not mitigated by CSV2, meaning CPUs that previously reported 'Not affected' are now moderately mitigated by CSV2. Update the value in /sys/devices/system/cpu/vulnerabilities/spectre_v2 to also show the state of the BHB mitigation. Reviewed-by: Catalin Marinas [ code move to cpu_errata.c for backport ] Signed-off-by: James Morse Signed-off-by: Sasha Levin --- arch/arm64/include/asm/cpufeature.h | 9 +++++++ arch/arm64/kernel/cpu_errata.c | 41 ++++++++++++++++++++++++++--- 2 files changed, 46 insertions(+), 4 deletions(-) diff --git a/arch/arm64/include/asm/cpufeature.h b/arch/arm64/include/asm/cpufeature.h index ccae05da98a7..a798443ed76f 100644 --- a/arch/arm64/include/asm/cpufeature.h +++ b/arch/arm64/include/asm/cpufeature.h @@ -639,6 +639,15 @@ static inline int arm64_get_ssbd_state(void) void arm64_set_ssbd_mitigation(bool state); +/* Watch out, ordering is important here. */ +enum mitigation_state { + SPECTRE_UNAFFECTED, + SPECTRE_MITIGATED, + SPECTRE_VULNERABLE, +}; + +enum mitigation_state arm64_get_spectre_bhb_state(void); + extern int do_emulate_mrs(struct pt_regs *regs, u32 sys_reg, u32 rt); static inline u32 id_aa64mmfr0_parange_to_phys_shift(int parange) diff --git a/arch/arm64/kernel/cpu_errata.c b/arch/arm64/kernel/cpu_errata.c index 1e16c4e00e77..182305000de3 100644 --- a/arch/arm64/kernel/cpu_errata.c +++ b/arch/arm64/kernel/cpu_errata.c @@ -989,15 +989,41 @@ ssize_t cpu_show_spectre_v1(struct device *dev, struct device_attribute *attr, return sprintf(buf, "Mitigation: __user pointer sanitization\n"); } +static const char *get_bhb_affected_string(enum mitigation_state bhb_state) +{ + switch (bhb_state) { + case SPECTRE_UNAFFECTED: + return ""; + default: + case SPECTRE_VULNERABLE: + return ", but not BHB"; + case SPECTRE_MITIGATED: + return ", BHB"; + } +} + ssize_t cpu_show_spectre_v2(struct device *dev, struct device_attribute *attr, char *buf) { + enum mitigation_state bhb_state = arm64_get_spectre_bhb_state(); + const char *bhb_str = get_bhb_affected_string(bhb_state); + const char *v2_str = "Branch predictor hardening"; + switch (get_spectre_v2_workaround_state()) { case ARM64_BP_HARDEN_NOT_REQUIRED: - return sprintf(buf, "Not affected\n"); - case ARM64_BP_HARDEN_WA_NEEDED: - return sprintf(buf, "Mitigation: Branch predictor hardening\n"); - case ARM64_BP_HARDEN_UNKNOWN: + if (bhb_state == SPECTRE_UNAFFECTED) + return sprintf(buf, "Not affected\n"); + + /* + * Platforms affected by Spectre-BHB can't report + * "Not affected" for Spectre-v2. + */ + v2_str = "CSV2"; + fallthrough; + case ARM64_BP_HARDEN_WA_NEEDED: + return sprintf(buf, "Mitigation: %s%s\n", v2_str, bhb_str); + case ARM64_BP_HARDEN_UNKNOWN: + fallthrough; default: return sprintf(buf, "Vulnerable\n"); } @@ -1019,3 +1045,10 @@ ssize_t cpu_show_spec_store_bypass(struct device *dev, return sprintf(buf, "Vulnerable\n"); } + +static enum mitigation_state spectre_bhb_state; + +enum mitigation_state arm64_get_spectre_bhb_state(void) +{ + return spectre_bhb_state; +} -- 2.34.1