1 /* SPDX-License-Identifier: GPL-2.0 2 * Copyright (C) 2024 Rivos, Inc. 3 * Deepak Gupta <debug@rivosinc.com> 4 */ 5 #ifndef _ASM_RISCV_USERCFI_H 6 #define _ASM_RISCV_USERCFI_H 7 8 #ifndef __ASSEMBLER__ 9 #include <linux/types.h> 10 #include <linux/prctl.h> 11 12 struct task_struct; 13 struct kernel_clone_args; 14 15 #ifdef CONFIG_RISCV_USER_CFI 16 struct cfi_state { 17 unsigned long ubcfi_en : 1; /* Enable for backward cfi. */ 18 unsigned long ubcfi_locked : 1; 19 unsigned long ufcfi_en : 1; /* Enable for forward cfi. Note that ELP goes in sstatus */ 20 unsigned long ufcfi_locked : 1; 21 unsigned long user_shdw_stk; /* Current user shadow stack pointer */ 22 unsigned long shdw_stk_base; /* Base address of shadow stack */ 23 unsigned long shdw_stk_size; /* size of shadow stack */ 24 }; 25 26 unsigned long shstk_alloc_thread_stack(struct task_struct *tsk, 27 const struct kernel_clone_args *args); 28 void shstk_release(struct task_struct *tsk); 29 void set_shstk_base(struct task_struct *task, unsigned long shstk_addr, unsigned long size); 30 unsigned long get_shstk_base(struct task_struct *task, unsigned long *size); 31 void set_active_shstk(struct task_struct *task, unsigned long shstk_addr); 32 bool is_shstk_enabled(struct task_struct *task); 33 bool is_shstk_locked(struct task_struct *task); 34 bool is_shstk_allocated(struct task_struct *task); 35 void set_shstk_lock(struct task_struct *task); 36 void set_shstk_status(struct task_struct *task, bool enable); 37 bool is_indir_lp_enabled(struct task_struct *task); 38 bool is_indir_lp_locked(struct task_struct *task); 39 void set_indir_lp_status(struct task_struct *task, bool enable); 40 void set_indir_lp_lock(struct task_struct *task); 41 42 #define PR_SHADOW_STACK_SUPPORTED_STATUS_MASK (PR_SHADOW_STACK_ENABLE) 43 44 #else 45 46 #define shstk_alloc_thread_stack(tsk, args) 0 47 48 #define shstk_release(tsk) 49 50 #define get_shstk_base(task, size) 0UL 51 52 #define set_shstk_base(task, shstk_addr, size) do {} while (0) 53 54 #define set_active_shstk(task, shstk_addr) do {} while (0) 55 56 #define is_shstk_enabled(task) false 57 58 #define is_shstk_locked(task) false 59 60 #define is_shstk_allocated(task) false 61 62 #define set_shstk_lock(task) do {} while (0) 63 64 #define set_shstk_status(task, enable) do {} while (0) 65 66 #define is_indir_lp_enabled(task) false 67 68 #define is_indir_lp_locked(task) false 69 70 #define set_indir_lp_status(task, enable) do {} while (0) 71 72 #define set_indir_lp_lock(task) do {} while (0) 73 74 #endif /* CONFIG_RISCV_USER_CFI */ 75 76 #endif /* __ASSEMBLER__ */ 77 78 #endif /* _ASM_RISCV_USERCFI_H */ 79