1 /* SPDX-License-Identifier: GPL-2.0 */
3 #ifndef _ASM_RISCV_STACKPROTECTOR_H
4 #define _ASM_RISCV_STACKPROTECTOR_H
6 #include <linux/random.h>
7 #include <linux/version.h>
9 extern unsigned long __stack_chk_guard
;
12 * Initialize the stackprotector canary value.
14 * NOTE: this must only be called from functions that never return,
15 * and it must always be inlined.
17 static __always_inline
void boot_init_stack_canary(void)
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
;
26 current
->stack_canary
= canary
;
27 __stack_chk_guard
= current
->stack_canary
;
29 #endif /* _ASM_RISCV_STACKPROTECTOR_H */