Skip to content

arm64: Add return address protection to asm code

Ard Biesheuvel linux-arm-kernel 2 versions – New

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v3 Latest4 patches 0 repliesNew
  2. v14 patches 9 repliesSuperseded

Changes in v3 from the cover letter

- rebase onto updated ftrace tree
- drop EFI changes for the time being, I'll bring those back later
- emit unwind directives for return address registers != x30, and handle them in the dynamic SCS patching code

Patches in v3 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/4arm64: assembler: Force error on misuse of .Lframe_local_offsetarch/arm64/include/asm/assembler.h+1 -00 replies
2/4arm64: assembler: Protect return addresses in asm routinesarch/arm64/include/asm/assembler.h arch/arm64/kernel/patch-scs.c+127 -180 replies
3/4arm64: ftrace: Preserve original link register value in ftrace_regsarch/arm64/include/asm/ftrace.h arch/arm64/kernel/entry-ftrace.S+7 -70 replies
4/4arm64: ftrace: Add return address protectionarch/arm64/kernel/entry-ftrace.S arch/arm64/kernel/stacktrace.c+17 -10 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v3 yet.

Read the v3 thread

Cover letter [PATCH v3 0/4] arm64: Add return address protection to asm code

Control flow integrity features such as shadow call stack or PAC work by placing special instructions between the reload of the link register from the stack and the function return. The point of this is not only to protect the control flow when calling that particular function, but also to ensure that the sequence of instructions appearing at the end of the function cannot be subverted and used in other ways than intended, in a ROP/JOP style attack.

This means that it is generally a bad idea to incorporate any code that is rarely or never used, but lacks such protections. So add some macros that we can invoke in assembler code to protect the return address while it is stored on the stack, and wire it up in the ftrace code, which is often built into production kernels even when not used.

Another example of this is crypto code, and some fixes have been queued up in the cryptodev tree to ensure that the frame_push and frame_pop macros are used consistently.

v3:
- rebase onto updated ftrace tree
- drop EFI changes for the time being, I'll bring those back later
- emit unwind directives for return address registers != x30, and handle them in the dynamic SCS patching code

Cc Marc Zyngier <[email protected]>
Cc Will Deacon <[email protected]>
Cc Mark Rutland <[email protected]>
Cc Kees Cook <[email protected]>
Cc Catalin Marinas <[email protected]>
Cc Mark Brown <[email protected]>

Ard Biesheuvel (4):
arm64: assembler: Force error on misuse of .Lframe_local_offset
arm64: assembler: Protect return addresses in asm routines
arm64: ftrace: Preserve original link register value in ftrace_regs
arm64: ftrace: Add return address protection

 arch/arm64/include/asm/assembler.h | 76 ++++++++++++++++++++
 arch/arm64/include/asm/ftrace.h    |  2 +-
 arch/arm64/kernel/entry-ftrace.S   | 27 +++++--
 arch/arm64/kernel/patch-scs.c      | 70 +++++++++++++-----
 arch/arm64/kernel/stacktrace.c     |  1 +
 5 files changed, 151 insertions(+), 25 deletions(-)
Signature · 7 lines
2.35.1


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel