Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp28706pxp; Thu, 10 Mar 2022 21:35:13 -0800 (PST) X-Google-Smtp-Source: ABdhPJzgLmbb+76wIhpu5VrWgnB7nWXINKIxqKd+k7rByEaOgG/Mlgd4ZLnP006dEXfUOPFpDcth X-Received: by 2002:aa7:c58c:0:b0:415:9ed3:1a59 with SMTP id g12-20020aa7c58c000000b004159ed31a59mr7350274edq.25.1646976912956; Thu, 10 Mar 2022 21:35:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646976912; cv=none; d=google.com; s=arc-20160816; b=jto+06yslX2HDZ2K9V/PCZbcvwtsznQiGynpnD3D7Y5FdlAxwmh6tVKxtOV8Pd3qzd ydVzBh/aqT+GMyobeYjPi6wKy7JrP/G1tjdnxVApXrU7S/KGKIFGtw31CWKojVNBc+xh Yu4LO/Osny5KXgOE5ckLio0EqXhhu9hrLmd1/KLaUKZ2mWIvhKhSYEBEs1q90cVPiIaN 5nNNqTEWWT1G0U62JJVLROoUPmLuJC7u9x0Y/0yGXnN1C+wJZxM/9Xlh3fcvBsfLINhF VTT6dM6YcwYs7vfZj9NvPHHkljhvw6bLcnUDcNsGLbT5C7ICID/zaZWzDEpAzvD368cy lR3g== 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=X6QvbEmzPFKuLiYmKywaW1H/wiljp2wuTdP4zTeXxlE=; b=0eVpj1UI+kdXQsDCUCueMnG7OvqMsGW0XCg2t0Ev2tO0SXwSMLq84z8VN+t8jHG3Vl xpH02IuJv7MwoazsZsxvGv3zbIc3kqKMyHXPJGkIBsSvJOiky11pHFI9PYkOnt3t0Q0F f7kTbQ+ksP23g/jp5tmTDKzhik7gzhFGMkdybPT5h7Nrx/Z8c3RXjnFwl7xRlu9Ey4XK mTOoSPTBlqP608NTs9Bw/0ZhTiqTYEkPCxmvPwTEIMaEo04BmvnP/01LYtm9YFbqUn2t y5k9W7vgnsqurkuEg3L+udr3x1kVLlviqQB8yszQZVhHxKDXSWvBSH4t1V7LnXQLxEoQ tGTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=um3kwZCS; 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 go37-20020a1709070da500b006dafff034eesi5100201ejc.283.2022.03.10.21.34.21; Thu, 10 Mar 2022 21:35:12 -0800 (PST) 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=um3kwZCS; 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 S243048AbiCJOPC (ORCPT + 99 others); Thu, 10 Mar 2022 09:15:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49598 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243037AbiCJOOJ (ORCPT ); Thu, 10 Mar 2022 09:14:09 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7799B1587B8; Thu, 10 Mar 2022 06:11:47 -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 dfw.source.kernel.org (Postfix) with ESMTPS id AB17E61B7A; Thu, 10 Mar 2022 14:11:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A3BC1C340E8; Thu, 10 Mar 2022 14:11:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1646921495; bh=O7bwEJKYJXRVJIDfJwdzLbTR7ZgsTiITRhcn192SuLw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=um3kwZCSE54ejEjsQSQb22hryMmiGO/MWb7ekPR0aTid43zqNwZidaGMVo4E3OajT vrUu5HAhfHz4nwrS4szu1nNZ4geeJ2VRw9Zg4GEQvKI2pF30SsCmICpdDns2bnsAwy 30AVoELWqDDyWGGs6Bh7sl3r9VplBifkAqbD8nQs= 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.16 32/53] arm64: proton-pack: Report Spectre-BHB vulnerabilities as part of Spectre-v2 Date: Thu, 10 Mar 2022 15:09:37 +0100 Message-Id: <20220310140812.757862740@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220310140811.832630727@linuxfoundation.org> References: <20220310140811.832630727@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=-7.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 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 @@ -93,5 +93,7 @@ void spectre_v4_enable_task_mitigation(s enum mitigation_state arm64_get_meltdown_state(void); +enum mitigation_state arm64_get_spectre_bhb_state(void); + #endif /* __ASSEMBLY__ */ #endif /* __ASM_SPECTRE_H */ --- a/arch/arm64/kernel/proton-pack.c +++ b/arch/arm64/kernel/proton-pack.c @@ -96,14 +96,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: @@ -771,6 +796,13 @@ int arch_prctl_spec_ctrl_get(struct task } } +static enum mitigation_state spectre_bhb_state; + +enum mitigation_state arm64_get_spectre_bhb_state(void) +{ + return spectre_bhb_state; +} + /* Patched to NOP when enabled */ void noinstr spectre_bhb_patch_loop_mitigation_enable(struct alt_instr *alt, __le32 *origptr,