forked from Bananymous/banan-os
Implement Stack Smashing Protection
This commit is contained in:
parent
7ad8189e24
commit
db656fe469
|
@ -13,7 +13,7 @@ EXEC_PREFIX?=$(PREFIX)
|
||||||
BOOTDIR?=$(EXEC_PREFIX)/boot
|
BOOTDIR?=$(EXEC_PREFIX)/boot
|
||||||
INCLUDEDIR?=$(PREFIX)/include
|
INCLUDEDIR?=$(PREFIX)/include
|
||||||
|
|
||||||
CFLAGS:=$(CFLAGS) -ffreestanding -Wall -Wextra
|
CFLAGS:=$(CFLAGS) -fstack-protector -ffreestanding -Wall -Wextra
|
||||||
CPPFLAGS:=$(CPPFLAGS) -D__is_kernel -Iinclude
|
CPPFLAGS:=$(CPPFLAGS) -D__is_kernel -Iinclude
|
||||||
LDFLAGS:=$(LDFLAGS)
|
LDFLAGS:=$(LDFLAGS)
|
||||||
LIBS:=$(LIBS) -nostdlib -lk -lgcc
|
LIBS:=$(LIBS) -nostdlib -lk -lgcc
|
||||||
|
@ -30,6 +30,7 @@ LIBS:=$(LIBS) $(KERNEL_ARCH_LIBS)
|
||||||
KERNEL_OBJS=\
|
KERNEL_OBJS=\
|
||||||
$(KERNEL_ARCH_OBJS) \
|
$(KERNEL_ARCH_OBJS) \
|
||||||
kernel/kernel.o \
|
kernel/kernel.o \
|
||||||
|
kernel/ssp.o \
|
||||||
|
|
||||||
OBJS=\
|
OBJS=\
|
||||||
$(ARCHDIR)/crti.o \
|
$(ARCHDIR)/crti.o \
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.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)
|
||||||
|
{
|
||||||
|
printf("Stack smashing detected\n");
|
||||||
|
abort();
|
||||||
|
}
|
Loading…
Reference in New Issue