stackprotector.h 788 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * GCC stack protector support.
  4. *
  5. */
  6. #ifndef _ASM_STACKPROTECTOR_H
  7. #define _ASM_STACKPROTECTOR_H
  8. #include <linux/random.h>
  9. #include <linux/version.h>
  10. #include <asm/reg.h>
  11. #include <asm/current.h>
  12. #include <asm/paca.h>
  13. /*
  14. * Initialize the stackprotector canary value.
  15. *
  16. * NOTE: this must only be called from functions that never return,
  17. * and it must always be inlined.
  18. */
  19. static __always_inline void boot_init_stack_canary(void)
  20. {
  21. unsigned long canary;
  22. /* Try to get a semi random initial value. */
  23. canary = get_random_canary();
  24. canary ^= mftb();
  25. canary ^= LINUX_VERSION_CODE;
  26. canary &= CANARY_MASK;
  27. current->stack_canary = canary;
  28. #ifdef CONFIG_PPC64
  29. get_paca()->canary = canary;
  30. #endif
  31. }
  32. #endif /* _ASM_STACKPROTECTOR_H */