kselftest/riscv: add kselftest for user mode CFIAdd a kselftest for RISC-V control flow integrity implementation foruser mode. There is not a lot going on in the kernel to enable landingpad for u
kselftest/riscv: add kselftest for user mode CFIAdd a kselftest for RISC-V control flow integrity implementation foruser mode. There is not a lot going on in the kernel to enable landingpad for user mode. CFI selftests are intended to be compiled with azicfilp and zicfiss enabled compiler. This kselftest simply checks iflanding pads and shadow stacks for the process are enabled or not andexecutes ptrace selftests on CFI. The selftest then registers aSIGSEGV signal handler. Any control flow violations are reported asSIGSEGV with si_code = SEGV_CPERR. The test will fail on receivingany SEGV_CPERR. The shadow stack part has more changes in the kernel,and thus there are separate tests for that.- Exercise 'map_shadow_stack' syscall- 'fork' test to make sure COW works for shadow stack pages- gup tests Kernel uses FOLL_FORCE when access happens to memory via /proc/<pid>/mem. Not breaking that for shadow stack.- signal test. Make sure signal delivery results in token creation on shadow stack and consumes (and verifies) token on sigreturn- shadow stack protection test. attempts to write using regular store instruction on shadow stack memory must result in access faults- ptrace test: adds landing pad violation, clears ELP and continuesIn case the toolchain doesn't support the CFI extension, the CFIkselftest won't be built.Test output==========="""TAP version 131..5 This is to ensure shadow stack is indeed enabled and working This is to ensure shadow stack is indeed enabled and workingok 1 shstk fork testok 2 map shadow stack syscallok 3 shadow stack gup testsok 4 shadow stack signal testsok 5 memory protections of shadow stack memory"""Suggested-by: Charlie Jenkins <charlie@rivosinc.com>Signed-off-by: Charlie Jenkins <charlie@rivosinc.com>Signed-off-by: Deepak Gupta <debug@rivosinc.com>Tested-by: Andreas Korb <andreas.korb@aisec.fraunhofer.de> # QEMU, custom CVA6Tested-by: Valentin Haudiquet <valentin.haudiquet@canonical.com>Link: https://patch.msgid.link/20251112-v5_user_cfi_series-v23-28-b55691eacf4f@rivosinc.com[pjw@kernel.org: updated to apply; cleaned up patch description, code comments]Signed-off-by: Paul Walmsley <pjw@kernel.org>
show more ...