Skip to content

Conversation

@jserv
Copy link
Collaborator

@jserv jserv commented Oct 30, 2025

This implements canary-based stack overflow detection for hart coroutine to catch stack corruption before it leads to undefined behavior.

The implementation provides immediate detection of stack corruption with minimal performance cost.


Summary by cubic

Adds canary-based stack overflow detection for hart coroutines. The canary is checked before and after resuming a coroutine to catch corruption early.

  • New Features
    • Place the canary at the bottom of each coroutine stack buffer and initialize it in coro_create_hart.
    • Adjust usable stack bounds to skip the canary when creating the context.
    • On mismatch, print a fatal message and abort. Minimal overhead.

Written for commit 5093626. Summary will update automatically on new commits.

Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 1 file

Prompt for AI agents (all 1 issues)

Understand the root cause of the following 1 issues and fix them.


<file name="coro.c">

<violation number="1" location="coro.c:251">
`coro_check_stack` only compares the `coro_t` struct field, so an actual stack overflow past the coroutine stack memory will never flip this value and the detection cannot trigger. Store the canary in the stack buffer itself and verify that sentinel instead.</violation>
</file>

React with 👍 or 👎 to teach cubic. Mention @cubic-dev-ai to give feedback, ask questions, or re-run the review.

Implement canary-based stack overflow detection for hart coroutines
to catch stack corruption before it leads to undefined behavior.

The canary is placed at the bottom of the stack buffer itself (not in
the coro_t structure), so actual stack overflow will corrupt it and
trigger detection.

The implementation provides immediate detection of stack corruption
with minimal performance cost. Validated with Linux boot test and
unit tests confirming canary is in the actual stack buffer.
@jserv jserv merged commit bb10925 into master Oct 30, 2025
10 checks passed
@jserv jserv deleted the coro-safety branch October 30, 2025 09:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants