feat: created initial stack smash protector
This commit is contained in:
29
kernel/util/ssp.c
Normal file
29
kernel/util/ssp.c
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user