Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * GCC stack protector support.
0004  *
0005  * (This is directly adopted from the ARM implementation)
0006  *
0007  * Stack protector works by putting predefined pattern at the start of
0008  * the stack frame and verifying that it hasn't been overwritten when
0009  * returning from the function.  The pattern is called stack canary
0010  * and gcc expects it to be defined by a global variable called
0011  * "__stack_chk_guard" on MIPS.  This unfortunately means that on SMP
0012  * we cannot have a different canary value per task.
0013  */
0014 
0015 #ifndef _ASM_STACKPROTECTOR_H
0016 #define _ASM_STACKPROTECTOR_H 1
0017 
0018 #include <linux/random.h>
0019 #include <linux/version.h>
0020 
0021 extern unsigned long __stack_chk_guard;
0022 
0023 /*
0024  * Initialize the stackprotector canary value.
0025  *
0026  * NOTE: this must only be called from functions that never return,
0027  * and it must always be inlined.
0028  */
0029 static __always_inline void boot_init_stack_canary(void)
0030 {
0031     unsigned long canary;
0032 
0033     /* Try to get a semi random initial value. */
0034     get_random_bytes(&canary, sizeof(canary));
0035     canary ^= LINUX_VERSION_CODE;
0036 
0037     current->stack_canary = canary;
0038     __stack_chk_guard = current->stack_canary;
0039 }
0040 
0041 #endif  /* _ASM_STACKPROTECTOR_H */