mirror of
https://github.com/xen-project/xen.git
synced 2026-10-28 18:21:39 +01:00
Both GCC and Clang support -fstack-protector feature, which add stack canaries to functions where stack corruption is possible. This patch makes general preparations to enable this feature on different supported architectures: - Added CONFIG_HAS_STACK_PROTECTOR option so each architecture can enable this feature individually - Added user-selectable CONFIG_STACK_PROTECTOR option - Implemented code that sets up random stack canary and a basic handler for stack protector failures Stack guard value is initialized in two phases: 1. Pre-defined randomly-selected value. 2. Own implementation of linear congruent random number generator. It relies on get_cycles() being available very early. If get_cycles() returns zero, it would leave pre-defined value from the previous step. boot_stack_chk_guard_setup() is declared as always_inline to ensure that it will not trigger stack protector by itself. And of course, caller should ensure that stack protection code will not be reached later. It is possible to call the same function from an ASM code by introducing simple trampoline in stack-protector.c, but right now there is no use case for such trampoline. As __stack_chk_fail() is not called by Xen source code directly, and only called by compiler-generated code, it does not needed to be declared separately. So we need separate MISRA deviation for it. Signed-off-by: Volodymyr Babchuk <volodymyr_babchuk@epam.com> Reviewed-by: Jan Beulich <jbeulich@suse.com>