Added stack guard

This commit is contained in:
Alex 2022-11-28 08:21:24 +02:00
parent 414662b24a
commit bc92258a5f
Signed by untrusted user who does not match committer: enderice2
GPG Key ID: EACC3AD603BAB4DD
2 changed files with 38 additions and 1 deletions

View File

@ -42,7 +42,7 @@ CFLAGS := \
ifeq ($(OSARCH), amd64)
CFLAGS += -fPIC -march=x86-64
CFLAGS += -fPIC -march=x86-64 -fstack-protector-all -fstack-clash-protection
else ifeq ($(OSARCH), i686)

37
apps/system/init/ssp.c Normal file
View File

@ -0,0 +1,37 @@
#ifndef STACK_CHK_GUARD_VALUE
#if UINTPTR_MAX == UINT32_MAX
#define STACK_CHK_GUARD_VALUE 0xDEAD57AC
#else
#define STACK_CHK_GUARD_VALUE 0xDEAD57AC00000000
#endif
#endif
__UINTPTR_TYPE__ __stack_chk_guard = 0;
static void __attribute__((constructor, no_stack_protector)) __guard_setup(void)
{
if (__stack_chk_guard == 0)
__stack_chk_guard = STACK_CHK_GUARD_VALUE;
}
__attribute__((weak, noreturn, no_stack_protector)) void __stack_chk_fail(void)
{
// const char *msg = "Stack smashing detected";
__asm__ __volatile__("syscall"
:
: "a"(0), "D"(0x57AC)
: "rcx", "r11", "memory");
while (1)
;
}
__attribute__((weak, noreturn, no_stack_protector)) void __chk_fail(void)
{
// const char *msg = "Buffer overflow detected";
__asm__ __volatile__("syscall"
:
: "a"(0), "D"(0xF700)
: "rcx", "r11", "memory");
while (1)
;
}