Fix missing IS_INVALID_TAGINDEX check in RETHROW handler#4837
Open
sumleo wants to merge 1 commit intobytecodealliance:mainfrom
Open
Fix missing IS_INVALID_TAGINDEX check in RETHROW handler#4837sumleo wants to merge 1 commit intobytecodealliance:mainfrom
sumleo wants to merge 1 commit intobytecodealliance:mainfrom
Conversation
The RETHROW opcode handler in the classic interpreter reads the exception_tag_index from the stack and directly uses it to index module->module->tags[] without checking IS_INVALID_TAGINDEX first. When CATCH_ALL catches a cross-module exception, it pushes INVALID_TAGINDEX (0xFFFFFFFF) onto the stack. If RETHROW then executes, it reads 0xFFFFFFFF and accesses tags[0xFFFFFFFF], causing a massive out-of-bounds read. The THROW handler at line 1744 properly checks IS_INVALID_TAGINDEX before accessing the tags array. Add the same check to the RETHROW handler: when IS_INVALID_TAGINDEX is true, skip the tags[] access and set cell_num_to_copy to 0, allowing the exception to propagate to CATCH_ALL handlers. Add unit tests verifying IS_INVALID_TAGINDEX detection and that RETHROW uses the same validation logic as THROW.
4de4f92 to
bb89991
Compare
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.
The RETHROW opcode handler reads
exception_tag_indexfrom the stack and directly accessesmodule->module->tags[exception_tag_index]without checking forINVALID_TAGINDEX.When
CATCH_ALLcatches a cross-module exception with an unknown tag, it pushesINVALID_TAGINDEX(0xFFFFFFFF) onto the stack. If RETHROW then executes, it accessestags[0xFFFFFFFF]— a massive out-of-bounds read.The THROW handler correctly checks
IS_INVALID_TAGINDEXbefore the array access. This patch adds the same check to the RETHROW handler: when the tag index is invalid, skip thetags[]access and setcell_num_to_copyto 0, allowing the exception to propagate toCATCH_ALLhandlers.