Repository navigation
disk_hook: check the range before refusing a read-only write or unmap - #5245
Open
Robert Nowotny (bitranox) wants to merge 1 commit into
Open
Robert Nowotny (bitranox) wants to merge 1 commit into
Robert Nowotny (bitranox) wants to merge 1 commit into
Conversation
On a read-only HookDisk, write_vectored and unmap returned ReadOnly before the backing disk could check the range, so an out-of-range request got ReadOnly where the DiskIo contract asks for IllegalBlock. Check the range first, the same order disk_layered uses since microsoft#5090.
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are recorded for the test-only HookDisk change aligning range-validation error precedence with the DiskIo contract.
No open issues 🎉
What changed in this PR
This PR aligns the test-only HookDisk with the DiskIo contract and the fixes in #5090: out-of-range writes and unmaps return IllegalBlock before read-only checks return ReadOnly.
Changes:
- Adds a shared range-first validation helper for writes and unmaps.
- Adds regression tests for out-of-range requests and valid-range read-only refusals.
- Leaves shipped behavior unchanged because
HookDiskis used only in tests.
| File | Description |
|---|---|
vm/devices/storage/disk_hook/src/tests.rs |
Tests error precedence for read-only writes and unmaps. |
vm/devices/storage/disk_hook/src/lib.rs |
Checks mutation ranges before enforcing read-only status. |
Review effort: Balanced
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.
On a read-only
HookDisk,write_vectoredandunmapreturnReadOnlybefore the backing disk gets to check the range. So an out-of-range write or unmap answersReadOnly, while theDiskIocontract asks forIllegalBlockon any request that falls outside the disk.#5090 fixed the same order in
disk_layeredandDisk::unmap. This does the same for the test disk: range first, then read-only, then the backing disk. Only tests useHookDisk, so nothing shipped changes, but a test that sends an out-of-range request to a read-only hook disk now gets the error a real backend returns.Testing: new
read_only_override_checks_range_firstindisk_hook. It fails on the old order, first at the out-of-range write and, with onlyunmapreverted, at the out-of-range unmap.cargo test -p disk_hookpasses (21 tests).