Skip to content

virtio: reject regions whose address and length overflow - #4145

Merged
John Starks (jstarks) merged 1 commit into
microsoft:mainfrom
knQzx:fix/virtio-gpn-list-overflow
Aug 2, 2026
Merged

John Starks (jstarks) merged 1 commit into
microsoft:mainfrom
knQzx:fix/virtio-gpn-list-overflow

Conversation

@knQzx

Copy link
Copy Markdown
Contributor

try_build_gpn_list computes addr + len on region descriptors without checking for overflow. A region whose address and length wrap past u64::MAX panics in debug builds and, with overflow checks off, wraps to a bogus gpn range in release - first_gpn ends up above last_gpn, the range iterates zero times, and prev_end is left holding a wrapped value

this uses checked_add and treats an overflowing region as invalid, which is how the function already reports every other malformed input, so callers keep falling back to the bounce buffer path they use whenever this returns None

added two tests: a single wrapping region, and a wrapping region followed by a well-formed one, which also covers the stale prev_end. Both fail before the change with attempt to add with overflow

try_build_gpn_list computed addr + len on caller-supplied region
descriptors without checking for overflow, panicking in debug builds and
wrapping to a bogus gpn range in release. Use checked_add and treat an
overflowing region as invalid, which is how the function already reports
every other malformed input.
Copilot AI review requested due to automatic review settings August 1, 2026 15:39
@knQzx
Novikov Kirill (knQzx) requested a review from a team as a code owner August 1, 2026 15:39

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.

Pull request overview

This PR hardens virtio region handling by rejecting data regions whose addr + len would overflow u64, preventing debug-build panics and release-build miscomputation of the resulting GPN range.

Changes:

  • Use checked_add when computing the end address for each region and treat overflow as invalid input (None).
  • Recompute last_gpn and prev_end from the checked end value to avoid wrapped/stale state.
  • Add unit tests covering a single wrapping region and a wrapping region followed by another region.

Comment on lines +137 to 139
prev_end = Some(end);
total_len += len;
}
@smalis-msft

Copy link
Copy Markdown
Contributor

Is this something you hit coming from an actual device? Wouldn't such a range be invalid for the device to use anyways? John Starks (@jstarks) what does virtio-villain say about this?

@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown

@jstarks

Copy link
Copy Markdown
Member

Anatol Belski (@weltling), it might be good to add some (more?) GPA overflow cases to virtio-villain. It looks like this case would have hit virtio-blk and virtio-vsock.

@jstarks

Copy link
Copy Markdown
Member

Thanks for the contribution.

@jstarks
John Starks (jstarks) merged commit c3df923 into microsoft:main Aug 2, 2026
68 of 69 checks passed
@weltling

Copy link
Copy Markdown
Member

Anatol Belski (@weltling), it might be good to add some (more?) GPA overflow cases to virtio-villain. It looks like this case would have hit virtio-blk and virtio-vsock.

Thanks for the ping, John Starks (@jstarks). I added these in https://github.com/weltling/virtio-villain/releases/tag/v0.8.1. The block cases run on OpenVMM, but the vsock cases skip. The runner has no vsock device on the bus. Passing --virtio-vsock-path on its own aborts at launch with missing PCI INT#A line.

Two questions. Are there other spots that build a paged range the same way, that would be worth a case as well? And would it be ok to add --virtio-vsock-pcie-port flag mirroring --virtio-console-pcie-port so the vsock device could be attached in direct boot?

Thanks

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.

5 participants