From patchwork Thu Oct 24 12:48:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 177464 Delivered-To: patch@linaro.org Received: by 2002:a92:409a:0:0:0:0:0 with SMTP id d26csp2143154ill; Thu, 24 Oct 2019 05:49:59 -0700 (PDT) X-Google-Smtp-Source: APXvYqwgFIo14RMFB7MyrWgL6qfcFzyMxAVZwlSdpBHHTxNNq6WQnlLNQZgVl3PobvuZGZ4fWdvp X-Received: by 2002:a17:906:c289:: with SMTP id r9mr21349892ejz.311.1571921399458; Thu, 24 Oct 2019 05:49:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571921399; cv=none; d=google.com; s=arc-20160816; b=inCDgMI9Zzemzet3mHk7kuqekLwVizn6TYF+SGjCgwZ0bRSRinx1qIGKF/GMSB3H/j dKeO5JsVIZ8mrK9rhJyL4S4qbF6MjRKHC/mROdnpNfRvotFatKeEdvHsC49XM5GcnnWK t0N/sMfh8t3ATbhivpV76tOTRmkqKRoZ4TOOqvHrEQIv2c1OHLK63morZGdE6MfxiEbh qVEZrmJ+Uo5SH9CJ7jUNAUpFYWz74+Gx94k5DrXt03pz/Q/MvHyeSIp5dUVOwNmBZhPa vHpAGP1evvsQMEUUjfni675+1H4eZE1z+T3IDUshLCM80JPyT9iRjTuteGOXcPMbPS1R RsYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=g2Zsqrc//i/JLADDP/HYxz1nyRfqYR6RzPTnN2UOUgM=; b=fg2MYv8PdswsMgdmAO0nlIIC8/gioJPacma3kCLibeIi9v08r1xYoaWmUlsYfVRad+ zOeSQP7GT72hKae2eS0QQIyrXYaR7LuoWS+hEL/wmG9aBSt6A/hY4LyGhZAloHmnIoBy EvWgaOKWoRpY8UUs7H8My1XYgRAQh00/2ji6CcoVAQSv3aZVsqJN/3axc6y6F/PMMcgP 7ztJk4kJsooxRc1GLpvn32UeWKHnrxjLOhR2aLtMCSfnKcZZ1NWK4YKdRskpCr2Yvj2d +/2o9Mf6chQNOikUV1hBSqvafBkaTN3heCZ+vUUgTlium/PA57yV67CBbqbF85BxA7UK hJWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cRVImgZP; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y71si17602216ede.135.2019.10.24.05.49.59; Thu, 24 Oct 2019 05:49:59 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cRVImgZP; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2502143AbfJXMt6 (ORCPT + 14 others); Thu, 24 Oct 2019 08:49:58 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:39921 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2502116AbfJXMt6 (ORCPT ); Thu, 24 Oct 2019 08:49:58 -0400 Received: by mail-wm1-f67.google.com with SMTP id r141so2476574wme.4 for ; Thu, 24 Oct 2019 05:49:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=g2Zsqrc//i/JLADDP/HYxz1nyRfqYR6RzPTnN2UOUgM=; b=cRVImgZPI4cDr+SdYtc+5e0bRLvE06CRbZFetILdxYGAmvffnzY3sI3Um/WXbSRZri c+SMpxJXYVS4YBCq5sDI2DfIbYYSmEVe93RGOwYiv3kgCJLa6P8nntd5Mhgf5qUSn+pQ T3FtfVinO5sqLGt3QxSCbz94Lj+CTWNtI0cAlsdkh7KwNR6AnLoe1EvlTJOt1fkfvmUj VvIyTlEijSuUp+q7CcTwB5EMG0Z7J1lfc6PTHyqwJDYOCaonSrAT6p+QpBBmjJvA7s6S uE/Pfzb4Wia7Xdb+PaI1NCT72t0PLo+Rf3yp47pCimjqjUtqIs//PInE/BUxcEWMTdez 61Xg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=g2Zsqrc//i/JLADDP/HYxz1nyRfqYR6RzPTnN2UOUgM=; b=lCVy1kTcCMxeZjXdgA3+r/vect8y0VyYjefavO6/gnN2ybENHRFWGtL/9OLXOu2/u7 3usQlhKJRPShPs6GYAMc0HmLbxlM40rJHLZUsVvr4bTE5xrg5hl4SAszFn6a4nnk411r Kg3R+cyUOsykbHiwauZ/MPAZWl0KG7sPjiYpp3F7/fyrXULbFrwv4LThu/9bNyNZ7cQZ ngSXcI3BvR1T1xejz8skVhjsqxiN1rp4PkDaGROIoBEW5EaFxOFYlJ28cfVU8E1kigGj 0SAno43bSeKmwm+/bwgNkk1O51ie/cOzJMTl8R9jLO1NJ1SKnLbTLahbLsERMZaTj4mR WDBg== X-Gm-Message-State: APjAAAWSilItT5xPb1azM7chIfybvjOzQTDHSaTNb0NGYan3tsB1hlTF bywJStHFE9y/hSKo+9CEmgU67zO016/3ELxo X-Received: by 2002:a1c:f401:: with SMTP id z1mr4681069wma.66.1571921395897; Thu, 24 Oct 2019 05:49:55 -0700 (PDT) Received: from localhost.localdomain (aaubervilliers-681-1-126-126.w90-88.abo.wanadoo.fr. [90.88.7.126]) by smtp.gmail.com with ESMTPSA id j22sm29111038wrd.41.2019.10.24.05.49.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Oct 2019 05:49:55 -0700 (PDT) From: Ard Biesheuvel To: stable@vger.kernel.org Cc: Ard Biesheuvel , Will Deacon , Catalin Marinas , Marc Zyngier , Mark Rutland , Suzuki K Poulose , Jeremy Linton , Andre Przywara , Alexandru Elisei , Stefan Wahren , Will Deacon Subject: [PATCH for-stable-4.14 43/48] arm64: add sysfs vulnerability show for spectre-v2 Date: Thu, 24 Oct 2019 14:48:28 +0200 Message-Id: <20191024124833.4158-44-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191024124833.4158-1-ard.biesheuvel@linaro.org> References: <20191024124833.4158-1-ard.biesheuvel@linaro.org> MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Jeremy Linton [ Upstream commit d2532e27b5638bb2e2dd52b80b7ea2ec65135377 ] Track whether all the cores in the machine are vulnerable to Spectre-v2, and whether all the vulnerable cores have been mitigated. We then expose this information to userspace via sysfs. Signed-off-by: Jeremy Linton Reviewed-by: Andre Przywara Reviewed-by: Catalin Marinas Tested-by: Stefan Wahren Signed-off-by: Will Deacon Signed-off-by: Ard Biesheuvel --- arch/arm64/kernel/cpu_errata.c | 27 +++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) -- 2.20.1 diff --git a/arch/arm64/kernel/cpu_errata.c b/arch/arm64/kernel/cpu_errata.c index 647c533cfd90..809a736f38a9 100644 --- a/arch/arm64/kernel/cpu_errata.c +++ b/arch/arm64/kernel/cpu_errata.c @@ -456,6 +456,10 @@ static bool has_ssbd_mitigation(const struct arm64_cpu_capabilities *entry, .type = ARM64_CPUCAP_LOCAL_CPU_ERRATUM, \ CAP_MIDR_RANGE_LIST(midr_list) +/* Track overall mitigation state. We are only mitigated if all cores are ok */ +static bool __hardenbp_enab = true; +static bool __spectrev2_safe = true; + /* * List of CPUs that do not need any Spectre-v2 mitigation at all. */ @@ -466,6 +470,10 @@ static const struct midr_range spectre_v2_safe_list[] = { { /* sentinel */ } }; +/* + * Track overall bp hardening for all heterogeneous cores in the machine. + * We are only considered "safe" if all booted cores are known safe. + */ static bool __maybe_unused check_branch_predictor(const struct arm64_cpu_capabilities *entry, int scope) { @@ -487,6 +495,8 @@ check_branch_predictor(const struct arm64_cpu_capabilities *entry, int scope) if (!need_wa) return false; + __spectrev2_safe = false; + if (!IS_ENABLED(CONFIG_HARDEN_BRANCH_PREDICTOR)) { pr_warn_once("spectrev2 mitigation disabled by kernel configuration\n"); __hardenbp_enab = false; @@ -496,11 +506,14 @@ check_branch_predictor(const struct arm64_cpu_capabilities *entry, int scope) /* forced off */ if (__nospectre_v2) { pr_info_once("spectrev2 mitigation disabled by command line option\n"); + __hardenbp_enab = false; return false; } - if (need_wa < 0) + if (need_wa < 0) { pr_warn_once("ARM_SMCCC_ARCH_WORKAROUND_1 missing from firmware\n"); + __hardenbp_enab = false; + } return (need_wa > 0); } @@ -663,3 +676,15 @@ ssize_t cpu_show_spectre_v1(struct device *dev, struct device_attribute *attr, { return sprintf(buf, "Mitigation: __user pointer sanitization\n"); } + +ssize_t cpu_show_spectre_v2(struct device *dev, struct device_attribute *attr, + char *buf) +{ + if (__spectrev2_safe) + return sprintf(buf, "Not affected\n"); + + if (__hardenbp_enab) + return sprintf(buf, "Mitigation: Branch predictor hardening\n"); + + return sprintf(buf, "Vulnerable\n"); +}