feat: created initial stack smash protector
This commit is contained in:
@@ -10,7 +10,7 @@ SET(CMAKE_ASM_COMPILER ${COMPILER_RT}/i686-elf-gcc)
|
||||
#SET(CMAKE_VERBOSE_MAKEFILE ON)
|
||||
|
||||
# Set compile flags
|
||||
SET(CMAKE_C_FLAGS "-g -ffreestanding -Wall -Wextra -fno-exceptions -fno-stack-protector -fno-pie -m32")
|
||||
SET(CMAKE_C_FLAGS "-g -ffreestanding -Wall -Wextra -fno-exceptions -fstack-protector -fno-pie -m32")
|
||||
SET(CMAKE_ASM_FLAGS "${CFLAGS} -m32 -x assembler-with-cpp")
|
||||
SET(CMAKE_EXE_LINKER_FLAGS "-T${CMAKE_CURRENT_LIST_DIR}/linker.ld -lgcc -ffreestanding -nostdlib -no-pie")
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
#error "Userspace not implemented"
|
||||
#endif
|
||||
|
||||
void abort();
|
||||
void __attribute__((__noreturn__)) abort();
|
||||
|
||||
int atexit(void (*)(void));
|
||||
|
||||
|
||||
@@ -54,6 +54,8 @@ void explode(const char *args);
|
||||
|
||||
void exec_self_test(const char *args);
|
||||
|
||||
void smash(const char *args);
|
||||
|
||||
#endif
|
||||
|
||||
cmd_handler cmd_handlers[] = {
|
||||
@@ -65,10 +67,16 @@ cmd_handler cmd_handlers[] = {
|
||||
{"explode", explode},
|
||||
#ifdef ENABLE_SELF_TEST
|
||||
{"self-test", exec_self_test},
|
||||
{"smash", smash},
|
||||
#endif
|
||||
{NULL, NULL},
|
||||
};
|
||||
|
||||
void smash(const char* args) {
|
||||
char data[16];
|
||||
memset(data, 'A', 32);
|
||||
}
|
||||
|
||||
void exec_self_test(const char *args) {
|
||||
self_test();
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ void test_string() {
|
||||
assert_array_all_entries(array_b, 0, 8);
|
||||
assert_array_all_entries(array_b + 8, 1, 8);
|
||||
memcpy(array_b + 8, array_a, 8);
|
||||
assert_array_all_entries(array_b + 8, 0, 16);
|
||||
assert_array_all_entries(array_b, 0, 16);
|
||||
|
||||
// strlen
|
||||
assert_int(3, strlen("abc"));
|
||||
|
||||
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