Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * GCC stack protector support.
0004  *
0005  */
0006 
0007 #ifndef _ASM_STACKPROTECTOR_H
0008 #define _ASM_STACKPROTECTOR_H
0009 
0010 #include <linux/random.h>
0011 #include <linux/version.h>
0012 #include <asm/reg.h>
0013 #include <asm/current.h>
0014 #include <asm/paca.h>
0015 
0016 /*
0017  * Initialize the stackprotector canary value.
0018  *
0019  * NOTE: this must only be called from functions that never return,
0020  * and it must always be inlined.
0021  */
0022 static __always_inline void boot_init_stack_canary(void)
0023 {
0024     unsigned long canary;
0025 
0026     /* Try to get a semi random initial value. */
0027     canary = get_random_canary();
0028     canary ^= mftb();
0029     canary ^= LINUX_VERSION_CODE;
0030     canary &= CANARY_MASK;
0031 
0032     current->stack_canary = canary;
0033 #ifdef CONFIG_PPC64
0034     get_paca()->canary = canary;
0035 #endif
0036 }
0037 
0038 #endif  /* _ASM_STACKPROTECTOR_H */