From patchwork Thu Oct 10 08:36:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 175722 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp1983672ill; Thu, 10 Oct 2019 01:48:46 -0700 (PDT) X-Google-Smtp-Source: APXvYqyWeVUDXh9GLe5SyL7QSSrn/y6XcbUj9SJ4blX8JMKvIeAsjMggo7MZTu0ypJ6Lq3DbBtuU X-Received: by 2002:a17:906:d29a:: with SMTP id ay26mr7001790ejb.21.1570697326623; Thu, 10 Oct 2019 01:48:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570697326; cv=none; d=google.com; s=arc-20160816; b=mu9SVHv+3/PK2wFQ2DExAFcjQbEl9TwvccPjlPVYSEGiAZlPCDwu7xqKV7dvSL03vz akumN/kY8nUfpveBDKFfQk639eSFZWmpFFpsCs/TZmmbX36Cwxk2z+0qZZUic0HvL/uY G5SwmvXPlc0AtYbyTHQ15Q/fn6w/j/elBpSNwHGwQVdV5UiFWFvmIElIVSTceV2O7nux rTL/EQ2el6O3jYJyVkBxDDRb/Imys5r+hw5LXWHDEFpjBlTgagdvUqESDxbeBnBazkpf RFAYT2wBHLoFtXFO0Pt+Z3OFfFO5nVVNz75t7BnJao6RRCp/T8Av+wuWDTD0mS0FLRWm s7jA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Ig55dqOQyI+1xR+g16mymG0mITKpRtWUSWiqYJnb3cM=; b=bIGyWCUZLeDWEDwzuroZqX48vKAIYpPsEqH9XffYBjTRwU7gkUwBiBrv2l2q4L7VGN Z92Ity9CXViCAOhN8bNtEW7moZIOnkmyEt/tGZrfxC/I0EXnGCSwsM2787OvJ6oX0stm Kj1ZLO1ladEs86zsOfnhtkh0RElj5CsOkR9YVI1kHJGiwmEXfTySg9FGMQAC/Gang3SM 10pN7Zl8wvL2rmT4tWTObZdHqeYrnTV2CVM0a/sLD/c2i2SGSdhNTzEGUb6VIFC5i5qx I3pdPAKTvqz+upp58d6uKwIfck3bQPRIkGAAXMBO+fp3SmLEv7n1N/9hXVyoBgYMBXNn QSDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="siq/iEVa"; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z9si3135090edz.77.2019.10.10.01.48.46; Thu, 10 Oct 2019 01:48:46 -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=@kernel.org header.s=default header.b="siq/iEVa"; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389686AbfJJIsn (ORCPT + 13 others); Thu, 10 Oct 2019 04:48:43 -0400 Received: from mail.kernel.org ([198.145.29.99]:54970 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389157AbfJJIsm (ORCPT ); Thu, 10 Oct 2019 04:48:42 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B833121929; Thu, 10 Oct 2019 08:48:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570697321; bh=IyVvloWswiwb0rHjj5ssPaCzfOBHQsDBo6CZ5n2dG7o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=siq/iEVaQlSVNtjn/p3JBKEpbkKzNDmrrbS7Dr4V1H7jjz8KRLH4VupRd166e8NFu Vwb73Y4t4AicllntYTo4FFd15md9UrqbGoHVjsb4/D99gUkNfK1Lf9rcs5a++o0PNI MqBk/LxYP9i3uN1NrsznUHgYLT6pOprpY7G/ahxs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jeremy Linton , Andre Przywara , Catalin Marinas , Stefan Wahren , Will Deacon , Ard Biesheuvel Subject: [PATCH 4.19 100/114] arm64: add sysfs vulnerability show for spectre-v2 Date: Thu, 10 Oct 2019 10:36:47 +0200 Message-Id: <20191010083613.477591447@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191010083544.711104709@linuxfoundation.org> References: <20191010083544.711104709@linuxfoundation.org> User-Agent: quilt/0.66 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 Signed-off-by: Greg Kroah-Hartman --- arch/arm64/kernel/cpu_errata.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) --- a/arch/arm64/kernel/cpu_errata.c +++ b/arch/arm64/kernel/cpu_errata.c @@ -480,6 +480,10 @@ has_cortex_a76_erratum_1463225(const str .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_v { /* 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 arm6 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 arm6 /* 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 devic { 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"); +}