diff options
| author | Felix Morgner <felix.morgner@ost.ch> | 2026-09-05 13:19:25 +0200 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@ost.ch> | 2026-09-05 13:19:25 +0200 |
| commit | 9f544dea5dbcdb92f614c6092a60e81d3398b8da (patch) | |
| tree | 2a7098a472b7ef45092c830850b1625492fa04f3 | |
| parent | c0b2173d6b6c4587d1df3e8ea992ee19c9ff4418 (diff) | |
| download | kernel-9f544dea5dbcdb92f614c6092a60e81d3398b8da.tar.xz kernel-9f544dea5dbcdb92f614c6092a60e81d3398b8da.zip | |
build: enable strong stack protector
| -rw-r--r-- | CMakeLists.txt | 1 | ||||
| -rw-r--r-- | arch/x86_64/arch/boot/initialize_runtime.cpp | 11 | ||||
| -rw-r--r-- | libs/kstd/CMakeLists.txt | 2 |
3 files changed, 14 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 34738e18..8f622050 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -76,6 +76,7 @@ add_compile_options( "$<$<CXX_COMPILER_ID:GNU>:-Wextra>" "$<$<CXX_COMPILER_ID:GNU>:-Werror>" "$<$<CXX_COMPILER_ID:GNU>:-pedantic-errors>" + "$<$<CXX_COMPILER_ID:GNU>:-fstack-protector-strong>" ) if(NOT BUILD_TESTING) diff --git a/arch/x86_64/arch/boot/initialize_runtime.cpp b/arch/x86_64/arch/boot/initialize_runtime.cpp index e548f4a1..ad2fa205 100644 --- a/arch/x86_64/arch/boot/initialize_runtime.cpp +++ b/arch/x86_64/arch/boot/initialize_runtime.cpp @@ -1,3 +1,5 @@ +#include <kapi/system.hpp> + #include <algorithm> #include <functional> #include <span> @@ -12,6 +14,15 @@ namespace arch::boot // NOLINTBEGIN(readability-identifier-naming) extern global_initializer __init_array_start; extern global_initializer __init_array_end; + + [[gnu::used]] + constinit auto __stack_chk_guard = 0xcafe'face'1ee7'8ee7; // NOLINT(readability-magic-numbers) + + [[noreturn]] + auto __stack_chk_fail() -> void + { + kapi::system::panic("Stack smashing detected!"); + } // NOLINTEND(readability-identifier-naming) auto invoke_global_constructors() -> void diff --git a/libs/kstd/CMakeLists.txt b/libs/kstd/CMakeLists.txt index 573fc8f2..1902d0d9 100644 --- a/libs/kstd/CMakeLists.txt +++ b/libs/kstd/CMakeLists.txt @@ -59,6 +59,8 @@ if(NOT BUILD_TESTING) "memcmp" "memcpy" "memset" + "__stack_chk_fail" + "__stack_chk_guard" ) list(TRANSFORM KSTD_LIBC_SYMBOLS PREPEND "-Wl,--undefined=") |
