diff options
-rw-r--r-- | doc/LINKS.TODO | 3 | ||||
-rw-r--r-- | src/Makefile | 1 | ||||
-rw-r--r-- | src/kernel/kernel.c | 18 | ||||
-rw-r--r-- | src/kernel/kernel.h | 11 | ||||
-rw-r--r-- | src/libc/stdint.h | 4 | ||||
-rw-r--r-- | tests/libc/Makefile | 4 | ||||
-rw-r--r-- | tests/libc/kernel_stub.c | 7 | ||||
-rw-r--r-- | tests/libc/kernel_stub.h | 9 |
8 files changed, 55 insertions, 2 deletions
diff --git a/doc/LINKS.TODO b/doc/LINKS.TODO index 89f7ce8..968ff6d 100644 --- a/doc/LINKS.TODO +++ b/doc/LINKS.TODO @@ -102,3 +102,6 @@ https://stackoverflow.com/questions/26143123/how-do-i-ensure-the-entry-function- Linux: https://blog.packagecloud.io/eng/2016/04/05/the-definitive-guide-to-linux-system-calls/ + +Security: +http://wiki.osdev.org/Stack_Smashing_Protector diff --git a/src/Makefile b/src/Makefile index b4ceff1..3c2849e 100644 --- a/src/Makefile +++ b/src/Makefile @@ -3,6 +3,7 @@ DEFINES = -DOS_ABAOS INCLUDES = -I. -Ilibc -Ihardware -Idrivers -Idrivers/hdi -Idrivers/hdi/ps2 -Idrivers/video -Ikernel -Igui CFLAGS := -std=c99 -m32 -march=i486 -ffreestanding -O0 -g -Werror $(INCLUDES) $(DEFINES) LD := ld +LDFLAGS := -lgcc NASMFLAGS := -f elf32 NASM := nasm OBJCOPY := objcopy diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c index a472cde..be5da7c 100644 --- a/src/kernel/kernel.c +++ b/src/kernel/kernel.c @@ -419,4 +419,22 @@ static void print_memory_status( global_context_t *global_context ) } +uintptr_t __stack_chk_guard = STACK_CHK_GUARD; +__attribute__( ( noreturn ) ) +void __stack_chk_fail_local( void ) +{ + kernel_panic( "Stack smashing detected!" ); + + // make gcc happy on noreturn does return + for( ;; ); +} + +__attribute__( ( noreturn ) ) +void __stack_chk_fail( void ) +{ + kernel_panic( "Stack smashing detected!" ); + + // make gcc happy on noreturn does return + for( ;; ); +} diff --git a/src/kernel/kernel.h b/src/kernel/kernel.h index dc23fd6..87733c8 100644 --- a/src/kernel/kernel.h +++ b/src/kernel/kernel.h @@ -1,10 +1,21 @@ #ifndef KERNEL_H #define KERNEL_H +#include "stdint.h" #include "stdio.h" void kernel_main( void ); void kernel_panic( const char *format, ... ); void kernel_halt( void ); +#define STACK_CHK_GUARD 0xe2dee396 + +extern uintptr_t __stack_chk_guard; + +__attribute__( ( noreturn ) ) +void __stack_chk_fail_local( void ); + +__attribute__( ( noreturn ) ) +void __stack_chk_fail( void ); + #endif // KERNEL_H diff --git a/src/libc/stdint.h b/src/libc/stdint.h index e0f35b6..23dc370 100644 --- a/src/libc/stdint.h +++ b/src/libc/stdint.h @@ -10,6 +10,10 @@ typedef unsigned short uint16_t; typedef signed short int16_t; typedef unsigned char uint8_t; typedef signed char int8_t; +typedef uint32_t uintptr_t; +#else +// gcc and clang provide a stdint.h +#include_next <stdint.h> #endif #endif // STDINT_H diff --git a/tests/libc/Makefile b/tests/libc/Makefile index d9d2927..2d89940 100644 --- a/tests/libc/Makefile +++ b/tests/libc/Makefile @@ -2,8 +2,8 @@ CC := gcc DEFINES = -DOS_LINUX INCLUDES = -I. -I../../src/libc -I../../src/kernel -I/home/abaumann/cross-compilers/include CFLAGS := -std=c99 -m32 -ffreestanding -O0 -g -Wall -Werror $(INCLUDES) $(DEFINES) -LD := ld -LDFLAGS := +LD := $(CC) +LDFLAGS := NASMFLAGS := -f elf32 NASM := nasm diff --git a/tests/libc/kernel_stub.c b/tests/libc/kernel_stub.c index 610c3d3..cacab34 100644 --- a/tests/libc/kernel_stub.c +++ b/tests/libc/kernel_stub.c @@ -22,3 +22,10 @@ void kernel_panic( const char *format, ... ) exit( 255 ); } +uintptr_t __stack_chk_guard = STACK_CHK_GUARD; + +__attribute__( ( noreturn ) ) +void __stack_chk_fail_local( void ) +{ + abort( ); +} diff --git a/tests/libc/kernel_stub.h b/tests/libc/kernel_stub.h index 467ad20..65047f9 100644 --- a/tests/libc/kernel_stub.h +++ b/tests/libc/kernel_stub.h @@ -24,4 +24,13 @@ long syscall1( long n, long a1 ); long syscall2( long n, long a1, long a2 ); long syscall3( long n, long a1, long a2, long a3 ); +// SSP stub, we don't want to link against libssp + +#include <stdint.h> +#include <stdlib.h> + +#define STACK_CHK_GUARD 0xe2dee396 + +extern uintptr_t __stack_chk_guard; + #endif |