fix(snapshot): make vfs_restore fail closed and apply atomically#1586
Merged
Conversation
Previously, restore_snapshot_inner restored shell state first and then called fs.vfs_restore(...) ignoring its boolean return. The FileSystemExt contract returned `false` for unsupported restore, and InMemoryFs::restore returned early without clearing entries on validation failure. A forged unkeyed snapshot whose VFS section failed path validation would therefore return Ok after mutating the shell state, while leaving previous-tenant files readable in the VFS — a half-restored, cross-tenant leak. - Change `FileSystemExt::vfs_restore` to return `crate::Result<()>`. The default impl returns Err(Unsupported); InMemoryFs/OverlayFs/ MountableFs propagate the inner restore result. - Change `InMemoryFs::restore` to return `Result<()>` with the underlying limit error and never clear on validation failure. - Reorder restore_snapshot_inner: validate shell limits, then apply VFS (which can fail), then apply shell state (cannot fail past validation). Mutation order guarantees no half-restored state. Add an integration regression test (snapshot_restore_fails_closed_on_malformed_vfs) that forges a poisoned VFS path inside an otherwise valid snapshot and verifies: - restore_snapshot returns Err - shell variable values are unchanged - previous-tenant VFS contents remain intact Closes #1576
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
bashkit | c4757fb | Commit Preview URL Branch Preview URL |
May 07 2026, 04:22 AM |
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.
Closes #1576.
Summary
restore_snapshot_innerpreviously restored shell state first and then calledfs.vfs_restore(...)ignoring its boolean return. TheFileSystemExtcontract returnedfalsefor unsupported restore, andInMemoryFs::restorereturned early without clearing on validation failure. A forged unkeyed snapshot whose VFS section failed path validation therefore returnedOkafter mutating the shell state, while leaving previous-tenant files readable in the VFS — a half-restored, cross-tenant leak.Fix
FileSystemExt::vfs_restorenow returnscrate::Result<()>. The default impl returnsErr(Unsupported);InMemoryFs/OverlayFs/MountableFspropagate the inner result.InMemoryFs::restorereturnsResult<()>with the underlying limit error.restore_snapshot_innerreordered to: validate shell limits → apply VFS (can fail) → apply shell state (cannot fail past validation). Mutation order guarantees no half-restored state.Tests
New integration test
snapshot_restore_fails_closed_on_malformed_vfsforges a poisoned VFS path inside an otherwise valid snapshot and asserts:restore_snapshotreturnsErr.Existing snapshot tests updated to handle the new
Resultreturn onInMemoryFs::restore.Test plan
cargo test -p bashkit --test snapshot_tests(38/38 passing)cargo test -p bashkit --lib fs::memory(49/49 passing)cargo test -p bashkit --lib --no-default-features(2207 passing)cargo fmt --all -- --checkcargo clippy -p bashkit --all-features --all-targets -- -D warningsGenerated by Claude Code