feat: created initial stack smash protector

This commit is contained in:
2021-03-15 19:21:46 +01:00
parent 3d08828e8d
commit 513693189e
5 changed files with 40 additions and 3 deletions

29
kernel/util/ssp.c Normal file
View File

@@ -0,0 +1,29 @@
//
// Created by rick on 15-03-21.
//
// stack smashing protector
#include <stdint.h>
#if __STDC_HOSTED__
#include <stdlib.h>
#else
#include <myke/libk/libk.h>
#endif
#if UINT32_MAX == UINTPTR_MAX
#define STACK_CHK_GUARD 0xe2dee396
#else
#define STACK_CHK_GUARD 0x595e9fbd94fda766
#endif
// todo this value should be unique every time the kernel starts
uintptr_t __stack_chk_guard = STACK_CHK_GUARD;
void __attribute__((__noreturn__)) __stack_chk_fail(void) {
#if __STDC_HOSTED__
#error "UNKNONONO"
abort();
#else
k_panics("Stack Smashed!");
#endif
}