From: Amit Daniel Kachhap <amit.kachhap@arm.com>
To: linux-arm-kernel@lists.infradead.org
Cc: Mark Rutland <mark.rutland@arm.com>,
Andrew Jones <drjones@redhat.com>,
Marc Zyngier <marc.zyngier@arm.com>,
Catalin Marinas <catalin.marinas@arm.com>,
Will Deacon <will.deacon@arm.com>,
Christoffer Dall <christoffer.dall@arm.com>,
Kristina Martsenko <kristina.martsenko@arm.com>,
kvmarm@lists.cs.columbia.edu,
Ramana Radhakrishnan <ramana.radhakrishnan@arm.com>,
Amit Daniel Kachhap <amit.kachhap@arm.com>,
Dave Martin <Dave.Martin@arm.com>,
linux-kernel@vger.kernel.org
Subject: [PATCH v5 1/5] arm64: Add utilities to save restore pointer authentication keys
Date: Mon, 28 Jan 2019 12:28:42 +0530 [thread overview]
Message-ID: <1548658727-14271-2-git-send-email-amit.kachhap@arm.com> (raw)
In-Reply-To: <1548658727-14271-1-git-send-email-amit.kachhap@arm.com>
The keys can be switched either inside an assembly or such
functions which do not have pointer authentication checks, so a GCC
attribute is added to enable it.
A function ptrauth_keys_store is added which is similar to existing
function ptrauth_keys_switch but saves the key values in memory.
This may be useful for save/restore scenarios when CPU changes
privilege levels, suspend/resume etc.
Signed-off-by: Amit Daniel Kachhap <amit.kachhap@arm.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Marc Zyngier <marc.zyngier@arm.com>
Cc: Christoffer Dall <christoffer.dall@arm.com>
Cc: Kristina Martsenko <kristina.martsenko@arm.com>
Cc: kvmarm@lists.cs.columbia.edu
Cc: Ramana Radhakrishnan <ramana.radhakrishnan@arm.com>
Cc: Will Deacon <will.deacon@arm.com>
---
arch/arm64/include/asm/pointer_auth.h | 28 ++++++++++++++++++++++++++++
1 file changed, 28 insertions(+)
diff --git a/arch/arm64/include/asm/pointer_auth.h b/arch/arm64/include/asm/pointer_auth.h
index 15d4951..98441ce 100644
--- a/arch/arm64/include/asm/pointer_auth.h
+++ b/arch/arm64/include/asm/pointer_auth.h
@@ -11,6 +11,13 @@
#ifdef CONFIG_ARM64_PTR_AUTH
/*
+ * Compile the function without pointer authentication instructions. This
+ * allows pointer authentication to be enabled/disabled within the function
+ * (but leaves the function unprotected by pointer authentication).
+ */
+#define __no_ptrauth __attribute__((target("sign-return-address=none")))
+
+/*
* Each key is a 128-bit quantity which is split across a pair of 64-bit
* registers (Lo and Hi).
*/
@@ -50,6 +57,13 @@ do { \
write_sysreg_s(__pki_v.hi, SYS_ ## k ## KEYHI_EL1); \
} while (0)
+#define __ptrauth_key_save(k, v) \
+do { \
+ struct ptrauth_key __pki_v = (v); \
+ __pki_v.lo = read_sysreg_s(SYS_ ## k ## KEYLO_EL1); \
+ __pki_v.hi = read_sysreg_s(SYS_ ## k ## KEYHI_EL1); \
+} while (0)
+
static inline void ptrauth_keys_switch(struct ptrauth_keys *keys)
{
if (system_supports_address_auth()) {
@@ -63,6 +77,19 @@ static inline void ptrauth_keys_switch(struct ptrauth_keys *keys)
__ptrauth_key_install(APGA, keys->apga);
}
+static inline void ptrauth_keys_store(struct ptrauth_keys *keys)
+{
+ if (system_supports_address_auth()) {
+ __ptrauth_key_save(APIA, keys->apia);
+ __ptrauth_key_save(APIB, keys->apib);
+ __ptrauth_key_save(APDA, keys->apda);
+ __ptrauth_key_save(APDB, keys->apdb);
+ }
+
+ if (system_supports_generic_auth())
+ __ptrauth_key_save(APGA, keys->apga);
+}
+
extern int ptrauth_prctl_reset_keys(struct task_struct *tsk, unsigned long arg);
/*
@@ -88,6 +115,7 @@ do { \
ptrauth_keys_switch(&(tsk)->thread.keys_user)
#else /* CONFIG_ARM64_PTR_AUTH */
+#define __no_ptrauth
#define ptrauth_prctl_reset_keys(tsk, arg) (-EINVAL)
#define ptrauth_strip_insn_pac(lr) (lr)
#define ptrauth_thread_init_user(tsk)
--
2.7.4
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2019-01-28 6:59 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-28 6:58 [PATCH v5 0/6] Add ARMv8.3 pointer authentication for kvm guest Amit Daniel Kachhap
2019-01-28 6:58 ` Amit Daniel Kachhap [this message]
2019-01-31 16:20 ` [PATCH v5 1/5] arm64: Add utilities to save restore pointer authentication keys James Morse
2019-02-13 17:32 ` Kristina Martsenko
2019-02-14 10:53 ` Amit Daniel Kachhap
2019-01-28 6:58 ` [PATCH v5 2/5] arm64/kvm: preserve host HCR_EL2/MDCR_EL2 value Amit Daniel Kachhap
2019-01-31 16:22 ` James Morse
2019-02-14 9:49 ` Amit Daniel Kachhap
2019-02-13 17:34 ` Kristina Martsenko
2019-02-14 11:03 ` Amit Daniel Kachhap
2019-02-15 15:50 ` Kristina Martsenko
2019-01-28 6:58 ` [PATCH v5 3/5] arm64/kvm: context-switch ptrauth registers Amit Daniel Kachhap
2019-01-28 14:25 ` Julien Thierry
2019-01-31 16:25 ` [PATCH v5 3/5] arm64/kvm: context-switch ptrauth register James Morse
2019-02-13 17:35 ` Kristina Martsenko
2019-02-15 4:00 ` Amit Daniel Kachhap
2019-02-14 10:16 ` Amit Daniel Kachhap
2019-02-13 17:34 ` [PATCH v5 3/5] arm64/kvm: context-switch ptrauth registers Kristina Martsenko
2019-02-14 11:06 ` Amit Daniel Kachhap
2019-01-28 6:58 ` [PATCH v5 4/5] arm64/kvm: add a userspace option to enable pointer authentication Amit Daniel Kachhap
2019-01-28 14:35 ` Julien Thierry
2019-01-31 16:27 ` James Morse
2019-02-14 10:47 ` Amit Daniel Kachhap
2019-02-13 17:35 ` Kristina Martsenko
2019-02-15 4:49 ` Amit Daniel Kachhap
2019-01-28 6:58 ` [PATCH v5 5/5] arm64/kvm: control accessibility of ptrauth key registers Amit Daniel Kachhap
2019-02-13 17:35 ` Kristina Martsenko
2019-02-13 17:54 ` Dave P Martin
2019-02-15 4:57 ` Amit Daniel Kachhap
2019-01-28 6:58 ` [kvmtool PATCH v5 6/6] arm/kvm: arm64: Add a vcpu feature for pointer authentication Amit Daniel Kachhap
2019-01-28 14:56 ` Julien Thierry
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=1548658727-14271-2-git-send-email-amit.kachhap@arm.com \
--to=amit.kachhap@arm.com \
--cc=Dave.Martin@arm.com \
--cc=catalin.marinas@arm.com \
--cc=christoffer.dall@arm.com \
--cc=drjones@redhat.com \
--cc=kristina.martsenko@arm.com \
--cc=kvmarm@lists.cs.columbia.edu \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=marc.zyngier@arm.com \
--cc=mark.rutland@arm.com \
--cc=ramana.radhakrishnan@arm.com \
--cc=will.deacon@arm.com \
/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).