1234567891011121314151617181920212223242526272829303132333435363738 |
- #ifndef _ASM_STACKPROTECTOR_H
- #define _ASM_STACKPROTECTOR_H 1
- #include <asm/tsc.h>
- #include <asm/pda.h>
- /*
- * Initialize the stackprotector canary value.
- *
- * NOTE: this must only be called from functions that never return,
- * and it must always be inlined.
- */
- static __always_inline void boot_init_stack_canary(void)
- {
- u64 canary;
- u64 tsc;
- /*
- * Build time only check to make sure the stack_canary is at
- * offset 40 in the pda; this is a gcc ABI requirement
- */
- BUILD_BUG_ON(offsetof(struct x8664_pda, stack_canary) != 40);
- /*
- * We both use the random pool and the current TSC as a source
- * of randomness. The TSC only matters for very early init,
- * there it already has some randomness on most systems. Later
- * on during the bootup the random pool has true entropy too.
- */
- get_random_bytes(&canary, sizeof(canary));
- tsc = __native_read_tsc();
- canary += tsc + (tsc << 32UL);
- current->stack_canary = canary;
- write_pda(stack_canary, canary);
- }
- #endif
|