Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Filippo Arcidiacono | 5d920bb | 2012-04-19 15:45:57 +0900 | [diff] [blame] | 2 | #ifndef __ASM_SH_STACKPROTECTOR_H |
| 3 | #define __ASM_SH_STACKPROTECTOR_H |
| 4 | |
| 5 | #include <linux/random.h> |
| 6 | #include <linux/version.h> |
| 7 | |
| 8 | extern unsigned long __stack_chk_guard; |
| 9 | |
| 10 | /* |
| 11 | * Initialize the stackprotector canary value. |
| 12 | * |
| 13 | * NOTE: this must only be called from functions that never return, |
| 14 | * and it must always be inlined. |
| 15 | */ |
| 16 | static __always_inline void boot_init_stack_canary(void) |
| 17 | { |
| 18 | unsigned long canary; |
| 19 | |
| 20 | /* Try to get a semi random initial value. */ |
| 21 | get_random_bytes(&canary, sizeof(canary)); |
| 22 | canary ^= LINUX_VERSION_CODE; |
Rik van Riel | 2c8340e | 2017-07-12 14:36:29 -0700 | [diff] [blame] | 23 | canary &= CANARY_MASK; |
Filippo Arcidiacono | 5d920bb | 2012-04-19 15:45:57 +0900 | [diff] [blame] | 24 | |
| 25 | current->stack_canary = canary; |
| 26 | __stack_chk_guard = current->stack_canary; |
| 27 | } |
| 28 | |
| 29 | #endif /* __ASM_SH_STACKPROTECTOR_H */ |