2008-06-25 21:33:28 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/libkern.h>
|
|
|
|
|
|
|
|
long __stack_chk_guard[8] = {};
|
|
|
|
void __stack_chk_fail(void);
|
|
|
|
|
|
|
|
void
|
|
|
|
__stack_chk_fail(void)
|
|
|
|
{
|
|
|
|
|
|
|
|
panic("stack overflow detected; backtrace may be corrupted");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
__stack_chk_init(void *dummy __unused)
|
|
|
|
{
|
|
|
|
size_t i;
|
2015-06-16 20:19:00 +00:00
|
|
|
long guard[nitems(__stack_chk_guard)];
|
2008-06-25 21:33:28 +00:00
|
|
|
|
2019-05-13 23:37:44 +00:00
|
|
|
arc4rand(guard, sizeof(guard), 0);
|
|
|
|
for (i = 0; i < nitems(guard); i++)
|
|
|
|
__stack_chk_guard[i] = guard[i];
|
2008-06-25 21:33:28 +00:00
|
|
|
}
|
2009-10-20 16:36:51 +00:00
|
|
|
SYSINIT(stack_chk, SI_SUB_RANDOM, SI_ORDER_ANY, __stack_chk_init, NULL);
|