Libc: add stack smashing protection, moved kernel panic from abort to panic function in stdlib
This commit is contained in:
parent
e839ac8a3f
commit
99888ea24d
|
@ -13,7 +13,7 @@ EXEC_PREFIX?=$(PREFIX)
|
|||
BOOTDIR?=$(EXEC_PREFIX)/boot
|
||||
INCLUDEDIR?=$(PREFIX)/include
|
||||
|
||||
CFLAGS:=$(CFLAGS) -ffreestanding -Wall -Wextra
|
||||
CFLAGS:=$(CFLAGS) -ffreestanding -Wall -Wextra -fstack-protector-all
|
||||
CPPFLAGS:=$(CPPFLAGS) -D__is_kernel -Iinclude
|
||||
LDFLAGS:=$(LDFLAGS)
|
||||
LIBS:=$(LIBS) -nostdlib -lk -lgcc
|
||||
|
|
|
@ -33,6 +33,8 @@ stdio/printf.o \
|
|||
stdio/putchar.o \
|
||||
stdio/puts.o \
|
||||
stdlib/abort.o \
|
||||
stdlib/panic.o \
|
||||
stdlib/stack_protection.o \
|
||||
string/memcmp.o \
|
||||
string/memcpy.o \
|
||||
string/memmove.o \
|
||||
|
|
|
@ -9,6 +9,7 @@ extern "C" {
|
|||
|
||||
__attribute__((__noreturn__))
|
||||
void abort(void);
|
||||
void panic(char *panic_msg);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -5,11 +5,9 @@ __attribute__((__noreturn__))
|
|||
void abort(void) {
|
||||
#if defined(__is_libk)
|
||||
// TODO: Add proper kernel panic.
|
||||
printf("kernel: panic: abort()\n");
|
||||
panic("abort()\n");
|
||||
#else
|
||||
// TODO: Abnormally terminate the process as if by SIGABRT.
|
||||
printf("abort()\n");
|
||||
#endif
|
||||
while (1) { }
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
__attribute__((__noreturn__))
|
||||
void panic(char *panic_msg) {
|
||||
#if defined(__is_libk)
|
||||
// TODO: Add proper kernel panic.
|
||||
printf("kernel: panic: %s\n", panic_msg);
|
||||
#endif
|
||||
while (1) { }
|
||||
__builtin_unreachable();
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#if UINT32_MAX == UINTPTR_MAX
|
||||
#define STACK_CHK_GUARD 0xe2dee396
|
||||
#else
|
||||
#define STACK_CHK_GUARD 0x595e9fbd94fda766
|
||||
#endif
|
||||
|
||||
uintptr_t __stack_chk_guard = STACK_CHK_GUARD;
|
||||
|
||||
__attribute__((noreturn))
|
||||
void __stack_chk_fail(void)
|
||||
{
|
||||
#if __STDC_HOSTED__
|
||||
abort();
|
||||
#elif __is_myos_kernel
|
||||
panic("Stack smashing detected");
|
||||
#endif
|
||||
}
|
Loading…
Reference in New Issue