read/macho: bound exports trie traversal to avoid exponential blowup#953
Open
scadastrangelove wants to merge 1 commit into
Open
read/macho: bound exports trie traversal to avoid exponential blowup#953scadastrangelove wants to merge 1 commit into
scadastrangelove wants to merge 1 commit into
Conversation
The cycle check added in gimli-rs#940 rejects a child offset equal to an ancestor, but not shared subtrees: a node reached by multiple non-ancestor paths is re-traversed each time. A small crafted trie whose every node has two edges to the same next node has 2^depth root-to-leaf paths, so the DFS runs in exponential time (a ~330-byte Mach-O hangs the exports_trie iterator). A well-formed exports trie is a prefix tree with at most data.len() nodes, so a valid DFS needs at most ~2 * data.len() steps. Bound the traversal to that and stop cleanly when exceeded, which covers shared-subtree (and any residual cyclic) inputs. Verified: cargo test passes (lib incl exports_trie + integration), valid tries still traverse, and the crafted exponential trie now terminates. Discovered by the rust-in-peace security pipeline (https://github.com/scadastrangelove/rust-in-peace/).
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.
Fixes #952.
The cycle check added in #940 rejects a child offset equal to an ancestor, but not shared subtrees: a node reached by multiple non-ancestor paths is re-traversed each time. A trie whose every node has two edges to the same next node therefore has
2^depthroot-to-leaf paths and the DFS runs in exponential time (a ~330-byte Mach-O hangs theexports_trie()iterator).A well-formed exports trie is a prefix tree with at most
data.len()nodes, so a valid DFS needs at most ~2 * data.len()steps. This bounds the traversal to that and stops cleanly when exceeded, covering shared-subtree (and any residual cyclic) inputs.Verified against
main:cargo testpasses (25 lib incl theexports_trietests, integration, and--features all), valid tries still traverse, and the crafted exponential trie (#952) now terminates instead of hanging.Discovered by the rust-in-peace security pipeline.