1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */ 236ecafc5SGregory Fong /* 336ecafc5SGregory Fong * GCC stack protector support. 436ecafc5SGregory Fong * 536ecafc5SGregory Fong * (This is directly adopted from the ARM implementation) 636ecafc5SGregory Fong * 736ecafc5SGregory Fong * Stack protector works by putting predefined pattern at the start of 836ecafc5SGregory Fong * the stack frame and verifying that it hasn't been overwritten when 936ecafc5SGregory Fong * returning from the function. The pattern is called stack canary 1036ecafc5SGregory Fong * and gcc expects it to be defined by a global variable called 1136ecafc5SGregory Fong * "__stack_chk_guard" on MIPS. This unfortunately means that on SMP 1236ecafc5SGregory Fong * we cannot have a different canary value per task. 1336ecafc5SGregory Fong */ 1436ecafc5SGregory Fong 1536ecafc5SGregory Fong #ifndef _ASM_STACKPROTECTOR_H 1636ecafc5SGregory Fong #define _ASM_STACKPROTECTOR_H 1 1736ecafc5SGregory Fong 1836ecafc5SGregory Fong extern unsigned long __stack_chk_guard; 1936ecafc5SGregory Fong 2036ecafc5SGregory Fong /* 2136ecafc5SGregory Fong * Initialize the stackprotector canary value. 2236ecafc5SGregory Fong * 2336ecafc5SGregory Fong * NOTE: this must only be called from functions that never return, 2436ecafc5SGregory Fong * and it must always be inlined. 2536ecafc5SGregory Fong */ boot_init_stack_canary(void)2636ecafc5SGregory Fongstatic __always_inline void boot_init_stack_canary(void) 2736ecafc5SGregory Fong { 28*622754e8SJason A. Donenfeld unsigned long canary = get_random_canary(); 2936ecafc5SGregory Fong 3036ecafc5SGregory Fong current->stack_canary = canary; 3136ecafc5SGregory Fong __stack_chk_guard = current->stack_canary; 3236ecafc5SGregory Fong } 3336ecafc5SGregory Fong 3436ecafc5SGregory Fong #endif /* _ASM_STACKPROTECTOR_H */ 35