1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _LINUX_STACKPROTECTOR_H
3 #define _LINUX_STACKPROTECTOR_H 1
5 #include <linux/compiler.h>
6 #include <linux/sched.h>
7 #include <linux/random.h>
10 * On 64-bit architectures, protect against non-terminated C string overflows
11 * by zeroing out the first byte of the canary; this leaves 56 bits of entropy.
14 # ifdef __LITTLE_ENDIAN
15 # define CANARY_MASK 0xffffffffffffff00UL
16 # else /* big endian, 64 bits: */
17 # define CANARY_MASK 0x00ffffffffffffffUL
20 # define CANARY_MASK 0xffffffffUL
23 static inline unsigned long get_random_canary(void)
25 return get_random_long() & CANARY_MASK
;
28 #if defined(CONFIG_STACKPROTECTOR) || defined(CONFIG_ARM64_PTR_AUTH)
29 # include <asm/stackprotector.h>
31 static inline void boot_init_stack_canary(void)