Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp1818856pxb; Sat, 2 Apr 2022 04:54:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx9bdD/D7Dzd7tg8JWhiwhnqJKz8zwrNSPfKUIldwcyozLwPFbs1VwqLdX/yUjuhApZKjNC X-Received: by 2002:a17:907:7f0f:b0:6e4:c15e:7751 with SMTP id qf15-20020a1709077f0f00b006e4c15e7751mr3623848ejc.266.1648900443527; Sat, 02 Apr 2022 04:54:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648900443; cv=none; d=google.com; s=arc-20160816; b=IB5XMck6hrEZWz9TBjc+S5cEp3ORtO1xa4ZractmOpyKkpxaNY2UcbzMJMzmUwVqcq m+vCkpE19LbznBx7hBiPtujldXQkiG+9jQs3YDKxhyHxMDf6KDkjzppiZoDcW7Pkf6cw attq4lh6tUV4/nIy3TpUphDJyyNYDbSkCRJ28CQLQXbSY27zznZy7fxOiQ1agmoz6+R+ rsOaRophM1nqKjj+7iunEoCoQd3UGIlU8c8k6Rj00mqUtRjm8FgGNAvUXqmGEAJlp6CD B2axQYKQvdcoaNt/tl+eVEBywjPxSDhI5FcdfXBf65T37kBe5vz5kzB639BJkA5ZC5A5 j/rA== 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=gXIQe58IfxpXTeCMXGftdjS3MKM7ikO6Yb8hsR6Q56M=; b=touEa7KqYBGLdoRe/VfOfT2a27PAsNAxymvtflQoyafrGOy7CObJQMc1ISRKR8SCKV L/CiYvNe8ueVt/QSL6G1ACv3Xp9WQ3L61kif3bsMKgDc9hjv2Hdr/NV+o5z2QL5D4RNB DpSycWGPgb14xnWUpII2G9/XMBXmVEuBqU5bBtG71WXfQdFzWR1BVE96B9RTClcA1wMr ydFH6WaD1cYdq5/kOOqmcSAmtGXEtDwH4hRXykLi6wvR16oF7+I6DwWIDGmExymFxph5 8vKxQSbfyeuscxfqqGBI6Y7C2CIuWfvQ5x+rZYg4lpDi7wldcfhvuM01zlnAx0yrnJCc /mjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=1d0ytcSX; 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 g1-20020a50e041000000b00418c2b5becbsi3303902edl.429.2022.04.02.04.53.31; Sat, 02 Apr 2022 04:54:03 -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=1d0ytcSX; 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 S245567AbiDAGkY (ORCPT + 99 others); Fri, 1 Apr 2022 02:40:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46214 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245611AbiDAGjg (ORCPT ); Fri, 1 Apr 2022 02:39:36 -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 F3288264811; Thu, 31 Mar 2022 23:37: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 ams.source.kernel.org (Postfix) with ESMTPS id 4749AB823E8; Fri, 1 Apr 2022 06:37:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B3527C340EE; Fri, 1 Apr 2022 06:37:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1648795040; bh=ozyQ2xQiU42aoCVatxu5Lv/+CjIAA8xu/x5KnPLdbr8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1d0ytcSX0Y1Zql2p2IXnCDYUi4lmH5ioWVzxfLLCXkO6YjdTCwQ/s9nlvyvMtRZNT V4ejl3FouwIp22rB6ppqCcVkIpC/C9iGb00yfzansnPoBNkhtL1mJ/oDRugLqyoPRJ jv5aY501nFeKaz4ZBrg5XCo4PGLIU/xleuRqOPpA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Catalin Marinas , James Morse Subject: [PATCH 4.14 22/27] arm64: proton-pack: Report Spectre-BHB vulnerabilities as part of Spectre-v2 Date: Fri, 1 Apr 2022 08:36:32 +0200 Message-Id: <20220401063624.860794754@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220401063624.232282121@linuxfoundation.org> References: <20220401063624.232282121@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.1 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: Greg Kroah-Hartman --- arch/arm64/include/asm/cpufeature.h | 8 +++++++ arch/arm64/kernel/cpu_errata.c | 38 +++++++++++++++++++++++++++++++++--- 2 files changed, 43 insertions(+), 3 deletions(-) --- a/arch/arm64/include/asm/cpufeature.h +++ b/arch/arm64/include/asm/cpufeature.h @@ -495,6 +495,14 @@ static inline int arm64_get_ssbd_state(v 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); #endif /* __ASSEMBLY__ */ #endif --- a/arch/arm64/kernel/cpu_errata.c +++ b/arch/arm64/kernel/cpu_errata.c @@ -730,14 +730,39 @@ ssize_t cpu_show_spectre_v1(struct devic 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) { - if (__spectrev2_safe) - return sprintf(buf, "Not affected\n"); + 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"; + + if (__spectrev2_safe) { + 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"; + } if (__hardenbp_enab) - return sprintf(buf, "Mitigation: Branch predictor hardening\n"); + return sprintf(buf, "Mitigation: %s%s\n", v2_str, bhb_str); return sprintf(buf, "Vulnerable\n"); } @@ -758,3 +783,10 @@ ssize_t cpu_show_spec_store_bypass(struc 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; +}