summaryrefslogtreecommitdiff
path: root/userspace
diff options
context:
space:
mode:
authorMichal Idziorek <m.i@gmx.at>2014-11-25 12:22:35 +0100
committerMichal Idziorek <m.i@gmx.at>2014-11-25 12:22:35 +0100
commit6ec747105bfa8d52aca77bc577268f1944b19585 (patch)
tree1b4ae560171f8779079e13c2616f301b1d3d90b9 /userspace
parentbad8fa17adf4d9609343fe86feabe05188023bc1 (diff)
started adding stack shmashing protection
Diffstat (limited to 'userspace')
-rw-r--r--userspace/Makefile1
-rw-r--r--userspace/sys/sys.c24
2 files changed, 25 insertions, 0 deletions
diff --git a/userspace/Makefile b/userspace/Makefile
index 63310bf..6c6d711 100644
--- a/userspace/Makefile
+++ b/userspace/Makefile
@@ -1,6 +1,7 @@
CC=i686-foolos-gcc
CFLAGS=
+#CFLAGS+=-fstack-protector-all
CFLAGS+=-I..
CFLAGS+=-w
CFLAGS+=-std=gnu11
diff --git a/userspace/sys/sys.c b/userspace/sys/sys.c
index ef0d1df..1ab3579 100644
--- a/userspace/sys/sys.c
+++ b/userspace/sys/sys.c
@@ -3,6 +3,30 @@
#include <sys/stat.h>
+// CODE FOR Stack Smashing Protector, TODO: MOVE / and do not duplicate
+// with kernel.c
+// http://wiki.osdev.org/Stack_Smashing_Protector
+#include <stdint.h>
+#include <stdlib.h>
+
+#if UINT32_MAX == UINTPTR_MAX
+#define STACK_CHK_GUARD 0xe2dee396
+#else
+#define STACK_CHK_GUARD 0x595e9fbd94fda766
+#endif
+
+uintptr_t __stack_chk_guard = STACK_CHK_GUARD;
+
+__attribute__((noreturn))
+void __stack_chk_fail(void)
+{
+ write(1,"stack smashing!\n",16);
+ exit(99);
+}
+
+
+///////////////////
+
// required by binutils!
long sysconf(int name)