Kumar Gala | d12d8af | 2016-10-05 12:01:54 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2012-2014 Wind River Systems, Inc. |
| 3 | * |
David B. Kinder | ac74d8b | 2017-01-18 17:01:01 -0800 | [diff] [blame] | 4 | * SPDX-License-Identifier: Apache-2.0 |
Kumar Gala | d12d8af | 2016-10-05 12:01:54 -0500 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | /** |
| 8 | * @file |
| 9 | * @brief Compiler stack protection (kernel part) |
| 10 | * |
| 11 | * This module provides functions to support compiler stack protection |
| 12 | * using canaries. This feature is enabled with configuration |
| 13 | * CONFIG_STACK_CANARIES=y. |
| 14 | * |
| 15 | * When this feature is enabled, the compiler generated code refers to |
| 16 | * function __stack_chk_fail and global variable __stack_chk_guard. |
| 17 | */ |
| 18 | |
| 19 | #include <toolchain.h> /* compiler specific configurations */ |
| 20 | |
Benjamin Walsh | f6ca7de | 2016-11-08 10:36:50 -0500 | [diff] [blame] | 21 | #include <kernel_structs.h> |
Kumar Gala | d12d8af | 2016-10-05 12:01:54 -0500 | [diff] [blame] | 22 | #include <toolchain.h> |
| 23 | #include <sections.h> |
| 24 | |
| 25 | /** |
| 26 | * |
| 27 | * @brief Stack canary error handler |
| 28 | * |
| 29 | * This function is invoked when a stack canary error is detected. |
| 30 | * |
| 31 | * @return Does not return |
| 32 | */ |
| 33 | void FUNC_NORETURN _StackCheckHandler(void) |
| 34 | { |
| 35 | /* Stack canary error is a software fatal condition; treat it as such. |
| 36 | */ |
| 37 | |
| 38 | _NanoFatalErrorHandler(_NANO_ERR_STACK_CHK_FAIL, &_default_esf); |
| 39 | } |
| 40 | |
| 41 | /* Global variable */ |
| 42 | |
| 43 | /* |
| 44 | * Symbol referenced by GCC compiler generated code for canary value. |
| 45 | * The canary value gets initialized in _Cstart(). |
| 46 | */ |
| 47 | void __noinit *__stack_chk_guard; |
| 48 | |
| 49 | /** |
| 50 | * |
| 51 | * @brief Referenced by GCC compiler generated code |
| 52 | * |
| 53 | * This routine is invoked when a stack canary error is detected, indicating |
| 54 | * a buffer overflow or stack corruption problem. |
| 55 | */ |
| 56 | FUNC_ALIAS(_StackCheckHandler, __stack_chk_fail, void); |