Repository navigation
Fix pickle complexity DoS: add memo_get node budget - #3688
Closed
AnkitNakhawa wants to merge 3 commits into
Closed
AnkitNakhawa wants to merge 3 commits into
AnkitNakhawa wants to merge 3 commits into
Conversation
Contributor
|
Heads-up for triage: there's meaningful overlap with #3628 ("Bound the pickle VM's working set and nesting depth"). #3628's byte-based working-set cap also bounds the memo-replay amplification this node budget targets — each memo-expanded clone charges bytes against the cap, and #3628 even ships a rejects_memo_replay_amplification test for exactly that DoS. So the two guard largely the same surface via different metrics (cumulative node count here vs. a heap-bytes ceiling there). Might be worth deciding whether both are wanted or whether they should be unified, to avoid two overlapping limits on the same path. |
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 pickle memo bomb: add cumulative complexity limit to
memo_get(closes #3620)What
Adds a cumulative node-budget guard to
Stack::memo_getincandle-core/src/pickle.rsto prevent the algorithmic-complexity DoS described in #3620.Root cause
memo_getreturnedobj.clone()unconditionally — a deep clone of the entireObjecttree on everyBinGet. A crafted pickle that fetches the same memo slot twice, combines the copies, and writes the result back doubles the node count each cycle. After N cycles, parsing requires O(2^N) work and memory from an input whose size grows only linearly with N (the same "Billion Laughs" amplification principle). Two paths were confirmed:BinGet+BinGet+Tuple2+BinPut— N=25 stalls ~5.7s on a release buildBinGet+BinGet+Build(dict-merge) +BinPut— ~92 GB RSS measured before OOM on a 128 GB hostFix
memo_getnow counts the nodes in the object being retrieved, checks the budget, and only clones if the budget is not exceeded. The cost is added to a runningcomplexitycounter on theStack; if it exceedsmax_complexity(default: 1,000,000 nodes),parsing is aborted before the expensive object-tree clone occurs. The node walk is iterative rather than recursive so a deeply-nested input cannot stack-overflow before the guard fires.The 1,000,000-node default is a conservative initial bound — real checkpoint complexity is estimated well below this, but it has not been validated against large production checkpoints and can be adjusted based on maintainer guidance.
Stack::with_limit(n)is exposed for callers that need a custom budget.u64::MAXdisables the check entirely.Tests added
Closes #3620