1 /* $MirOS: src/sys/kern/init_ssp.c,v 1.6 2013/10/31 20:06:57 tg Exp $ */
2 
3 /*-
4  * Copyright (c) 2004, 2013
5  *	Thorsten "mirabilos" Glaser <tg@mirbsd.org>
6  * Copyright (c) by The OpenBSD Project.
7  *
8  * Provided that these terms and disclaimer and all copyright notices
9  * are retained or reproduced in an accompanying document, permission
10  * is granted to deal in this work without restriction, including un-
11  * limited rights to use, publicly perform, distribute, sell, modify,
12  * merge, give away, or sublicence.
13  *
14  * This work is provided "AS IS" and WITHOUT WARRANTY of any kind, to
15  * the utmost extent permitted by applicable law, neither express nor
16  * implied; without malicious intent or gross negligence. In no event
17  * may a licensor, author or contributor be held liable for indirect,
18  * direct, other damage, loss, or other issues arising in any way out
19  * of dealing in the work, even if advised of the possibility of such
20  * damage or existence of a defect, except proven that it results out
21  * of said person's immediate fault when using the work as intended.
22  */
23 
24 #ifdef __SSP_ALL__
25 #error "You must compile this file with -fno-stack-protector-all"
26 #endif
27 
28 #include <sys/param.h>
29 #include <sys/systm.h>
30 #include <dev/rndvar.h>
31 
32 void init_ssp(void);
33 #ifndef	NO_PROPOLICE
34 void __stack_smash_handler(char [], int);
35 #endif
36 
37 #define GUARDLEN 8
38 
39 #ifndef	NO_PROPOLICE
40 long __guard[GUARDLEN];
41 #endif
42 
43 void
init_ssp(void)44 init_ssp(void)
45 {
46 #ifndef	NO_PROPOLICE
47 	long tmp[GUARDLEN];
48 	int i = GUARDLEN;
49 
50 	/*
51 	 * this is so arc4random_buf does not
52 	 * cause a kernel panic for smashing...
53 	 */
54 	arc4random_buf(tmp, sizeof(tmp));
55 	while (i--)
56 		__guard[i] = tmp[i];
57 #endif
58 }
59 
60 #ifndef	NO_PROPOLICE
61 __dead void
__stack_smash_handler(char func[],int damaged)62 __stack_smash_handler(char func[], int damaged __attribute__((__unused__)))
63 {
64 	panic("ProPolice: kernel stack smashed in %s", func);
65 }
66 #endif
67