Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,20 @@ elseif(CMAKE_C_COMPILER_ID MATCHES "GNU|Clang")
add_compile_options(-Wall -Wextra)
endif()

# Mixing up the reset enums is a security-relevant error rather than a style
# nit: eos_reset_reason_t (why a reset happened) and eos_reset_type_t (which
# reset to perform) overlap numerically, so passing one where the other is
# expected silently selects the wrong action. Promote that specific diagnostic
# to an error so it cannot be reintroduced.
#
# Scoped to native GCC/Clang builds. That covers core/ and hal/, the
# platform-agnostic code where this class of mistake actually occurs, without
# promoting warnings to errors in per-board cross builds whose sources are not
# compiled here. MSVC has no equivalent flag.
if(NOT CMAKE_CROSSCOMPILING AND CMAKE_C_COMPILER_ID MATCHES "GNU|Clang")
add_compile_options(-Werror=enum-conversion)
endif()

# Security hardening flags
if(EBLDR_HARDENING AND CMAKE_C_COMPILER_ID MATCHES "GNU|Clang")
add_compile_options(-fstack-protector-strong -D_FORTIFY_SOURCE=2)
Expand Down
9 changes: 7 additions & 2 deletions core/runtime_services.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,13 @@ void __stack_chk_fail(void)
#ifdef EBOOT_ENABLE_PRINTF
printf("FATAL: stack smashing detected\n");
#endif
/* Trigger immediate system reset */
eos_rtsvc_reset_system(EOS_RESET_SOFTWARE);
/* Trigger immediate system reset.
* EOS_RESET_COLD is an eos_reset_type_t (the reset *action* to perform).
* Do not pass eos_reset_reason_t values such as EOS_RESET_SOFTWARE here:
* that enum reports why a reset already happened, and its value 2 aliases
* onto EOS_RESET_HALT, which would halt the device instead of resetting
* it. */
eos_rtsvc_reset_system(EOS_RESET_COLD);
while (1); /* unreachable */
}

Expand Down