1 /* SPDX-License-Identifier: GPL-2.0 */ 2 3 #ifndef _ASM_RISCV_STACKPROTECTOR_H 4 #define _ASM_RISCV_STACKPROTECTOR_H 5 6 #include <linux/random.h> 7 #include <linux/version.h> 8 9 extern unsigned long __stack_chk_guard; 10 11 /* 12 * Initialize the stackprotector canary value. 13 * 14 * NOTE: this must only be called from functions that never return, 15 * and it must always be inlined. 16 */ 17 static __always_inline void boot_init_stack_canary(void) 18 { 19 unsigned long canary; 20 21 /* Try to get a semi random initial value. */ 22 get_random_bytes(&canary, sizeof(canary)); 23 canary ^= LINUX_VERSION_CODE; 24 canary &= CANARY_MASK; 25 26 current->stack_canary = canary; 27 if (!IS_ENABLED(CONFIG_STACKPROTECTOR_PER_TASK)) 28 __stack_chk_guard = current->stack_canary; 29 } 30 #endif /* _ASM_RISCV_STACKPROTECTOR_H */ 31