Skip to content

block: Fix WriteZeroes sector arithmetic overflow - #8388

Merged
rbradford merged 2 commits into
cloud-hypervisor:mainfrom
weltling:blk-write-zeroes-overflow
Jun 15, 2026
Merged

block: Fix WriteZeroes sector arithmetic overflow#8388
rbradford merged 2 commits into
cloud-hypervisor:mainfrom
weltling:blk-write-zeroes-overflow

Conversation

@weltling

Copy link
Copy Markdown
Member

The WriteZeroes arm of Request::execute_async computed wz_sector * SECTOR_SIZE before the checked_add of sector and num_sectors. A guest wz_sector near u64::MAX overflows the multiplication. The Discard arm above already runs the bounds check first; WriteZeroes now matches.

Found with virtio-villain B0018.

In Request::execute_async the WriteZeroes arm multiplied wz_sector
by SECTOR_SIZE before the checked_add of sector and num_sectors.
A wz_sector near u64::MAX overflows the multiplication.

Reorder the arm to run the checked_add and disk_nsectors check
first, matching the Discard arm above.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
@weltling
weltling requested a review from a team as a code owner June 14, 2026 23:05

@phip1611 phip1611 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nice find!

Comment thread block/src/io/request.rs Outdated
};
let mut disk = PanicAsyncIo(EventFd::new(0).unwrap());

match request.execute_async(mem, 1024, &mut disk, &[], false, 0) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: I think this can be a let Err(ExecuteError::BadRequest(Error::InvalidOffset) = request.execute_async() ... else {panic}

Please try to check if it improves the code. I'm also fine with keeping the match

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Applied as suggested. Match would print the actual value on mismatch, but this form is shorter and the panic message names the expected variant.

Thanks

@rbradford rbradford left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you! Waiting on merge to hear if you want to interation @phip1611's feedback.

Cover the prior commit by constructing a Request directly and a stub
AsyncIo whose backend methods are unreachable, then submit a payload
with sector + num_sectors past u64::MAX and assert BadRequest.

Assisted-by: Claude:Opus-4.7
Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
@weltling
weltling force-pushed the blk-write-zeroes-overflow branch from d947179 to e1cd6cb Compare June 15, 2026 10:36
@weltling

Copy link
Copy Markdown
Member Author

Thanks for the reviews!

@rbradford
rbradford enabled auto-merge June 15, 2026 11:08
@rbradford
rbradford added this pull request to the merge queue Jun 15, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to no response for status checks Jun 15, 2026
@rbradford
rbradford merged commit 0e4e327 into cloud-hypervisor:main Jun 15, 2026
41 checks passed
@weltling
weltling deleted the blk-write-zeroes-overflow branch June 15, 2026 13:11
@github-project-automation github-project-automation Bot moved this from 🆕 New to ✅ Done in Cloud Hypervisor Roadmap Jul 8, 2026
@rbradford rbradford added the bug-fix Bug fix to include in release notes label Jul 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug-fix Bug fix to include in release notes

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

4 participants