2016-10-06 01:01:54 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2012-2014 Wind River Systems, Inc.
|
|
|
|
*
|
2017-01-19 09:01:01 +08:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2016-10-06 01:01:54 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* @brief Compiler stack protection (kernel part)
|
|
|
|
*
|
|
|
|
* This module provides functions to support compiler stack protection
|
|
|
|
* using canaries. This feature is enabled with configuration
|
|
|
|
* CONFIG_STACK_CANARIES=y.
|
|
|
|
*
|
|
|
|
* When this feature is enabled, the compiler generated code refers to
|
|
|
|
* function __stack_chk_fail and global variable __stack_chk_guard.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <toolchain.h> /* compiler specific configurations */
|
|
|
|
|
2016-11-08 23:36:50 +08:00
|
|
|
#include <kernel_structs.h>
|
2016-10-06 01:01:54 +08:00
|
|
|
#include <toolchain.h>
|
2017-06-17 23:30:47 +08:00
|
|
|
#include <linker/sections.h>
|
2017-04-19 06:22:05 +08:00
|
|
|
#include <kernel.h>
|
2016-10-06 01:01:54 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @brief Stack canary error handler
|
|
|
|
*
|
|
|
|
* This function is invoked when a stack canary error is detected.
|
|
|
|
*
|
|
|
|
* @return Does not return
|
|
|
|
*/
|
|
|
|
void FUNC_NORETURN _StackCheckHandler(void)
|
|
|
|
{
|
|
|
|
/* Stack canary error is a software fatal condition; treat it as such.
|
|
|
|
*/
|
2017-04-19 06:22:05 +08:00
|
|
|
_k_except_reason(_NANO_ERR_STACK_CHK_FAIL);
|
2016-10-06 01:01:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Global variable */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Symbol referenced by GCC compiler generated code for canary value.
|
|
|
|
* The canary value gets initialized in _Cstart().
|
|
|
|
*/
|
|
|
|
void __noinit *__stack_chk_guard;
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @brief Referenced by GCC compiler generated code
|
|
|
|
*
|
|
|
|
* This routine is invoked when a stack canary error is detected, indicating
|
|
|
|
* a buffer overflow or stack corruption problem.
|
|
|
|
*/
|
|
|
|
FUNC_ALIAS(_StackCheckHandler, __stack_chk_fail, void);
|