Better(?) stack guard

This commit is contained in:
Alex 2022-11-17 03:32:38 +02:00
parent 9fdad650b9
commit 11641b1ff3
Signed by untrusted user who does not match committer: enderice2
GPG Key ID: EACC3AD603BAB4DD

View File

@ -1,6 +1,8 @@
#include <types.h>
#include <debug.h>
#include "../kernel.h"
#ifndef STACK_CHK_GUARD_VALUE
#if UINTPTR_MAX == UINT32_MAX
#define STACK_CHK_GUARD_VALUE 0x25F6CC8D
@ -32,25 +34,30 @@ static void __attribute__((constructor, no_stack_protector)) __construct_stk_chk
__attribute__((weak, noreturn, no_stack_protector)) void __stack_chk_fail(void)
{
error("Stack smashing detected!", false);
for (;;)
{
error("Stack smashing detected!");
KPrint("\eFF0000Stack smashing detected!");
#if defined(__amd64__) || defined(__i386__)
asmv("hlt");
asmv("loop__stack_chk_fail:\n"
"cli\n"
"hlt\n"
"jmp loop__stack_chk_fail\n");
#elif defined(__aarch64__)
asmv("wfe");
asmv("wfe");
#endif
}
}
// https://github.com/gcc-mirror/gcc/blob/master/libssp/ssp.c
__attribute__((weak, noreturn, no_stack_protector)) void __chk_fail(void)
{
error("Buffer overflow detected!", false);
error("Buffer overflow detected!");
KPrint("\eFF0000Buffer overflow detected!");
for (;;)
{
#if defined(__amd64__) || defined(__i386__)
asmv("hlt");
asmv("loop__chk_fail:\n"
"cli\n"
"hlt\n"
"jmp loop__chk_fail\n");
#elif defined(__aarch64__)
asmv("wfe");
#endif