140d1a07bSMax Filippov /* 240d1a07bSMax Filippov * GCC stack protector support. 340d1a07bSMax Filippov * 440d1a07bSMax Filippov * (This is directly adopted from the ARM implementation) 540d1a07bSMax Filippov * 640d1a07bSMax Filippov * Stack protector works by putting predefined pattern at the start of 740d1a07bSMax Filippov * the stack frame and verifying that it hasn't been overwritten when 840d1a07bSMax Filippov * returning from the function. The pattern is called stack canary 940d1a07bSMax Filippov * and gcc expects it to be defined by a global variable called 1040d1a07bSMax Filippov * "__stack_chk_guard" on Xtensa. This unfortunately means that on SMP 1140d1a07bSMax Filippov * we cannot have a different canary value per task. 1240d1a07bSMax Filippov */ 1340d1a07bSMax Filippov 1440d1a07bSMax Filippov #ifndef _ASM_STACKPROTECTOR_H 1540d1a07bSMax Filippov #define _ASM_STACKPROTECTOR_H 1 1640d1a07bSMax Filippov 1740d1a07bSMax Filippov extern unsigned long __stack_chk_guard; 1840d1a07bSMax Filippov 1940d1a07bSMax Filippov /* 2040d1a07bSMax Filippov * Initialize the stackprotector canary value. 2140d1a07bSMax Filippov * 2240d1a07bSMax Filippov * NOTE: this must only be called from functions that never return, 2340d1a07bSMax Filippov * and it must always be inlined. 2440d1a07bSMax Filippov */ boot_init_stack_canary(void)2540d1a07bSMax Filippovstatic __always_inline void boot_init_stack_canary(void) 2640d1a07bSMax Filippov { 27*622754e8SJason A. Donenfeld unsigned long canary = get_random_canary(); 2840d1a07bSMax Filippov 2940d1a07bSMax Filippov current->stack_canary = canary; 3040d1a07bSMax Filippov __stack_chk_guard = current->stack_canary; 3140d1a07bSMax Filippov } 3240d1a07bSMax Filippov 3340d1a07bSMax Filippov #endif /* _ASM_STACKPROTECTOR_H */ 34