diff options
| author | Maxime Ripard <maxime@cerno.tech> | 2023-01-03 10:32:12 +0300 |
|---|---|---|
| committer | Maxime Ripard <maxime@cerno.tech> | 2023-01-03 10:32:12 +0300 |
| commit | 2c55d703391acf7e9101da596d0c15ee03b318a3 (patch) | |
| tree | 422ef671343624b56d333b47d20a538eeedbfe10 /include/linux/stackprotector.h | |
| parent | 92d43bd3bc9728c1fb114d7011d46f5ea9489e28 (diff) | |
| parent | 88603b6dc419445847923fcb7fe5080067a30f98 (diff) | |
| download | linux-2c55d703391acf7e9101da596d0c15ee03b318a3.tar.xz | |
Merge drm/drm-fixes into drm-misc-fixes
Let's start the fixes cycle.
Signed-off-by: Maxime Ripard <maxime@cerno.tech>
Diffstat (limited to 'include/linux/stackprotector.h')
| -rw-r--r-- | include/linux/stackprotector.h | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/include/linux/stackprotector.h b/include/linux/stackprotector.h index 4c678c4fec58..9c88707d9a0f 100644 --- a/include/linux/stackprotector.h +++ b/include/linux/stackprotector.h @@ -6,6 +6,25 @@ #include <linux/sched.h> #include <linux/random.h> +/* + * On 64-bit architectures, protect against non-terminated C string overflows + * by zeroing out the first byte of the canary; this leaves 56 bits of entropy. + */ +#ifdef CONFIG_64BIT +# ifdef __LITTLE_ENDIAN +# define CANARY_MASK 0xffffffffffffff00UL +# else /* big endian, 64 bits: */ +# define CANARY_MASK 0x00ffffffffffffffUL +# endif +#else /* 32 bits: */ +# define CANARY_MASK 0xffffffffUL +#endif + +static inline unsigned long get_random_canary(void) +{ + return get_random_long() & CANARY_MASK; +} + #if defined(CONFIG_STACKPROTECTOR) || defined(CONFIG_ARM64_PTR_AUTH) # include <asm/stackprotector.h> #else |
