diff --git a/Kernel/CMakeLists.txt b/Kernel/CMakeLists.txt index 09239729923..74bb9cb5d7b 100644 --- a/Kernel/CMakeLists.txt +++ b/Kernel/CMakeLists.txt @@ -495,6 +495,18 @@ add_compile_options(-fno-exceptions) # FIXME: remove -nodefaultlibs after the next toolchain update add_compile_options(-nodefaultlibs -nostdlib) +# Auto initialize trivial types on the stack, we use "pattern" as +# it's the only option portable across compilers going forward. +# +# This is designed to help avoid uninitialized variables bugs and +# information disclosures coming from the kernel stack. +# +# FIXME: It appears to conflict with something during the boot of the +# aarch64 kernel, we should investigate and remove this special case. +if (NOT "${SERENITY_ARCH}" STREQUAL "aarch64") + add_compile_options(-ftrivial-auto-var-init=pattern) +endif() + if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") # Apply any flags that are only available on >= GCC 11.1 if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "11.1")