]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
arm64: perf: strip PAC when unwinding userspace
authorMark Rutland <mark.rutland@arm.com>
Fri, 7 Dec 2018 18:39:27 +0000 (18:39 +0000)
committerWill Deacon <will.deacon@arm.com>
Thu, 13 Dec 2018 16:42:46 +0000 (16:42 +0000)
When the kernel is unwinding userspace callchains, we can't expect that
the userspace consumer of these callchains has the data necessary to
strip the PAC from the stored LR.

This patch has the kernel strip the PAC from user stackframes when the
in-kernel unwinder is used. This only affects the LR value, and not the
FP.

This only affects the in-kernel unwinder. When userspace performs
unwinding, it is up to userspace to strip PACs as necessary (which can
be determined from DWARF information).

Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: Kristina Martsenko <kristina.martsenko@arm.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Ramana Radhakrishnan <ramana.radhakrishnan@arm.com>
Cc: Will Deacon <will.deacon@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
arch/arm64/include/asm/pointer_auth.h
arch/arm64/kernel/perf_callchain.c

index 2a22c03c1540fcccf7376ba3b3c6cbc940e528c7..5ccf49b4dac38ff4decf900e2a1213ed694bd65a 100644 (file)
@@ -69,6 +69,12 @@ static inline void ptrauth_keys_switch(struct ptrauth_keys *keys)
  */
 #define ptrauth_user_pac_mask()        GENMASK(54, vabits_user)
 
+/* Only valid for EL0 TTBR0 instruction pointers */
+static inline unsigned long ptrauth_strip_insn_pac(unsigned long ptr)
+{
+       return ptr & ~ptrauth_user_pac_mask();
+}
+
 #define ptrauth_thread_init_user(tsk)                                  \
 do {                                                                   \
        struct task_struct *__ptiu_tsk = (tsk);                         \
@@ -80,6 +86,7 @@ do {                                                                  \
        ptrauth_keys_switch(&(tsk)->thread_info.keys_user)
 
 #else /* CONFIG_ARM64_PTR_AUTH */
+#define ptrauth_strip_insn_pac(lr)     (lr)
 #define ptrauth_thread_init_user(tsk)
 #define ptrauth_thread_switch(tsk)
 #endif /* CONFIG_ARM64_PTR_AUTH */
index bcafd7dcfe8b186c07c1f7138ca4dc62035aa61e..94754f07f67aa29363c3d4e86be560d8b8b1a5d1 100644 (file)
@@ -18,6 +18,7 @@
 #include <linux/perf_event.h>
 #include <linux/uaccess.h>
 
+#include <asm/pointer_auth.h>
 #include <asm/stacktrace.h>
 
 struct frame_tail {
@@ -35,6 +36,7 @@ user_backtrace(struct frame_tail __user *tail,
 {
        struct frame_tail buftail;
        unsigned long err;
+       unsigned long lr;
 
        /* Also check accessibility of one struct frame_tail beyond */
        if (!access_ok(VERIFY_READ, tail, sizeof(buftail)))
@@ -47,7 +49,9 @@ user_backtrace(struct frame_tail __user *tail,
        if (err)
                return NULL;
 
-       perf_callchain_store(entry, buftail.lr);
+       lr = ptrauth_strip_insn_pac(buftail.lr);
+
+       perf_callchain_store(entry, lr);
 
        /*
         * Frame pointers should strictly progress back up the stack