Skip to content

RFC arm64: use unwind data on GCC for shadow call stack

Ard Biesheuvel linux-arm-kernel linux-hardening linux-toolchains 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 RFC Latest9 patches 6 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/9arm64: assembler: enable PAC for non-leaf assembler routinesarch/arm64/include/asm/assembler.h+6 -00 replies
2/9arm64: cache: use ALIAS version of linkage macros for local aliasesarch/arm64/mm/cache.S+4 -40 replies
3/9arm64: crypto: avoid overlapping linkage definitions for AES-CBCarch/arm64/crypto/aes-modes.S+2 -20 replies
4/9arm64: aes-neonbs: move frame pop to end of functionarch/arm64/crypto/aes-neonbs-core.S+4 -40 replies
5/9arm64: chacha-neon: move frame pop forwardarch/arm64/crypto/chacha-neon-core.S+5 -40 replies
6/9arm64: smccc: create proper stack frames for HVC/SMC callsarch/arm64/kernel/smccc-call.S+17 -231 reply
7/9arm64: assembler: add unwind annotations to frame push/pop macrosarch/arm64/include/asm/assembler.h arch/arm64/include/asm/linkage.h+40 -20 replies
8/9arm64: unwind: add asynchronous unwind tables to the kernel properarch/arm64/Kconfig arch/arm64/Makefile arch/arm64/kernel/vmlinux.lds.S +1 more+30 -10 replies
9/9arm64: implement dynamic shadow call stack for GCCMakefile arch/Kconfig arch/arm64/Kconfig +3 more+239 -53 replies

Reviews trailers per patch

1 of 9 patches has a Reviewed-by or Acked-by.

PatchMark Brown
1/9
2/9
3/9
4/9
5/9
6/9R-b
7/9
8/9
9/9

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v1 thread

Cover letter [RFC PATCH 0/9] arm64: use unwind data on GCC for shadow call stack

This series is a proof of concept implementation of using unwind tables to locate PACIASP/AUTIASP instructions in the code, and patching them into shadow call stack pushes/pops at boot time if the platform in question does not support pointer authentication in hardware. This way, the overhead of the shadow call stack is only imposed if it actually gives any benefit. It also means that the compiler does not need to generate the code, so this works with GCC as well.

In fact, it only works with GCC at the moment, as Clang does not seem to implement the DW_CFA_negate_ra_state correctly, which is emitted after each PACIASP or AUTIASP instruction (Clang only does the former). However, GCC does not appear to get it quite right either, as it emits the directive in the wrong place in some cases (but in a way that can be worked around).

Note that this only implements it for the core kernel. Modules should be straight-forward, and most of the code can be reused. Also, the transformation is applied unconditionally, even if the hardware does implement PAC, but this does not really matter for a PoC.

One obvious downside is the size of the unwind tables (3 MiB for defconfig), although there are plenty of use cases where this does not really matters (and I haven't checked the compressed size). However, there may be other reasons why we'd want to have access to these unwind tables (reliable stack traces), so this will need to be discussed before I intend to take this any further.

Cc Kees Cook <[email protected]>
Cc Sami Tolvanen <[email protected]>
Cc Fangrui Song <[email protected]>
Cc Nick Desaulniers <[email protected]>
Cc Dan Li <[email protected]>

Ard Biesheuvel (9):
arm64: assembler: enable PAC for non-leaf assembler routines
arm64: cache: use ALIAS version of linkage macros for local aliases
arm64: crypto: avoid overlapping linkage definitions for AES-CBC
arm64: aes-neonbs: move frame pop to end of function
arm64: chacha-neon: move frame pop forward
arm64: smccc: create proper stack frames for HVC/SMC calls
arm64: assembler: add unwind annotations to frame push/pop macros
arm64: unwind: add asynchronous unwind tables to the kernel proper
arm64: implement dynamic shadow call stack for GCC

 Makefile                              |   4 +-
 arch/Kconfig                          |   4 +-
 arch/arm64/Kconfig                    |  11 +-
 arch/arm64/Makefile                   |   7 +-
 arch/arm64/crypto/aes-modes.S         |   4 +-
 arch/arm64/crypto/aes-neonbs-core.S   |   8 +-
 arch/arm64/crypto/chacha-neon-core.S  |   9 +-
 arch/arm64/include/asm/assembler.h    |  32 ++-
 arch/arm64/include/asm/linkage.h      |  16 +-
 arch/arm64/kernel/Makefile            |   2 +
 arch/arm64/kernel/head.S              |   3 +
 arch/arm64/kernel/patch-scs.c         | 223 ++++++++++++++++++++
 arch/arm64/kernel/smccc-call.S        |  40 ++--
 arch/arm64/kernel/vmlinux.lds.S       |  20 ++
 arch/arm64/mm/cache.S                 |   8 +-
 drivers/firmware/efi/libstub/Makefile |   1 +
 16 files changed, 347 insertions(+), 45 deletions(-)
 create mode 100644 arch/arm64/kernel/patch-scs.c
Signature · 1 line
2.30.2