From: Julien Grall <julien.grall@linaro.org>
To: xen-devel@lists.xen.org
Cc: Marc Zyngier <marc.zyngier@arm.com>,
sstabellini@kernel.org, Julien Grall <julien.grall@linaro.org>,
andre.przywara@linaro.org
Subject: [PATCH v4 6/7] xen/arm32: Invalidate icache on guest exist for Cortex-A15
Date: Fri, 2 Feb 2018 14:19:24 +0000 [thread overview]
Message-ID: <20180202141925.19387-7-julien.grall@linaro.org> (raw)
In-Reply-To: <20180202141925.19387-1-julien.grall@linaro.org>
In order to avoid aliasing attacks against the branch predictor on
Cortex A-15, let's invalidate the BTB on guest exit, which can only be
done by invalidating the icache (with ACTLR[0] being set).
We use the same hack as for A12/A17 to perform the vector decoding.
This is based on Linux patch from the kpti branch in [1].
[1] https://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
Signed-off-by: Julien Grall <julien.grall@linaro.org>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
---
Changes in v2:
- Add Stefano's reviewed-by
---
xen/arch/arm/arm32/entry.S | 21 +++++++++++++++++++++
xen/arch/arm/cpuerrata.c | 13 +++++++++++++
2 files changed, 34 insertions(+)
diff --git a/xen/arch/arm/arm32/entry.S b/xen/arch/arm/arm32/entry.S
index 1ebbe4b065..2f8b7cb7b8 100644
--- a/xen/arch/arm/arm32/entry.S
+++ b/xen/arch/arm/arm32/entry.S
@@ -163,6 +163,26 @@ GLOBAL(hyp_traps_vector)
#ifdef CONFIG_HARDEN_BRANCH_PREDICTOR
.align 5
+GLOBAL(hyp_traps_vector_ic_inv)
+ /*
+ * We encode the exception entry in the bottom 3 bits of
+ * SP, and we have to guarantee to be 8 bytes aligned.
+ */
+ add sp, sp, #1 /* Reset 7 */
+ add sp, sp, #1 /* Undef 6 */
+ add sp, sp, #1 /* Hypervisor call 5 */
+ add sp, sp, #1 /* Prefetch abort 4 */
+ add sp, sp, #1 /* Data abort 3 */
+ add sp, sp, #1 /* Hypervisor 2 */
+ add sp, sp, #1 /* IRQ 1 */
+ nop /* FIQ 0 */
+
+ mcr p15, 0, r0, c7, c5, 0 /* ICIALLU */
+ isb
+
+ b decode_vectors
+
+ .align 5
GLOBAL(hyp_traps_vector_bp_inv)
/*
* We encode the exception entry in the bottom 3 bits of
@@ -180,6 +200,7 @@ GLOBAL(hyp_traps_vector_bp_inv)
mcr p15, 0, r0, c7, c5, 6 /* BPIALL */
isb
+decode_vectors:
.macro vect_br val, targ
eor sp, sp, #\val
tst sp, #7
diff --git a/xen/arch/arm/cpuerrata.c b/xen/arch/arm/cpuerrata.c
index c79e6d65d3..9c7458ef06 100644
--- a/xen/arch/arm/cpuerrata.c
+++ b/xen/arch/arm/cpuerrata.c
@@ -180,6 +180,7 @@ static int enable_psci_bp_hardening(void *data)
DEFINE_PER_CPU_READ_MOSTLY(const char *, bp_harden_vecs);
extern char hyp_traps_vector_bp_inv[];
+extern char hyp_traps_vector_ic_inv[];
static void __maybe_unused
install_bp_hardening_vecs(const struct arm_cpu_capabilities *entry,
@@ -205,6 +206,13 @@ static int enable_bp_inv_hardening(void *data)
return 0;
}
+static int enable_ic_inv_hardening(void *data)
+{
+ install_bp_hardening_vecs(data, hyp_traps_vector_ic_inv,
+ "execute ICIALLU");
+ return 0;
+}
+
#endif
#define MIDR_RANGE(model, min, max) \
@@ -302,6 +310,11 @@ static const struct arm_cpu_capabilities arm_errata[] = {
MIDR_ALL_VERSIONS(MIDR_CORTEX_A17),
.enable = enable_bp_inv_hardening,
},
+ {
+ .capability = ARM_HARDEN_BRANCH_PREDICTOR,
+ MIDR_ALL_VERSIONS(MIDR_CORTEX_A15),
+ .enable = enable_ic_inv_hardening,
+ },
#endif
{},
};
--
2.11.0
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
next prev parent reply other threads:[~2018-02-02 14:19 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-02 14:19 [PATCH v4 0/7] xen/arm32: Branch predictor hardening (XSA-254 variant 2) Julien Grall
2018-02-02 14:19 ` [PATCH v4 1/7] xen/arm32: entry: Consolidate DEFINE_TRAP_ENTRY_* macros Julien Grall
2018-02-02 14:19 ` [PATCH v4 2/7] xen/arm32: Add missing MIDR values for Cortex-A17 and A12 Julien Grall
2018-02-02 14:19 ` [PATCH v4 3/7] xen/arm32: entry: Add missing trap_reset entry Julien Grall
2018-02-02 14:19 ` [PATCH v4 4/7] xen/arm32: Add skeleton to harden branch predictor aliasing attacks Julien Grall
2018-02-02 14:19 ` [PATCH v4 5/7] xen/arm32: Invalidate BTB on guest exit for Cortex A17 and 12 Julien Grall
2018-02-02 14:19 ` Julien Grall [this message]
2018-02-02 14:19 ` [PATCH v4 7/7] xen/arm32: entry: Document the purpose of r11 in the traps handler Julien Grall
2018-02-02 19:38 ` [PATCH v4 0/7] xen/arm32: Branch predictor hardening (XSA-254 variant 2) Stefano Stabellini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180202141925.19387-7-julien.grall@linaro.org \
--to=julien.grall@linaro.org \
--cc=andre.przywara@linaro.org \
--cc=marc.zyngier@arm.com \
--cc=sstabellini@kernel.org \
--cc=xen-devel@lists.xen.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).