Visitar URL original
vhost_user: use opaque guest addresses instead of exposing HVAs (#7190) by adilalperenciftci · Pull Request #9016 · cloud-hypervisor/cloud-hypervisor · GitHub
Skip to content

vhost_user: use opaque guest addresses instead of exposing HVAs (#7190) - #9016

Open
adilalperenciftci wants to merge 1 commit into
cloud-hypervisor:mainfrom
adilalperenciftci:vhost-user/opaque-guest-addresses
Open

adilalperenciftci wants to merge 1 commit into
cloud-hypervisor:mainfrom
adilalperenciftci:vhost-user/opaque-guest-addresses

Conversation

@adilalperenciftci

@adilalperenciftci adilalperenciftci commented Oct 6, 2026 •

Copy link
Copy Markdown

vhost-user backends were receiving actual host virtual addresses. This patch prevents HVA disclosure while keeping legacy compatibility and adding support for GPA_ADDRESSES negotiation.

  • Added VhostUserAddressMapper in vu_common_ctrl to handle GPA/HVA translation safely.
  • If GPA_ADDRESSES is supported, we map directly to GPAs.
  • For legacy backends, we use a 0x1000 synthetic bias to prevent NULL pointer issues without leaking the HVA.
  • State is persisted across reconnects and migrations.
  • Addressed edge cases like invalid ring ranges, zero-length allocs, and bounds crossing.
  • Enabled across all frontends (block, net, fs, generic).

Tested via:

  • cargo test -p virtio-devices -p vhost_user_block -p vhost_user_net --lib
  • cargo check --locked -p virtio-devices --all-targets --tests
  • Wire-level checks on SET_MEM_TABLE and SET_VRING_ADDR ensuring no HVA leakage in either mode.
  • Tested against a legacy vhost-user-backend missing GPA_ADDRESSES (verifying synthetic namespace works).

Fixes #7190

@adilalperenciftci
adilalperenciftci requested a review from a team as a code owner October 6, 2026 07:15
Copilot AI balanced review requested due to automatic review settings October 6, 2026 07:15

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@adilalperenciftci
adilalperenciftci force-pushed the vhost-user/opaque-guest-addresses branch from 83dde6b to 64fdf33 Compare October 6, 2026 12:41

@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.

We already have a system for mapping like this which we use for the translating for VIRTIO_F_ACCESS_PLATFORM which should be reused instead.

New contributors are strongly discouraged from using LLMs as it does not help them understand the project and develop their skills. Please spend time reviewing the existing code and PRs before starting to try and contribute.

Comment on lines +58 to +61
#[derive(Clone, Copy, Default)]
struct VhostUserAddressMapper {
gpa_addresses: bool,
}

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.

Please don't submit PRs with LLM slop. Creating a struct for a single bool that is only embedded into one struct just so that the LLM can satisfy "always have a test" is classic LLM slop.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

yes, you're right. i missed the existing AccessPlatform mapping path. i kept this separate because GPA_ADDRESSES is negotiated with the backend while VIRTIO_F_ACCESS_PLATFORM is negotiated with the guest, and i wanted the vhost-user wire-address handling and range checks to stay together. the struct was a deliberate design choice, not something added just for testing, but i agree that it duplicates an existing abstraction. i'll rework it to reuse the current mapping system. also, i didn't use an llm to write this change.

The memory table and the vring addresses sent to a vhost-user backend
carried the frontend's host virtual addresses. A backend only needs
those values to be consistent with each other so it can derive offsets
into its own mappings, so there is no reason to hand out frontend HVAs.

Advertise the GPA_ADDRESSES protocol feature and reuse the existing
AccessPlatform translation that VIRTIO_F_ACCESS_PLATFORM already relies
on. A backend that negotiates GPA_ADDRESSES needs no translation and
receives guest physical addresses unchanged. A backend that does not
negotiate it keeps working against a biased guest address, which stays
consistent across the memory table and the vrings while remaining
non-zero.

The vring bounds check keeps rejecting rings that are not backed by a
single guest memory region, and the ring sizes now include the event
field only when VIRTIO_F_RING_EVENT_IDX has been negotiated, so a
region-boundary-aligned ring is no longer rejected for a trailer that
the guest never allocated.

Signed-off-by: Adil Alperen Çiftci <adilerta54@gmail.com>
@adilalperenciftci
adilalperenciftci force-pushed the vhost-user/opaque-guest-addresses branch from 1103cc9 to 842719c Compare October 10, 2026 14:10
@adilalperenciftci

Copy link
Copy Markdown
Author

Thanks for the pointer to the existing translation path, and for the review.

Reworked to reuse it. The handle now carries an
Option<Arc<dyn AccessPlatform>> and the addresses go through the same
Translatable::translate_gpa that VIRTIO_F_ACCESS_PLATFORM uses, in the
same shape as vdpa.rs. A backend that negotiates GPA_ADDRESSES needs no
translation, so it gets None and receives guest physical addresses
unchanged; a backend that does not negotiate it gets an AccessPlatform
implementation that applies the bias. The bespoke mapper struct and its
parallel helper API are gone, as is the test scaffolding that was built
around it, along with the vhost-user-backend dev-dependency it pulled in.

Two other things changed while doing that:

  • The commits are squashed into one, per CONTRIBUTING, and the title prefix
    is now virtio-devices: vhost_user:. The previous vhost_user: prefix is
    not in the valid component list in scripts/gitlint/rules.
  • The vring bounds check keeps the explicit zero-size rejection that
    get_host_address_range() performed, so that behaviour is unchanged.

The event-field sizing fix is folded into the same commit, since the sizes it
corrects were introduced by this change rather than existing upstream.

Local verification: cargo clippy -p virtio-devices --all-targets -- -D warnings
clean, cargo test -p virtio-devices --lib 129 passed, cargo +nightly fmt --all -- --check clean.

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.

Stop leaking virtqueue host addresses to vhost-user backends

3 participants