1 /* SPDX-License-Identifier: GPL-2.0 */ 1 /* SPDX-License-Identifier: GPL-2.0 */ 2 #ifndef _LINUX_STACKPROTECTOR_H 2 #ifndef _LINUX_STACKPROTECTOR_H 3 #define _LINUX_STACKPROTECTOR_H 1 3 #define _LINUX_STACKPROTECTOR_H 1 4 4 5 #include <linux/compiler.h> 5 #include <linux/compiler.h> 6 #include <linux/sched.h> 6 #include <linux/sched.h> 7 #include <linux/random.h> 7 #include <linux/random.h> 8 8 9 /* 9 /* 10 * On 64-bit architectures, protect against no 10 * On 64-bit architectures, protect against non-terminated C string overflows 11 * by zeroing out the first byte of the canary 11 * by zeroing out the first byte of the canary; this leaves 56 bits of entropy. 12 */ 12 */ 13 #ifdef CONFIG_64BIT 13 #ifdef CONFIG_64BIT 14 # ifdef __LITTLE_ENDIAN 14 # ifdef __LITTLE_ENDIAN 15 # define CANARY_MASK 0xffffffffffffff00UL 15 # define CANARY_MASK 0xffffffffffffff00UL 16 # else /* big endian, 64 bits: */ 16 # else /* big endian, 64 bits: */ 17 # define CANARY_MASK 0x00ffffffffffffffUL 17 # define CANARY_MASK 0x00ffffffffffffffUL 18 # endif 18 # endif 19 #else /* 32 bits: */ 19 #else /* 32 bits: */ 20 # define CANARY_MASK 0xffffffffUL 20 # define CANARY_MASK 0xffffffffUL 21 #endif 21 #endif 22 22 23 static inline unsigned long get_random_canary( 23 static inline unsigned long get_random_canary(void) 24 { 24 { 25 return get_random_long() & CANARY_MASK 25 return get_random_long() & CANARY_MASK; 26 } 26 } 27 27 28 #if defined(CONFIG_STACKPROTECTOR) || defined( 28 #if defined(CONFIG_STACKPROTECTOR) || defined(CONFIG_ARM64_PTR_AUTH) 29 # include <asm/stackprotector.h> 29 # include <asm/stackprotector.h> 30 #else 30 #else 31 static inline void boot_init_stack_canary(void 31 static inline void boot_init_stack_canary(void) 32 { 32 { 33 } 33 } 34 #endif 34 #endif 35 35 36 #endif 36 #endif 37 37
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.