Fix Reference Count Overflow (Use-After-Free) in Atom::clone#301
Open
matteoldani wants to merge 1 commit into
Open
Fix Reference Count Overflow (Use-After-Free) in Atom::clone#301matteoldani wants to merge 1 commit into
matteoldani wants to merge 1 commit into
Conversation
Previously, cloning a dynamic Atom blindly incremented the atomic reference count using `fetch_add` without any bounds checking. This allowed a degenerate program to clone an Atom ~2.1 billion times on a 32-bit platform, wrapping the reference count to negative and eventually back to 0. This would cause the entry to be freed while clones still exist, triggering an exploitable Use-After-Free. This patch adds an overflow check to abort the process if the reference count reaches `isize::MAX`, mirroring the safety mechanisms of `std::sync::Arc`. Local benchmarks show the performance impact is less than 0.2 nanoseconds per clone, which is statistically indistinguishable from the baseline noise.
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.
This PR adds a safeguard against Reference Count Overflow in
Atom::clone.If an
Atom's reference count exceedsisize::MAX, it will now deterministically abort the process (std::process::abort()) rather than wrapping around to a negative number and risking a subsequent Use-After-Free vulnerability.Despite being unlikely to occur in practice, the fix should be easy and without real tradeoffs.
Fixes #299