From patchwork Tue Oct 8 15:39:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 175513 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp5864538ill; Tue, 8 Oct 2019 08:40:29 -0700 (PDT) X-Google-Smtp-Source: APXvYqyH5wSsAnx2T8/9Ygjr+nqDu4SDhMzqfbK4hJN0zpJ4mmAtah48ZF0zoJ0wWaOemDtEsZN2 X-Received: by 2002:a17:906:cc9b:: with SMTP id oq27mr29408672ejb.125.1570549228919; Tue, 08 Oct 2019 08:40:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570549228; cv=none; d=google.com; s=arc-20160816; b=Jo+2y63SPIJlxnqyE5nswn6p9PeZsNhcLE4q4t/QfY7a9NR5ggGVwRPIvEXkOxTcj+ u/pMq4wzwZ0F/f7Qa7R6oDp1ZoPLabxdRSeZYWo/dVIrR6hUNfYF4hPdFAGy69k/U1iu qGWvHEkNJ0GrMBFiyZroVWpWDrU2aCD3XFBezRliMBmgITUzm6+caQJFWzRU26GxjTJM v/1HX6XDjFm2QYrhChCIRyvrS45iv9vE2hAkEoXBX7/zXfEOpe6dJRSX9lgbuiaMiyOV dm0UuqMhYowqh5Xl8JKJDQBkfMD8UbEl80pZ9q8neqcBglKtvuL4YjRm335pZ+ZxBbJb 6ITg== 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=xVW9YVfjij9vCoDvPQUdIJ4SaHECQBvveZX1DwTyL70=; b=J63mrLuMrqOAxDLrAFEkm7yh33rhfEybTYw7mG1dvYYC2aJpZ2YEru7hf4cVefsrNw 2e/FiDRYto2kbDh2ZHYMSQJw2ovE9TGN3ekpxusXN6ly/5yONRcWUPo1VWMHUA5/hXxO IBcJj4CqjsWbdLckc1GuUscUJsgd//dyCJB4+SaEruXIXLT1iPwdV4kKyERQfk0IHOCU g23aU6qREbqlrc07dA7Xi7bpAVdnRONtl3Fw/D744uKHJCePZ2/c3Ntmw/sq+ptkYEjO 4o5VuWGAZTVBbPtPZ/KU5zA9h3aHGxBi6F1iNSD4HS/8bVBDG3AyIHTkEEyI7/V/S0TL FcoQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CkH3V+Bg; 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 l6si10919464edc.67.2019.10.08.08.40.28; Tue, 08 Oct 2019 08:40:28 -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=CkH3V+Bg; 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 S1728185AbfJHPk2 (ORCPT + 13 others); Tue, 8 Oct 2019 11:40:28 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:46729 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728132AbfJHPk2 (ORCPT ); Tue, 8 Oct 2019 11:40:28 -0400 Received: by mail-wr1-f68.google.com with SMTP id o18so19926564wrv.13 for ; Tue, 08 Oct 2019 08:40:26 -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=xVW9YVfjij9vCoDvPQUdIJ4SaHECQBvveZX1DwTyL70=; b=CkH3V+Bg52IIiejwB7MJHrut8r0ZNm/pGILs03lNlE/a/HfmcdZspkl0VlLvPve04Z rFjR4bEabYl6kAu3KdPXO3SMd9wGbj8wnvGhpicK2sxxyu0cBi5Wcr9QFs2uaRmx5Gtn /Xu+1Le5EZmEZIrb80P3rhiAB+73kHsnCsfrO5wJQmfpe/WxaLxFz4gm94RwlGCjQkfL yhPCi2wQtSHA0uQ3UXcJyHASuZv8P4mnAb5DNXSKLaNRCohQFf4uCWKrul1znbjNqjQF lTjEK5b1HzS52S2OuNQJOUGgw87xRKyuZ7R7IxwixKcUg42UQgG/F1ZpXwARnPKkrqbj XU2Q== 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=xVW9YVfjij9vCoDvPQUdIJ4SaHECQBvveZX1DwTyL70=; b=rDs19DCOBzx4hF9if/4eeZK+JpFQwsMz4Z1yql2XzCeQ4BXi+EQcH+29sLmp7Gnbrw mLYs1q2QFKLK7y9ncWkqQ2ZV0E1nVxdBFE1E5E8VAsIaJ/M0HIjEnwxiJuEmldJ6zvWU JcqKiKg9f16VU280Po6KvYFJki2kd6lN5CLGNVZ4sfoz4G4SNDmSzVlEOfjLL2PBwjet Kiaf+n+h7XbWxPT79dYMCdTwjwxJ754J76HQo4sRsQwX+64Av+/KA+7nyeHLHXZSbZvG ZDPG+eq8rE8cFk8qkzx5jGqvG7gklN1RrKlkETPp1HVwZRmqMjmZrhubnopbzecgo7lJ z0uw== X-Gm-Message-State: APjAAAWdljhzGq+anlFouBncPfE4mSlmzPwjewpjAO6K508CzoAKtrk8 Jguia7LtmyRgTI/ltjrzpK5qCappVPCBuA== X-Received: by 2002:a5d:4043:: with SMTP id w3mr28849130wrp.318.1570549226179; Tue, 08 Oct 2019 08:40:26 -0700 (PDT) Received: from localhost.localdomain (laubervilliers-657-1-83-120.w92-154.abo.wanadoo.fr. [92.154.90.120]) by smtp.gmail.com with ESMTPSA id x16sm16784723wrl.32.2019.10.08.08.40.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Oct 2019 08:40:25 -0700 (PDT) From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Cc: stable@vger.kernel.org, Jeremy Linton , Andre Przywara , Catalin Marinas , Stefan Wahren , Will Deacon , Ard Biesheuvel Subject: [PATCH for-stable-v4.19 13/16] arm64: add sysfs vulnerability show for spectre-v2 Date: Tue, 8 Oct 2019 17:39:27 +0200 Message-Id: <20191008153930.15386-14-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191008153930.15386-1-ard.biesheuvel@linaro.org> References: <20191008153930.15386-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 96b0319dd0d6..b29d0b3b18b2 100644 --- a/arch/arm64/kernel/cpu_errata.c +++ b/arch/arm64/kernel/cpu_errata.c @@ -480,6 +480,10 @@ has_cortex_a76_erratum_1463225(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; + /* * Generic helper for handling capabilties with multiple (match,enable) pairs * of call backs, sharing the same capability bit. @@ -522,6 +526,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) { @@ -543,6 +551,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; @@ -552,11 +562,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); } @@ -753,3 +766,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"); +}