fix(runtime): pass a reset type, not a reason, to reset_system - #36
Merged
srpatcha merged 1 commit intoAug 27, 2026
Merged
Conversation
…_fail __stack_chk_fail called eos_rtsvc_reset_system(EOS_RESET_SOFTWARE). That constant belongs to eos_reset_reason_t, which reports why a reset already happened, while the parameter is an eos_reset_type_t, which selects the reset to perform. The two enums overlap numerically: EOS_RESET_SOFTWARE is 2, and 2 is EOS_RESET_HALT in the parameter's enum. The call is therefore a request to halt, not to reset, which is the opposite of what the comment above it states. eos_rtsvc_reset_system currently discards its type argument, so the defect is latent today. It becomes live as soon as any platform honors the parameter, and would then turn stack-smashing detection into a permanent halt instead of a recoverable reset. Pass EOS_RESET_COLD, and promote -Wenum-conversion to an error on GCC/Clang so the mistake cannot be reintroduced. That warning had exactly one occurrence in the tree, this one, so the flag is clean everywhere else. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
sunnyrishy
requested review from
hshanmug12,
maheshmunnangi and
srpatcha
as code owners
August 26, 2026 02:17
srpatcha
approved these changes
Aug 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
__stack_chk_fail, the handler that runs when the stack protector detectsmemory corruption, asks the system to halt rather than to reset. It does
this by passing a constant from the wrong enum. The comment directly above the
call says "Trigger immediate system reset", so the code does the opposite of
its stated intent.
Type of Change
Changes
core/runtime_services.c— passEOS_RESET_COLDinstead ofEOS_RESET_SOFTWAREfrom__stack_chk_fail, and document why the two enumsmust not be mixed.
CMakeLists.txt— promote-Wenum-conversionto-Werror=enum-conversionon GCC/Clang so this class of mistake cannot come back.
The defect
There are two reset enums, and they overlap numerically:
eos_reset_reason_t(include/eos_types.h)EOS_RESET_SOFTWAREeos_reset_type_t(include/eos_runtime_svc.h)EOS_RESET_HALTeos_rtsvc_reset_system()takes aneos_reset_type_t. The call passedEOS_RESET_SOFTWARE, a reason. Because both are 2, it silently becomes arequest to halt.
For a secure bootloader this inverts the security response: detecting a
stack-smashing attempt should reset into a controlled boot path, but halting
leaves the device wedged until someone power-cycles it — a detected attack
becomes a denial of service.
GCC had been reporting this the whole time; it was one warning among the ~9 the
native build emits, so it went unread:
Approach
The one-line correction is passing the right constant. The more useful half is
making the mistake impossible to repeat:
-Werror=enum-conversionturns anyfuture cross-enum pass into a hard build failure.
I checked before enabling it —
enum-conversionhad exactly one occurrencein the entire tree, the one fixed here, so the flag is clean everywhere else and
does not force unrelated churn.
The flag is scoped to native GCC/Clang builds (
NOT CMAKE_CROSSCOMPILING),deliberately. CI cross-compiles for ARM Cortex-M4, and I have no ARM toolchain
locally, so I am not willing to promote warnings to errors in board code I have
not actually compiled — that is how a guard turns into a broken pipeline. Native
builds cover
core/andhal/, the platform-agnostic code where this class ofmistake arises and where this defect lived, so the guard still catches exactly
what it needs to. MSVC has no equivalent flag, so the MSVC job is unaffected.
If maintainers with the cross toolchains in hand confirm the board tree is
clean, widening this to cross builds is a one-word change.
Testing
ctest --test-dir build --output-on-failure)Native build, GCC 15.2 (MinGW-w64),
-DEBLDR_BUILD_TESTS=ON:enum-conversionwarning. After: 0.test_recovery, which fails to link (undefined reference to eos_boot_log_get_head/eos_boot_log_append). That is pre-existing andunrelated — it is already addressed by fix: link eboot_stage1 into test_recovery #35.
Verifying the guard actually guards — reintroducing the old constant now breaks
the build rather than warning:
Considerations and limitations
eos_rtsvc_reset_system()currentlydoes
(void)type;and ignores its argument on every platform, so nothingmisbehaves at runtime right now. I want to be precise about that rather than
overstate the impact. It goes live the moment any platform honors the
parameter — which the enum's own
COLD/WARM/HALTvalues clearlyanticipate — and it would then be a silent, security-relevant wrong action in
the hardest place to debug one.
typehandling. Makingeos_rtsvc_reset_system()actually distinguish cold/warm/halt is per-platform work that cannot be
validated on a host build, so it belongs in its own change. Happy to open a
follow-up issue if that is wanted.
EOS_RESET_*prefix for different concepts remains alatent trap. A rename (e.g.
EOS_RESET_REASON_*) would remove the ambiguityat the source, but it is a public-header API break, so I kept this PR to the
defect plus the compiler guard rather than bundling it.
Pre-Submission Checklist
enum-conversionwarning in the tree. Other pre-existing warnings (unused variables in
ed25519_verify.c, unused parameters inboot_menu.c) are untouched andout of scope here.
test_recoveryfails to link on master and is already addressed by fix: link eboot_stage1 into test_recovery #35.
-Werrorguard is theregression test; reintroducing the defect now fails the build.
<type>(<scope>): <description>Related Issues
None.
test_recovery's link failure seen during validation is unrelated andalready covered by #35.