Skip to content

Commit 04ad99a

Browse files
mrutland-armctmarinas
authored andcommitted
arm64: unwind: strip PAC from kernel addresses
When we enable pointer authentication in the kernel, LR values saved to the stack will have a PAC which we must strip in order to retrieve the real return address. Strip PACs when unwinding the stack in order to account for this. When function graph tracer is used with patchable-function-entry then return_to_handler will also have pac bits so strip it too. Reviewed-by: Kees Cook <[email protected]> Acked-by: Catalin Marinas <[email protected]> Reviewed-by: James Morse <[email protected]> Signed-off-by: Mark Rutland <[email protected]> Signed-off-by: Kristina Martsenko <[email protected]> [Amit: Re-position ptrauth_strip_insn_pac, comment] Signed-off-by: Amit Daniel Kachhap <[email protected]> Signed-off-by: Catalin Marinas <[email protected]>
1 parent 689eae4 commit 04ad99a

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

arch/arm64/kernel/stacktrace.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <linux/stacktrace.h>
1515

1616
#include <asm/irq.h>
17+
#include <asm/pointer_auth.h>
1718
#include <asm/stack_pointer.h>
1819
#include <asm/stacktrace.h>
1920

@@ -86,7 +87,7 @@ int notrace unwind_frame(struct task_struct *tsk, struct stackframe *frame)
8687

8788
#ifdef CONFIG_FUNCTION_GRAPH_TRACER
8889
if (tsk->ret_stack &&
89-
(frame->pc == (unsigned long)return_to_handler)) {
90+
(ptrauth_strip_insn_pac(frame->pc) == (unsigned long)return_to_handler)) {
9091
struct ftrace_ret_stack *ret_stack;
9192
/*
9293
* This is a case where function graph tracer has
@@ -101,6 +102,8 @@ int notrace unwind_frame(struct task_struct *tsk, struct stackframe *frame)
101102
}
102103
#endif /* CONFIG_FUNCTION_GRAPH_TRACER */
103104

105+
frame->pc = ptrauth_strip_insn_pac(frame->pc);
106+
104107
/*
105108
* Frames created upon entry from EL0 have NULL FP and PC values, so
106109
* don't bother reporting these. Frames created by __noreturn functions

0 commit comments

Comments
 (0)