Fix off-by-one in aot_alloc_tiny_frame overflow check#4845
Open
sumleo wants to merge 2 commits intobytecodealliance:mainfrom
Open
Fix off-by-one in aot_alloc_tiny_frame overflow check#4845sumleo wants to merge 2 commits intobytecodealliance:mainfrom
sumleo wants to merge 2 commits intobytecodealliance:mainfrom
Conversation
The boundary check in aot_alloc_tiny_frame only verifies that new_frame itself doesn't exceed top_boundary, but doesn't account for the sizeof(AOTTinyFrame) bytes that are about to be written. When new_frame equals top_boundary exactly, the check passes but the subsequent write to new_frame->func_index goes past the boundary. This matches the correct pattern used in aot_alloc_frame (line 4086) which includes the frame size.
Break the overflow check condition across two lines to stay within the 80-column limit enforced by clang-format.
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
The boundary check in
aot_alloc_tiny_frame(core/iwasm/aot/aot_runtime.c, line 4179) only verifies thatnew_frameitself doesn't exceedtop_boundary, but doesn't account for thesizeof(AOTTinyFrame)bytes that are about to be written.When
new_frameequalstop_boundaryexactly, the check passes but the subsequent write tonew_frame->func_indexgoes past the boundary, causing an out-of-bounds write on the wasm operand stack.Fix
Changed the boundary check from:
to:
This matches the correct pattern already used in
aot_alloc_frame(line 4086) andaot_alloc_standard_frame(line 4086), which both include the frame size in their boundary checks:Impact
Without this fix, when the wasm operand stack is nearly full and
new_framelands exactly attop_boundary, the runtime would write past the stack boundary. This could corrupt adjacent memory and lead to undefined behavior or crashes.