Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp766320pxp; Fri, 11 Mar 2022 14:33:55 -0800 (PST) X-Google-Smtp-Source: ABdhPJwyZ6hND4Jul46XKZ/Ugp5XkT2lvvS29gEdzssT3n7lW2X6mzUhI2vJoH9CfBS5SOBGScMS X-Received: by 2002:a05:6a00:1349:b0:4f7:68db:5e3a with SMTP id k9-20020a056a00134900b004f768db5e3amr12532971pfu.51.1647038035024; Fri, 11 Mar 2022 14:33:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1647038035; cv=none; d=google.com; s=arc-20160816; b=FldU74imATB8wRkCy6MXV5Y3kQ/z3WQTvDsFyTQk73Z/drzyqZsUEKqkjZBW97+Xbu 3d5fjAzhuaBWD4o76DPwrdS7w6b3x1rnHzDdQDBWRwuTfBubUbZOwzqZI+bs/f83Tn+/ hQEaTUxCGGiZwj9QuXonIsBV3vQFXS8JoOMrUNn6nJApNUaCk09h0Qg6Y6qHwshznPeB u7QtgHMKFlgQkmI9nglokHmSyMiujh9eTuHu5hNrY19CvoWJ16kZL2iS4hV8GMj3k3Ax MnxUsHg3OF26Cfxv1O7dg2RzZxuro2jO/xF5uzMkeStdJKAOQ5f/omOuzqfDfWycvYk5 Mrbg== 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=lkgdQvBaPiXPc0FD338LiU1q3YjzOqMB9FyoozP7hd8=; b=Uncj3Fo9B/z75AwdUQ+8ossnA4rsDRYrwlwLFxwkuLn8xO0gxSpWIPtSj2OdvKpQnH mwmhJpG7qbpV7cGtvNFHUTUCGj/EbdlPUOz5/3QNyN18sNBjfsa0CsM1nfEs8FoWCzu5 q/urxCjJLTPpquZRCeBXLhQJHK07gQp1DJ8l0zOMzofinUMoRu0NYpvnS68Jm0xaxPVF 1VVTxmzTRjvuGnhj6+YwKZ/OHYSNWBDvmBtkhFCBDmOe+OEQKhhT6YBvKfPVQfChGKoT J9gUmiNKPkOzkV1jRxtv9/x+UDC8tQt3z8dGBS/rcONhd073PIEkBnHdOVQ2pErQVc5K Buig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=hB2xNvgD; 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 m194-20020a633fcb000000b00373bd6fea4asi8725905pga.797.2022.03.11.14.33.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Mar 2022 14:33:55 -0800 (PST) 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=hB2xNvgD; 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 64A04277690; Fri, 11 Mar 2022 13:40:39 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345020AbiCJOl3 (ORCPT + 99 others); Thu, 10 Mar 2022 09:41:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50106 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245233AbiCJOaQ (ORCPT ); Thu, 10 Mar 2022 09:30:16 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C9EC91704D0; Thu, 10 Mar 2022 06:25:44 -0800 (PST) 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 D0638B82676; Thu, 10 Mar 2022 14:25:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4080FC340F5; Thu, 10 Mar 2022 14:25:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1646922311; bh=RqzeAQhcKiZiQ5wOPHZeqLujTq7UN4gy/nboCZyWHbg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hB2xNvgDCpTrumpjhINTKNtDYM0hJVXoKHUJc+ukIVVUrGH39yche5RNf4lfDteAJ T1JBo944bcTT4SW5uylgyEVCzFMJrKU4j/MeWuSXqNUx8WhKBYqUxDbeVg7AD962Og 52kZBwnx8/URmJeoOLrT8q2U7g35WlvIJmESQTTg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Catalin Marinas , James Morse Subject: [PATCH 5.10 37/58] arm64: proton-pack: Report Spectre-BHB vulnerabilities as part of Spectre-v2 Date: Thu, 10 Mar 2022 15:18:57 +0100 Message-Id: <20220310140813.928124989@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220310140812.869208747@linuxfoundation.org> References: <20220310140812.869208747@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=-2.4 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=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 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 Signed-off-by: James Morse Signed-off-by: Greg Kroah-Hartman --- arch/arm64/include/asm/spectre.h | 2 ++ arch/arm64/kernel/proton-pack.c | 36 ++++++++++++++++++++++++++++++++++-- 2 files changed, 36 insertions(+), 2 deletions(-) --- a/arch/arm64/include/asm/spectre.h +++ b/arch/arm64/include/asm/spectre.h @@ -29,4 +29,6 @@ bool has_spectre_v4(const struct arm64_c void spectre_v4_enable_mitigation(const struct arm64_cpu_capabilities *__unused); void spectre_v4_enable_task_mitigation(struct task_struct *tsk); +enum mitigation_state arm64_get_spectre_bhb_state(void); + #endif /* __ASM_SPECTRE_H */ --- a/arch/arm64/kernel/proton-pack.c +++ b/arch/arm64/kernel/proton-pack.c @@ -94,14 +94,39 @@ static bool spectre_v2_mitigations_off(v return ret; } +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 (spectre_v2_state) { case SPECTRE_UNAFFECTED: - return sprintf(buf, "Not affected\n"); + 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 SPECTRE_MITIGATED: - return sprintf(buf, "Mitigation: Branch predictor hardening\n"); + return sprintf(buf, "Mitigation: %s%s\n", v2_str, bhb_str); case SPECTRE_VULNERABLE: fallthrough; default: @@ -787,3 +812,10 @@ int arch_prctl_spec_ctrl_get(struct task return -ENODEV; } } + +static enum mitigation_state spectre_bhb_state; + +enum mitigation_state arm64_get_spectre_bhb_state(void) +{ + return spectre_bhb_state; +}