Exclude guard page from stack bounds check in initialize#13704
Merged
cfallin merged 1 commit intoJun 22, 2026
Conversation
Fix the bounds check in VMContinuationStack::initialize to compare against usable stack space rather than total allocation size. Prior to bytecodealliance#13662, initialize() had no bounds check at all, so a high-arity function type (e.g. 600 params on an 8192-byte stack) would unconditionally write control data into the guard page and segfault. PR bytecodealliance#13662 added a bounds check, but compared against self.len which for Mmap allocations includes the guard page. This meant the 600-param case still slipped through: 9664 <= 12288 passed the check, but the write still landed in the non-writable guard page. This fix subtracts the guard page size for Mmap allocations so the check reflects the actual usable stack space. Custom allocations are unaffected since their len does not include a guard page. Adds a regression test matching the exact scenario from bytecodealliance#13703 (600 params on an 8192-byte stack). Closes bytecodealliance#13703 Signed-off-by: Sebastien Tardif <sebtardif@ncf.ca>
cfallin
approved these changes
Jun 22, 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.
Fix the bounds check in
VMContinuationStack::initializeto compareagainst usable stack space rather than total allocation size.
Prior to #13662,
initialize()had no bounds check at all, so ahigh-arity function type (e.g. 600 params on an 8192-byte stack)
would unconditionally write control data into the guard page and
segfault. PR #13662 added a bounds check, but compared against
self.lenwhich for Mmap allocations includes the guard page. Thismeant the 600-param case still slipped through:
9664 <= 12288passed the check, but the write still landed in the non-writable
guard page.
This fix subtracts the guard page size for Mmap allocations so
the check reflects the actual usable stack space. Custom
allocations are unaffected since their
lendoes not include aguard page.
Adds a regression test matching the exact scenario from #13703
(600 params on an 8192-byte stack).
Closes #13703