riscv: Implement Shadow Call Stack
authorSami Tolvanen <samitolvanen@google.com>
Wed, 27 Sep 2023 22:48:02 +0000 (22:48 +0000)
committerPalmer Dabbelt <palmer@rivosinc.com>
Fri, 27 Oct 2023 21:43:08 +0000 (14:43 -0700)
commitd1584d791a297aa8ed93503382a682a6ecfc4218
tree371b56adbd1d77f436e143555ab9fb47b4ad50c0
parente609b4f4252a2ad2454736078693571b9fbff019
riscv: Implement Shadow Call Stack

Implement CONFIG_SHADOW_CALL_STACK for RISC-V. When enabled, the
compiler injects instructions to all non-leaf C functions to
store the return address to the shadow stack and unconditionally
load it again before returning, which makes it harder to corrupt
the return address through a stack overflow, for example.

The active shadow call stack pointer is stored in the gp
register, which makes SCS incompatible with gp relaxation. Use
--no-relax-gp to ensure gp relaxation is disabled and disable
global pointer loading.  Add SCS pointers to struct thread_info,
implement SCS initialization, and task switching

Signed-off-by: Sami Tolvanen <samitolvanen@google.com>
Tested-by: Nathan Chancellor <nathan@kernel.org>
Link: https://lore.kernel.org/r/20230927224757.1154247-12-samitolvanen@google.com
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
arch/riscv/Kconfig
arch/riscv/Makefile
arch/riscv/include/asm/asm.h
arch/riscv/include/asm/scs.h [new file with mode: 0644]
arch/riscv/include/asm/thread_info.h
arch/riscv/kernel/asm-offsets.c
arch/riscv/kernel/entry.S
arch/riscv/kernel/head.S
arch/riscv/kernel/vdso/Makefile
arch/riscv/purgatory/Makefile