1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */ 2c0c264aeSLaura Abbott /* 3c0c264aeSLaura Abbott * GCC stack protector support. 4c0c264aeSLaura Abbott * 5c0c264aeSLaura Abbott * Stack protector works by putting predefined pattern at the start of 6c0c264aeSLaura Abbott * the stack frame and verifying that it hasn't been overwritten when 7c0c264aeSLaura Abbott * returning from the function. The pattern is called stack canary 8c0c264aeSLaura Abbott * and gcc expects it to be defined by a global variable called 9c0c264aeSLaura Abbott * "__stack_chk_guard" on ARM. This unfortunately means that on SMP 10c0c264aeSLaura Abbott * we cannot have a different canary value per task. 11c0c264aeSLaura Abbott */ 12c0c264aeSLaura Abbott 13c0c264aeSLaura Abbott #ifndef __ASM_STACKPROTECTOR_H 14c0c264aeSLaura Abbott #define __ASM_STACKPROTECTOR_H 15c0c264aeSLaura Abbott 1628321582SAmit Daniel Kachhap #include <asm/pointer_auth.h> 17c0c264aeSLaura Abbott 18c0c264aeSLaura Abbott extern unsigned long __stack_chk_guard; 19c0c264aeSLaura Abbott 20c0c264aeSLaura Abbott /* 21c0c264aeSLaura Abbott * Initialize the stackprotector canary value. 22c0c264aeSLaura Abbott * 23c0c264aeSLaura Abbott * NOTE: this must only be called from functions that never return, 24c0c264aeSLaura Abbott * and it must always be inlined. 25c0c264aeSLaura Abbott */ boot_init_stack_canary(void)26c0c264aeSLaura Abbottstatic __always_inline void boot_init_stack_canary(void) 27c0c264aeSLaura Abbott { 2828321582SAmit Daniel Kachhap #if defined(CONFIG_STACKPROTECTOR) 29*622754e8SJason A. Donenfeld unsigned long canary = get_random_canary(); 30c0c264aeSLaura Abbott 31c0c264aeSLaura Abbott current->stack_canary = canary; 320a1213faSArd Biesheuvel if (!IS_ENABLED(CONFIG_STACKPROTECTOR_PER_TASK)) 33c0c264aeSLaura Abbott __stack_chk_guard = current->stack_canary; 3428321582SAmit Daniel Kachhap #endif 3528321582SAmit Daniel Kachhap ptrauth_thread_init_kernel(current); 3628321582SAmit Daniel Kachhap ptrauth_thread_switch_kernel(current); 377f624085SSrinivas Ramana ptrauth_enable(); 38c0c264aeSLaura Abbott } 39c0c264aeSLaura Abbott 40c0c264aeSLaura Abbott #endif /* _ASM_STACKPROTECTOR_H */ 41