arm64: implement dynamic shadow call stack for Clang
authorArd Biesheuvel <ardb@kernel.org>
Thu, 27 Oct 2022 15:59:08 +0000 (17:59 +0200)
committerWill Deacon <will@kernel.org>
Wed, 9 Nov 2022 18:06:35 +0000 (18:06 +0000)
commit3b619e22c4601b444ed2d6a5458271f72625ac89
tree1f4754b78c6302a14322f629b72a6f195d8dd58e
parent9beccca0984022a844850e32f0d7dd80d4a225de
arm64: implement dynamic shadow call stack for Clang

Implement dynamic shadow call stack support on Clang, by parsing the
unwind tables at init time to locate all occurrences of PACIASP/AUTIASP
instructions, and replacing them with the shadow call stack push and pop
instructions, respectively.

This is useful because the overhead of the shadow call stack is
difficult to justify on hardware that implements pointer authentication
(PAC), and given that the PAC instructions are executed as NOPs on
hardware that doesn't, we can just replace them without breaking
anything. As PACIASP/AUTIASP are guaranteed to be paired with respect to
manipulations of the return address, replacing them 1:1 with shadow call
stack pushes and pops is guaranteed to result in the desired behavior.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Reviewed-by: Sami Tolvanen <samitolvanen@google.com>
Tested-by: Sami Tolvanen <samitolvanen@google.com>
Link: https://lore.kernel.org/r/20221027155908.1940624-4-ardb@kernel.org
Signed-off-by: Will Deacon <will@kernel.org>
arch/arm64/Kconfig
arch/arm64/Makefile
arch/arm64/include/asm/scs.h
arch/arm64/kernel/Makefile
arch/arm64/kernel/head.S
arch/arm64/kernel/irq.c
arch/arm64/kernel/module.c
arch/arm64/kernel/patch-scs.c [new file with mode: 0644]
arch/arm64/kernel/sdei.c
arch/arm64/kernel/setup.c