mirror of
https://github.com/Fennix-Project/Kernel.git
synced 2025-05-28 15:34:33 +00:00
Better(?) stack guard
This commit is contained in:
parent
9fdad650b9
commit
11641b1ff3
@ -1,6 +1,8 @@
|
|||||||
#include <types.h>
|
#include <types.h>
|
||||||
#include <debug.h>
|
#include <debug.h>
|
||||||
|
|
||||||
|
#include "../kernel.h"
|
||||||
|
|
||||||
#ifndef STACK_CHK_GUARD_VALUE
|
#ifndef STACK_CHK_GUARD_VALUE
|
||||||
#if UINTPTR_MAX == UINT32_MAX
|
#if UINTPTR_MAX == UINT32_MAX
|
||||||
#define STACK_CHK_GUARD_VALUE 0x25F6CC8D
|
#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)
|
__attribute__((weak, noreturn, no_stack_protector)) void __stack_chk_fail(void)
|
||||||
{
|
{
|
||||||
error("Stack smashing detected!", false);
|
error("Stack smashing detected!");
|
||||||
for (;;)
|
KPrint("\eFF0000Stack smashing detected!");
|
||||||
{
|
|
||||||
#if defined(__amd64__) || defined(__i386__)
|
#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__)
|
#elif defined(__aarch64__)
|
||||||
asmv("wfe");
|
asmv("wfe");
|
||||||
#endif
|
#endif
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://github.com/gcc-mirror/gcc/blob/master/libssp/ssp.c
|
// https://github.com/gcc-mirror/gcc/blob/master/libssp/ssp.c
|
||||||
__attribute__((weak, noreturn, no_stack_protector)) void __chk_fail(void)
|
__attribute__((weak, noreturn, no_stack_protector)) void __chk_fail(void)
|
||||||
{
|
{
|
||||||
error("Buffer overflow detected!", false);
|
error("Buffer overflow detected!");
|
||||||
|
KPrint("\eFF0000Buffer overflow detected!");
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
#if defined(__amd64__) || defined(__i386__)
|
#if defined(__amd64__) || defined(__i386__)
|
||||||
asmv("hlt");
|
asmv("loop__chk_fail:\n"
|
||||||
|
"cli\n"
|
||||||
|
"hlt\n"
|
||||||
|
"jmp loop__chk_fail\n");
|
||||||
#elif defined(__aarch64__)
|
#elif defined(__aarch64__)
|
||||||
asmv("wfe");
|
asmv("wfe");
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user