stackprotector.h 711 B

123456789101112131415161718192021222324252627282930
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __ASM_SH_STACKPROTECTOR_H
  3. #define __ASM_SH_STACKPROTECTOR_H
  4. #include <linux/random.h>
  5. #include <linux/version.h>
  6. extern unsigned long __stack_chk_guard;
  7. /*
  8. * Initialize the stackprotector canary value.
  9. *
  10. * NOTE: this must only be called from functions that never return,
  11. * and it must always be inlined.
  12. */
  13. static __always_inline void boot_init_stack_canary(void)
  14. {
  15. unsigned long canary;
  16. /* Try to get a semi random initial value. */
  17. get_random_bytes(&canary, sizeof(canary));
  18. canary ^= LINUX_VERSION_CODE;
  19. canary &= CANARY_MASK;
  20. current->stack_canary = canary;
  21. __stack_chk_guard = current->stack_canary;
  22. }
  23. #endif /* __ASM_SH_STACKPROTECTOR_H */