mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-11-16 13:55:04 +00:00
Add stack protector implementation for RISC-V architecture using a global __stack_chk_guard variable. This differs from x86 which uses per-CPU stack canaries. Tracked-On: #8834 Signed-off-by: Jian Jun Chen <jian.jun.chen@intel.com> Reviewed-by: Fei Li <fei1.li@intel.com> Acked-by: Wang, Yu1 <yu1.wang@intel.com>
33 lines
667 B
C
33 lines
667 B
C
/*
|
|
* Copyright (C) 2023-2025 Intel Corporation.
|
|
*
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
*/
|
|
|
|
#ifndef RISCV_SECURITY_H
|
|
#define RISCV_SECURITY_H
|
|
|
|
#ifdef STACK_PROTECTOR
|
|
#include <random.h>
|
|
#endif
|
|
|
|
#ifdef STACK_PROTECTOR
|
|
|
|
extern unsigned long __stack_chk_guard;
|
|
|
|
/*
|
|
* Initialize the stack protector __stack_chk_guard.
|
|
*
|
|
* NOTE: this function changes the __stack_chk_guard,
|
|
* - It must only be called from functions that never return
|
|
* - It must always be inlined itself
|
|
*/
|
|
static inline __attribute__((__always_inline__)) void init_stack_canary(void)
|
|
{
|
|
__stack_chk_guard = get_random_value();
|
|
}
|
|
|
|
#endif /* STACK_PROTECTOR */
|
|
|
|
#endif /* RISCV_SECURITY_H */
|