Received: by 10.223.185.116 with SMTP id b49csp7394611wrg; Thu, 1 Mar 2018 05:00:41 -0800 (PST) X-Google-Smtp-Source: AG47ELs1GvTYzsh8xvVdJJpf/U2+fn2dLgaZHWawOGtNkGijHB8gpK1diBg8X3LBaANNW0g8vtA4 X-Received: by 2002:a17:902:b187:: with SMTP id s7-v6mr1880170plr.448.1519909241718; Thu, 01 Mar 2018 05:00:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519909241; cv=none; d=google.com; s=arc-20160816; b=eeSIKb/4R0DbOzpECFj+qLfqXctYnhYgbg4ggXvKYjENyEwq8gf/BULBq+Qng2B6cP eyoWBlKsRIlbChLT95Y2RaZGHz70T1GclQ9+dRC5VY5IvcYIEqKHYW6CFQsxJPnwoQRf kTVe3Ce9UH5fRlgDVtoTJ9abH01NyvSEq2nrMbU+GY6LSGxgQu7triDdI0pCQPT6BLoD 31WQKlJEY6oZFrDRnkeCSV4p4jylN1py3Lqf4Zk17hzZuoLKknZwlae1yi+xWrnLKeAP K+YfNGtzyKQ6QLj4rymDpByezCRuMSLaoeC0jRsAjAWwyvYLsJPZKfedPvvUwFoK6CCU Y49w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=LVyW4e3/ZiswQxGmhghNNTu5Pe0KH7+4scjkon+J7js=; b=Mg3sR0l1hru91rNhdBxa8BGUNOBG9vsmV1+3xLMgy6KRGcBAWBm8tERC+yEZOYiZA2 5djgmDb0mwxHvv7kxU1xg2n7Zyz+owZvtO2f48zyBSDWxpuFLXA7/Qj+AltPRLJuZsQv FO2reWGssgHufj43SEeJ3BE3hjLRabyakDAUhg/wkyhzzBQUqdsWS9TQsEAuid7ZpbRG 8AAngFm7Zar/7sLd7aEppo72OOLdGCt14ds/LTcstLG2YkWYdEsLmHqSIdrVnEvtlCae tnu8hShrZzgJW474bdZSWoID0a6WY5Mr8ksbNMR/vFTeSm4xDT39+D12kixQ1Ug6RMte UEEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=TSi4qw+P; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 f15-v6si3031372plk.245.2018.03.01.05.00.26; Thu, 01 Mar 2018 05:00:41 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-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=TSi4qw+P; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 S1031005AbeCAM72 (ORCPT + 99 others); Thu, 1 Mar 2018 07:59:28 -0500 Received: from mail-pg0-f67.google.com ([74.125.83.67]:32779 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030804AbeCAM7W (ORCPT ); Thu, 1 Mar 2018 07:59:22 -0500 Received: by mail-pg0-f67.google.com with SMTP id g12so2279725pgs.0 for ; Thu, 01 Mar 2018 04:59:21 -0800 (PST) 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; bh=LVyW4e3/ZiswQxGmhghNNTu5Pe0KH7+4scjkon+J7js=; b=TSi4qw+PBRPwqxaK5h7uIK7sqDHPIq59aqoFS3cuBmSFfu62O14ncON6D1XvkgZ86g FiG07MpGA6rb1NlDEfQgmm4xsibPm3kLDs06hpiRD5G6kOmCzslEuelG9gGKvnFfFB87 bSEb1SIPy5LkLg521qXlNe8UfuG94rHDmADE4= 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; bh=LVyW4e3/ZiswQxGmhghNNTu5Pe0KH7+4scjkon+J7js=; b=mA+jj4A76mT5nmvNsQH2/z/ZH8E+iJ7qz0j0TUMaxbQaqBWdtKcofJVYI4K0p4jr0x e8iea7QybRSLvxJygTdvqmO4vO3HXKfhngMHCEzxHquQ8Kll1be+OlunxoKrZv4vEIV/ Aw/4dy88ELB0BxTITJT6+gaNTtvlIukVC3iA0DddNl1Eh5WYA2oBwihWQAKMkjy5C1il YN7gvdQ0Z46d/HbUSpefa2gDo2gpcbxoIPXYqqkHV62gdP3H8GQPtK84EutTin39t/MY EThCs0KjH1GA+0JwtoloG1HHk5I/Ws9eIRQfUVE65dAzg44AtuokEP67F+MuH2QVlfFJ ZjpA== X-Gm-Message-State: APf1xPBJwyQBHbNoRI0pke8G1ot0JeyvpP5NDb5/Mx4iknDwtcqR+ZmR irvQia4Bewn0yt/nCoivbze15au2sqM= X-Received: by 10.101.87.199 with SMTP id q7mr1496822pgr.215.1519909161327; Thu, 01 Mar 2018 04:59:21 -0800 (PST) Received: from localhost.localdomain (176.122.172.82.16clouds.com. [176.122.172.82]) by smtp.gmail.com with ESMTPSA id x4sm2289655pfb.46.2018.03.01.04.59.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 01 Mar 2018 04:59:20 -0800 (PST) From: Alex Shi To: Marc Zyngier , Will Deacon , Ard Biesheuvel , Catalin Marinas , stable@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Alex Shi Subject: [PATCH 29/45] arm64: Implement branch predictor hardening for affected Cortex-A CPUs Date: Thu, 1 Mar 2018 20:54:06 +0800 Message-Id: <1519908862-11425-30-git-send-email-alex.shi@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1519908862-11425-1-git-send-email-alex.shi@linaro.org> References: <1519908862-11425-1-git-send-email-alex.shi@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Will Deacon commit aa6acde65e03 upstream. Cortex-A57, A72, A73 and A75 are susceptible to branch predictor aliasing and can theoretically be attacked by malicious code. This patch implements a PSCI-based mitigation for these CPUs when available. The call into firmware will invalidate the branch predictor state, preventing any malicious entries from affecting other victim contexts. Co-developed-by: Marc Zyngier Signed-off-by: Will Deacon Signed-off-by: Catalin Marinas Signed-off-by: Alex Shi --- arch/arm64/kernel/bpi.S | 24 ++++++++++++++++++++++++ arch/arm64/kernel/cpu_errata.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) diff --git a/arch/arm64/kernel/bpi.S b/arch/arm64/kernel/bpi.S index 06a931e..dec95bd 100644 --- a/arch/arm64/kernel/bpi.S +++ b/arch/arm64/kernel/bpi.S @@ -53,3 +53,27 @@ ENTRY(__bp_harden_hyp_vecs_start) vectors __kvm_hyp_vector .endr ENTRY(__bp_harden_hyp_vecs_end) +ENTRY(__psci_hyp_bp_inval_start) + sub sp, sp, #(8 * 18) + stp x16, x17, [sp, #(16 * 0)] + stp x14, x15, [sp, #(16 * 1)] + stp x12, x13, [sp, #(16 * 2)] + stp x10, x11, [sp, #(16 * 3)] + stp x8, x9, [sp, #(16 * 4)] + stp x6, x7, [sp, #(16 * 5)] + stp x4, x5, [sp, #(16 * 6)] + stp x2, x3, [sp, #(16 * 7)] + stp x0, x1, [sp, #(16 * 8)] + mov x0, #0x84000000 + smc #0 + ldp x16, x17, [sp, #(16 * 0)] + ldp x14, x15, [sp, #(16 * 1)] + ldp x12, x13, [sp, #(16 * 2)] + ldp x10, x11, [sp, #(16 * 3)] + ldp x8, x9, [sp, #(16 * 4)] + ldp x6, x7, [sp, #(16 * 5)] + ldp x4, x5, [sp, #(16 * 6)] + ldp x2, x3, [sp, #(16 * 7)] + ldp x0, x1, [sp, #(16 * 8)] + add sp, sp, #(8 * 18) +ENTRY(__psci_hyp_bp_inval_end) diff --git a/arch/arm64/kernel/cpu_errata.c b/arch/arm64/kernel/cpu_errata.c index 0e07893..f8810bf 100644 --- a/arch/arm64/kernel/cpu_errata.c +++ b/arch/arm64/kernel/cpu_errata.c @@ -53,6 +53,8 @@ static int cpu_enable_trap_ctr_access(void *__unused) DEFINE_PER_CPU_READ_MOSTLY(struct bp_hardening_data, bp_hardening_data); #ifdef CONFIG_KVM +extern char __psci_hyp_bp_inval_start[], __psci_hyp_bp_inval_end[]; + static void __copy_hyp_vect_bpi(int slot, const char *hyp_vecs_start, const char *hyp_vecs_end) { @@ -94,6 +96,9 @@ static void __install_bp_hardening_cb(bp_hardening_cb_t fn, spin_unlock(&bp_lock); } #else +#define __psci_hyp_bp_inval_start NULL +#define __psci_hyp_bp_inval_end NULL + static void __install_bp_hardening_cb(bp_hardening_cb_t fn, const char *hyp_vecs_start, const char *hyp_vecs_end) @@ -118,6 +123,21 @@ static void install_bp_hardening_cb(const struct arm64_cpu_capabilities *entry, __install_bp_hardening_cb(fn, hyp_vecs_start, hyp_vecs_end); } + +#include + +static int enable_psci_bp_hardening(void *data) +{ + const struct arm64_cpu_capabilities *entry = data; + + if (psci_ops.get_version) + install_bp_hardening_cb(entry, + (bp_hardening_cb_t)psci_ops.get_version, + __psci_hyp_bp_inval_start, + __psci_hyp_bp_inval_end); + + return 0; +} #endif /* CONFIG_HARDEN_BRANCH_PREDICTOR */ #define MIDR_RANGE(model, min, max) \ @@ -211,6 +231,28 @@ const struct arm64_cpu_capabilities arm64_errata[] = { .def_scope = SCOPE_LOCAL_CPU, .enable = cpu_enable_trap_ctr_access, }, +#ifdef CONFIG_HARDEN_BRANCH_PREDICTOR + { + .capability = ARM64_HARDEN_BRANCH_PREDICTOR, + MIDR_ALL_VERSIONS(MIDR_CORTEX_A57), + .enable = enable_psci_bp_hardening, + }, + { + .capability = ARM64_HARDEN_BRANCH_PREDICTOR, + MIDR_ALL_VERSIONS(MIDR_CORTEX_A72), + .enable = enable_psci_bp_hardening, + }, + { + .capability = ARM64_HARDEN_BRANCH_PREDICTOR, + MIDR_ALL_VERSIONS(MIDR_CORTEX_A73), + .enable = enable_psci_bp_hardening, + }, + { + .capability = ARM64_HARDEN_BRANCH_PREDICTOR, + MIDR_ALL_VERSIONS(MIDR_CORTEX_A75), + .enable = enable_psci_bp_hardening, + }, +#endif { } }; -- 2.7.4