Skip to content

Commit

Permalink
Kernel+LibC: Build with basic -fstack-protector support
Browse files Browse the repository at this point in the history
Use simple stack cookies to try to provoke an assertion failure on
stack overflow.

This is far from perfect, since we use a constant cookie instead of
generating a random one on startup, but it can still help us catch
bugs, which is the primary concern right now. :^)
  • Loading branch information
awesomekling committed Dec 20, 2019
1 parent f006e66 commit 842716a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
8 changes: 8 additions & 0 deletions Kernel/StdLib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,12 @@ void free(void* p)
{
return kfree(p);
}

extern u32 __stack_chk_guard;
u32 __stack_chk_guard = (u32)0xc0000c13;

[[noreturn]] void __stack_chk_fail()
{
ASSERT_NOT_REACHED();
}
}
9 changes: 9 additions & 0 deletions Libraries/LibC/crt0.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <AK/Types.h>
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
Expand Down Expand Up @@ -51,4 +52,12 @@ int _start(int argc, char** argv, char** env)
void __cxa_atexit()
{
}

extern u32 __stack_chk_guard;
u32 __stack_chk_guard = (u32)0xc0000c13;

[[noreturn]] void __stack_chk_fail()
{
ASSERT_NOT_REACHED();
}
}
2 changes: 1 addition & 1 deletion Makefile.common
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ARCH_FLAGS =
STANDARD_FLAGS = -std=c++17 -Wno-sized-deallocation -fno-sized-deallocation
WARNING_FLAGS = -Werror -Wextra -Wall -Wno-nonnull-compare -Wno-deprecated-copy -Wno-address-of-packed-member -Wundef -Wcast-qual -Wwrite-strings -Wimplicit-fallthrough -Wno-expansion-to-defined
FLAVOR_FLAGS = -fno-exceptions -fno-rtti
FLAVOR_FLAGS = -fno-exceptions -fno-rtti -fstack-protector
OPTIMIZATION_FLAGS = -Os

MAKEFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST)))
Expand Down

0 comments on commit 842716a

Please sign in to comment.