Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef _ASM_STACKPROTECTOR_H
0003 #define _ASM_STACKPROTECTOR_H 1
0004 
0005 #include <linux/random.h>
0006 #include <linux/version.h>
0007 
0008 extern unsigned long __stack_chk_guard;
0009 
0010 /*
0011  * Initialize the stackprotector canary value.
0012  *
0013  * NOTE: this must only be called from functions that never return,
0014  * and it must always be inlined.
0015  */
0016 static __always_inline void boot_init_stack_canary(void)
0017 {
0018     unsigned long canary;
0019 
0020     /* Try to get a semi random initial value. */
0021     get_random_bytes(&canary, sizeof(canary));
0022     canary ^= LINUX_VERSION_CODE;
0023     canary &= CANARY_MASK;
0024 
0025     current->stack_canary = canary;
0026     __stack_chk_guard = current->stack_canary;
0027 }
0028 
0029 #endif /* __ASM_SH_STACKPROTECTOR_H */