Skip to content

disk_hook: check the range before refusing a read-only write or unmap - #5245

Open
Robert Nowotny (bitranox) wants to merge 1 commit into
microsoft:mainfrom
bitranox:disk-hook-range-before-readonly
Open

Robert Nowotny (bitranox) wants to merge 1 commit into
microsoft:mainfrom
bitranox:disk-hook-range-before-readonly

Conversation

@bitranox

Copy link
Copy Markdown
Contributor

On a read-only HookDisk, write_vectored and unmap return ReadOnly before the backing disk gets to check the range. So an out-of-range write or unmap answers ReadOnly, while the DiskIo contract asks for IllegalBlock on any request that falls outside the disk.

#5090 fixed the same order in disk_layered and Disk::unmap. This does the same for the test disk: range first, then read-only, then the backing disk. Only tests use HookDisk, 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_first in disk_hook. It fails on the old order, first at the out-of-range write and, with only unmap reverted, at the out-of-range unmap. cargo test -p disk_hook passes (21 tests).

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.
Copilot AI balanced review requested due to automatic review settings November 23, 2026 14:20

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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 HookDisk is 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants