2008-02-14 01:41:09 -07:00
|
|
|
#ifndef _ASM_STACKPROTECTOR_H
|
|
|
|
#define _ASM_STACKPROTECTOR_H 1
|
|
|
|
|
2009-02-09 06:17:39 -07:00
|
|
|
#ifdef CONFIG_CC_STACKPROTECTOR
|
|
|
|
|
2008-02-14 01:56:04 -07:00
|
|
|
#include <asm/tsc.h>
|
2009-01-18 20:21:28 -07:00
|
|
|
#include <asm/processor.h>
|
2009-02-09 06:17:39 -07:00
|
|
|
#include <asm/percpu.h>
|
|
|
|
#include <linux/random.h>
|
2008-02-14 01:56:04 -07:00
|
|
|
|
2008-02-14 01:42:02 -07:00
|
|
|
/*
|
|
|
|
* 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)
|
|
|
|
{
|
2008-02-14 01:56:04 -07:00
|
|
|
u64 canary;
|
|
|
|
u64 tsc;
|
|
|
|
|
2008-02-14 01:42:02 -07:00
|
|
|
/*
|
2009-01-19 20:29:19 -07:00
|
|
|
* Build time only check to make sure the stack_canary is at
|
|
|
|
* offset 40 in the pda; this is a gcc ABI requirement
|
|
|
|
*/
|
2009-01-18 20:21:28 -07:00
|
|
|
BUILD_BUG_ON(offsetof(union irq_stack_union, stack_canary) != 40);
|
2009-01-19 20:29:19 -07:00
|
|
|
|
|
|
|
/*
|
2008-02-14 01:56:04 -07:00
|
|
|
* 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.
|
2008-02-14 01:42:02 -07:00
|
|
|
*/
|
2008-02-14 01:56:04 -07:00
|
|
|
get_random_bytes(&canary, sizeof(canary));
|
|
|
|
tsc = __native_read_tsc();
|
|
|
|
canary += tsc + (tsc << 32UL);
|
|
|
|
|
|
|
|
current->stack_canary = canary;
|
2009-01-18 20:21:28 -07:00
|
|
|
percpu_write(irq_stack_union.stack_canary, canary);
|
2008-02-14 01:42:02 -07:00
|
|
|
}
|
|
|
|
|
2009-02-09 06:17:39 -07:00
|
|
|
#endif /* CC_STACKPROTECTOR */
|
|
|
|
#endif /* _ASM_STACKPROTECTOR_H */
|