From: Ard Biesheuvel <ardb@kernel.org>
To: linux-arm-kernel@lists.infradead.org
Cc: Ard Biesheuvel <ardb@kernel.org>, Marc Zyngier <maz@kernel.org>,
Will Deacon <will@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Kees Cook <keescook@chromium.org>,
Catalin Marinas <catalin.marinas@arm.com>,
Mark Brown <broonie@kernel.org>
Subject: [PATCH v3 3/4] arm64: ftrace: Preserve original link register value in ftrace_regs
Date: Fri, 9 Dec 2022 16:20:47 +0100 [thread overview]
Message-ID: <20221209152048.3517080-4-ardb@kernel.org> (raw)
In-Reply-To: <20221209152048.3517080-1-ardb@kernel.org>
In order to be able to add pointer authentication and/or shadow call
stack support to the ftrace asm routines, it will need to reason about
whether or not the callsite's return address was updated to point to
return_to_handler(), as in this case, we want the authentication to
occur there and not before returning to the call site.
To make this a bit easier, preserve the value of register X9, which
carries the callsite's LR value upon entry to ftrace_caller, so in a
later patch, we can compare it to the callsite's effective LR upon
return, and omit the authentication if the caller will be returning via
return_to_handler().
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
arch/arm64/include/asm/ftrace.h | 2 +-
arch/arm64/kernel/entry-ftrace.S | 12 ++++++------
2 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/arch/arm64/include/asm/ftrace.h b/arch/arm64/include/asm/ftrace.h
index 5664729800ae1c13..b07501645a74031a 100644
--- a/arch/arm64/include/asm/ftrace.h
+++ b/arch/arm64/include/asm/ftrace.h
@@ -86,7 +86,7 @@ struct ftrace_ops;
struct ftrace_regs {
/* x0 - x8 */
unsigned long regs[9];
- unsigned long __unused;
+ unsigned long orig_lr; // must follow ®s[8]
unsigned long fp;
unsigned long lr;
diff --git a/arch/arm64/kernel/entry-ftrace.S b/arch/arm64/kernel/entry-ftrace.S
index 30cc2a9d1757a6a7..bccd525241ab615d 100644
--- a/arch/arm64/kernel/entry-ftrace.S
+++ b/arch/arm64/kernel/entry-ftrace.S
@@ -42,12 +42,12 @@ SYM_CODE_START(ftrace_caller)
/* Make room for ftrace regs, plus two frame records */
sub sp, sp, #(FREGS_SIZE + 32)
- /* Save function arguments */
+ /* Save function arguments and original callsite LR */
stp x0, x1, [sp, #FREGS_X0]
stp x2, x3, [sp, #FREGS_X2]
stp x4, x5, [sp, #FREGS_X4]
stp x6, x7, [sp, #FREGS_X6]
- str x8, [sp, #FREGS_X8]
+ stp x8, x9, [sp, #FREGS_X8]
/* Save the callsite's FP, LR, SP */
str x29, [sp, #FREGS_FP]
@@ -78,22 +78,22 @@ SYM_INNER_LABEL(ftrace_call, SYM_L_GLOBAL)
* x19-x29 per the AAPCS, and we created frame records upon entry, so we need
* to restore x0-x8, x29, and x30.
*/
- /* Restore function arguments */
+ /* Restore function arguments and original callsite LR */
ldp x0, x1, [sp, #FREGS_X0]
ldp x2, x3, [sp, #FREGS_X2]
ldp x4, x5, [sp, #FREGS_X4]
ldp x6, x7, [sp, #FREGS_X6]
- ldr x8, [sp, #FREGS_X8]
+ ldp x8, x9, [sp, #FREGS_X8]
/* Restore the callsite's FP, LR, PC */
ldr x29, [sp, #FREGS_FP]
ldr x30, [sp, #FREGS_LR]
- ldr x9, [sp, #FREGS_PC]
+ ldr x10, [sp, #FREGS_PC]
/* Restore the callsite's SP */
add sp, sp, #FREGS_SIZE + 32
- ret x9
+ ret x10
SYM_CODE_END(ftrace_caller)
#else /* CONFIG_DYNAMIC_FTRACE_WITH_ARGS */
--
2.35.1
_______________________________________________
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:[~2022-12-09 15:22 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-09 15:20 [PATCH v3 0/4] arm64: Add return address protection to asm code Ard Biesheuvel
2022-12-09 15:20 ` [PATCH v3 1/4] arm64: assembler: Force error on misuse of .Lframe_local_offset Ard Biesheuvel
2022-12-09 15:20 ` [PATCH v3 2/4] arm64: assembler: Protect return addresses in asm routines Ard Biesheuvel
2022-12-09 15:20 ` Ard Biesheuvel [this message]
2022-12-09 15:20 ` [PATCH v3 4/4] arm64: ftrace: Add return address protection Ard Biesheuvel
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=20221209152048.3517080-4-ardb@kernel.org \
--to=ardb@kernel.org \
--cc=broonie@kernel.org \
--cc=catalin.marinas@arm.com \
--cc=keescook@chromium.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=mark.rutland@arm.com \
--cc=maz@kernel.org \
--cc=will@kernel.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).