Thanks to visit codestin.com
Credit goes to github.com

Skip to content

block: fix VHDX region table overlap detection - #8483

Merged
likebreath merged 1 commit into
cloud-hypervisor:mainfrom
htonkovac:block-vhdx-region-overlap-fix
Jun 29, 2026
Merged

likebreath merged 1 commit into
cloud-hypervisor:mainfrom
htonkovac:block-vhdx-region-overlap-fix

Conversation

@htonkovac

Copy link
Copy Markdown
Contributor

The region table overlap check in RegionInfo::new only rejected a new
region that strictly engulfed an existing one. Identical, fully
contained, and partially overlapping region entries passed undetected,
so a malformed VHDX with overlapping regions was wrongly accepted.

Per the MS-VHDX specification,
all region table objects MUST be non-overlapping. This corrects the
region-vs-region check by replacing the faulty predicate with a correct
half-open interval overlap test, extracted into a small pure helper
(ranges_overlap).

Scope: this fixes the region-vs-region check only; the broader VHDX
overlap validation remains tracked in #8009.

The region table overlap check in RegionInfo::new only rejected a new
region that strictly engulfed an existing one. Identical, fully
contained, and partially overlapping regions passed undetected, so a
malformed VHDX with overlapping region entries was wrongly accepted.

Per [MS-VHDX] all region objects MUST be non-overlapping, so such an
image should be rejected. Replace the faulty predicate with a correct
half-open interval overlap test, extracted into a small pure helper
(ranges_overlap).

Add a unit test for the predicate and an integration test that feeds a
crafted region table with two overlapping entries through the real
RegionInfo::new, confirming it is now rejected with RegionOverlap.

Related to cloud-hypervisor#8009 (broader VHDX overlap validation).

Signed-off-by: Henry Hrvoje Tonkovac <[email protected]>
Assisted-by: Claude:Opus-4.8
@htonkovac
htonkovac requested a review from a team as a code owner June 28, 2026 16:40
@likebreath
likebreath added this pull request to the merge queue Jun 29, 2026
Merged via the queue into cloud-hypervisor:main with commit fe8bd6e Jun 29, 2026
38 checks passed
metsw24-max added a commit to metsw24-max/cloud-hypervisor that referenced this pull request Jul 3, 2026
The region table overlap fix in RegionInfo::new computes each entry's
end offset as `file_offset + length`. Both values are taken verbatim
from the image, so a crafted or corrupt VHDX can set a file offset near
u64::MAX and make that addition wrap. A wrapped end offset compares as a
small value, which can slip a genuinely overlapping region past the
half-open interval check that cloud-hypervisor#8483 added.

Use checked_add for the end offset and return a new RegionEntryOverflow
error when it wraps, so a malformed entry is rejected instead of being
folded into a valid-looking range. The computed end is now reused for
the region_entries map so the bound is only calculated once. Add a
regression test for a wrapping entry.

Signed-off-by: Sayed Kaif <[email protected]>
metsw24-max added a commit to metsw24-max/cloud-hypervisor that referenced this pull request Jul 6, 2026
The region table overlap fix in RegionInfo::new computes each entry's
end offset as `file_offset + length`. Both values are taken verbatim
from the image, so a crafted or corrupt VHDX can set a file offset near
u64::MAX and make that addition wrap. A wrapped end offset compares as a
small value, which can slip a genuinely overlapping region past the
half-open interval check that cloud-hypervisor#8483 added.

Use checked_add for the end offset and return a new RegionEntryOverflow
error when it wraps, so a malformed entry is rejected instead of being
folded into a valid-looking range. The computed end is now reused for
the region_entries map so the bound is only calculated once. Add a
regression test for a wrapping entry.

Signed-off-by: Sayed Kaif <[email protected]>
Alvov1 pushed a commit to Alvov1/cloud-hypervisor that referenced this pull request Jul 7, 2026
The region table overlap fix in RegionInfo::new computes each entry's
end offset as `file_offset + length`. Both values are taken verbatim
from the image, so a crafted or corrupt VHDX can set a file offset near
u64::MAX and make that addition wrap. A wrapped end offset compares as a
small value, which can slip a genuinely overlapping region past the
half-open interval check that cloud-hypervisor#8483 added.

Use checked_add for the end offset and return a new RegionEntryOverflow
error when it wraps, so a malformed entry is rejected instead of being
folded into a valid-looking range. The computed end is now reused for
the region_entries map so the bound is only calculated once. Add a
regression test for a wrapping entry.

Signed-off-by: Sayed Kaif <[email protected]>
@rbradford rbradford added the bug-fix Bug fix to include in release notes label Jul 10, 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.

3 participants