Fix integer overflow in heap_opt range walk on top-of-memory access (… - #582
Open
kvpanch wants to merge 1 commit into
Open
Fix integer overflow in heap_opt range walk on top-of-memory access (…#582kvpanch wants to merge 1 commit into
kvpanch wants to merge 1 commit into
Conversation
…581) The word-stepping loops in `taint_range`, `mark_escaping_range`, and `mark_escaping_and_tainted_range` walked a static range with `while word < end { word += 32 }`. When an access sits near the top of the address space, `end = address.saturating_add(size)` saturates at `u64::MAX`, and the final `word += 32` steps past `u64::MAX`, panicking with "attempt to add with overflow". Under `--newyork` this is reachable from valid Yul: folding `add(mul(MAX_U256, 1), 0x41)` to `0x40` lets an mstore corrupt the free-memory-pointer word with `u64::MAX`; mem_opt then forwards `mload(0x40)` to that literal, turning a later `mstore(fmp, _)` into a static unaligned store at `u64::MAX` that taints its covered words. Iterate the already-bounded `num_words` count with a saturating step so the walk covers the same words without overflowing.
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.
…#581)
The word-stepping loops in
taint_range,mark_escaping_range, andmark_escaping_and_tainted_rangewalked a static range withwhile word < end { word += 32 }. When an access sits near the top of the address space,end = address.saturating_add(size)saturates atu64::MAX, and the finalword += 32steps pastu64::MAX, panicking with "attempt to add with overflow".Under
--newyorkthis is reachable from valid Yul: foldingadd(mul(MAX_U256, 1), 0x41)to0x40lets an mstore corrupt the free-memory-pointer word withu64::MAX; mem_opt then forwardsmload(0x40)to that literal, turning a latermstore(fmp, _)into a static unaligned store atu64::MAXthat taints its covered words.Iterate the already-bounded
num_wordscount with a saturating step so the walk covers the same words without overflowing.