1*c743f380SNicolas Pitre /* 2*c743f380SNicolas Pitre * GCC stack protector support. 3*c743f380SNicolas Pitre * 4*c743f380SNicolas Pitre * Stack protector works by putting predefined pattern at the start of 5*c743f380SNicolas Pitre * the stack frame and verifying that it hasn't been overwritten when 6*c743f380SNicolas Pitre * returning from the function. The pattern is called stack canary 7*c743f380SNicolas Pitre * and gcc expects it to be defined by a global variable called 8*c743f380SNicolas Pitre * "__stack_chk_guard" on ARM. This unfortunately means that on SMP 9*c743f380SNicolas Pitre * we cannot have a different canary value per task. 10*c743f380SNicolas Pitre */ 11*c743f380SNicolas Pitre 12*c743f380SNicolas Pitre #ifndef _ASM_STACKPROTECTOR_H 13*c743f380SNicolas Pitre #define _ASM_STACKPROTECTOR_H 1 14*c743f380SNicolas Pitre 15*c743f380SNicolas Pitre #include <linux/random.h> 16*c743f380SNicolas Pitre #include <linux/version.h> 17*c743f380SNicolas Pitre 18*c743f380SNicolas Pitre extern unsigned long __stack_chk_guard; 19*c743f380SNicolas Pitre 20*c743f380SNicolas Pitre /* 21*c743f380SNicolas Pitre * Initialize the stackprotector canary value. 22*c743f380SNicolas Pitre * 23*c743f380SNicolas Pitre * NOTE: this must only be called from functions that never return, 24*c743f380SNicolas Pitre * and it must always be inlined. 25*c743f380SNicolas Pitre */ 26*c743f380SNicolas Pitre static __always_inline void boot_init_stack_canary(void) 27*c743f380SNicolas Pitre { 28*c743f380SNicolas Pitre unsigned long canary; 29*c743f380SNicolas Pitre 30*c743f380SNicolas Pitre /* Try to get a semi random initial value. */ 31*c743f380SNicolas Pitre get_random_bytes(&canary, sizeof(canary)); 32*c743f380SNicolas Pitre canary ^= LINUX_VERSION_CODE; 33*c743f380SNicolas Pitre 34*c743f380SNicolas Pitre current->stack_canary = canary; 35*c743f380SNicolas Pitre __stack_chk_guard = current->stack_canary; 36*c743f380SNicolas Pitre } 37*c743f380SNicolas Pitre 38*c743f380SNicolas Pitre #endif /* _ASM_STACKPROTECTOR_H */ 39