[vm] Fail closed on aliased RefCell borrows in Move values - #426
Open
sausagee wants to merge 1 commit into
Open
Conversation
Container::swap_contents and VectorRef::move_range took paired borrow_mut on cells the verifier promises are distinct. A broken alias panicked the interpreter thread. Acquire the pair through exclusive_cell_pair (ptr_eq then try_borrow_mut) and return UNKNOWN_INVARIANT_VIOLATION_ERROR. Independent rewrite; no aptos-labs sources were copied. Co-authored-by: Young Yang Liauw <sausagee@users.noreply.github.com>
sausagee
marked this pull request as ready for review
September 6, 2026 05:05
sausagee
requested review from
0xIcarus,
fEst1ck and
seanyoung
as code owners
September 6, 2026 05:05
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.
Description
Clean-room rewrite (not a cherry-pick or copy of aptos-labs sources). Intent only: aliased paired
RefCell::borrow_mutmust not abort the interpreter thread (aptos-labs#20439).Container::swap_contentsandVectorRef::move_rangetook two exclusiveborrow_muts. Move's borrow checker promises the cells are distinct; if that invariant is broken, stackedborrow_mutpanicked the VM thread.This change acquires the pair through a new helper,
exclusive_cell_pair:Rc::ptr_eqimmediately.try_borrow_muteach cell.UNKNOWN_INVARIANT_VIOLATION_ERROR.Verified distinct cells still swap / move as before. No other crate in the monorepo is touched.
Invariant: a broken aliasing (or already-borrowed) pair on these paths surfaces as a catchable VM status, never a Rust panic.
Follows
SECURITY.md/RUST_SECURE_CODING.md:Resultinstead of panic, documented safety invariant, nounsafe.How Has This Been Tested?
cargo test -p move-vm-types— 70 passed, 0 failedcontainer_self_swap_returns_status_instead_of_panicking— specialized vector, generic struct, generic vector; self-swap isUNKNOWN_INVARIANT_VIOLATION_ERRORand leaves contents unchangedmove_range_on_aliased_vector_refs_returns_status_instead_of_panicking— distinct vectors still transfer; aliased refs return the same statustest_mem_swapcovers the happy path for distinct container refsKey Areas to Review
exclusive_cell_pairinthird_party/move/move-vm/types/src/values/values_impl.rs— fail-closed helper used by both hardened pathsptr_eqfirst, not a port of the upstream patch)Type of Change
Which Components or Systems Does This Change Impact?
Checklist
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.