• Sami Tolvanen's avatar
    riscv: Implement syscall wrappers · 08d0ce30
    Sami Tolvanen authored
    Commit f0bddf50 ("riscv: entry: Convert to generic entry") moved
    syscall handling to C code, which exposed function pointer type
    mismatches that trip fine-grained forward-edge Control-Flow Integrity
    (CFI) checks as syscall handlers are all called through the same
    syscall_t pointer type. To fix the type mismatches, implement pt_regs
    based syscall wrappers similarly to x86 and arm64.
    
    This patch is based on arm64 syscall wrappers added in commit
    4378a7d4 ("arm64: implement syscall wrappers"), where the main goal
    was to minimize the risk of userspace-controlled values being used
    under speculation. This may be a concern for riscv in future as well.
    
    Following other architectures, the syscall wrappers generate three
    functions for each syscall; __riscv_<compat_>sys_<name> takes a pt_regs
    pointer and extracts arguments from registers, __se_<compat_>sys_<name>
    is a sign-extension wrapper that casts the long arguments to the
    correct types for the real syscall implementation, which is named
    __do_<compat_>sys_<name>.
    Reviewed-by: default avatarKees Cook <keescook@chromium.org>
    Tested-by: default avatarNathan Chancellor <nathan@kernel.org>
    Signed-off-by: default avatarSami Tolvanen <samitolvanen@google.com>
    Link: https://lore.kernel.org/r/20230710183544.999540-9-samitolvanen@google.comSigned-off-by: default avatarPalmer Dabbelt <palmer@rivosinc.com>
    08d0ce30
sys_riscv.c 8.49 KB