Skip to content

Conversation

DemiMarie
Copy link

@DemiMarie DemiMarie commented Jul 8, 2025

Summary of the PR

vfio_syscall::map_dma causes the kernel to make an arbitrary address
accessible for DMA by a device the guest typically controls. This is
unsafe, as it can change memory that Rust assumes is immutable.

I found this through a review of Cloud Hypervisor, where I saw a
safe function that took a host address cast to u64 as an argument and
accessed that address. It turns out that this function was the source
of the unsoundness.

Requirements

Before submitting your PR, please make sure you addressed the following
requirements:

  • All commits in this PR have Signed-Off-By trailers (with
    git commit -s), and the commit message has max 60 characters for the
    summary and max 75 characters for each description line.
  • All added/changed functionality has a corresponding unit/integration
    test.
  • All added/changed public-facing functionality has entries in the "Upcoming
    Release" section of CHANGELOG.md (if no such section exists, please create one).
  • Any newly added unsafe code is properly documented.

@DemiMarie DemiMarie changed the title Fix multi Fix multiple soundness issues Jul 23, 2025
@jinankjain
Copy link
Collaborator

@DemiMarie can you please rebase and fix the clippy errors?

vfio_syscall::map_dma() accepts a u64 and tells the Linux kernel to make
the corresponding address accessible for DMA by a device.  Therefore,
passing bad u64 values can result in memory corruption or disclosure.
Change the u64 argument to a pointer to avoid confusion.  To reflect
that the caller must uphold invariants to prevent undefined behavior,
mark the API as unsafe.

I found this through a review of Cloud Hypervisor [1].  Some of its
internal APIs took a host took a host address cast to u64 as an argument
and accessed that address.  In one case, the u64 was passed directly to
vfio_syscall::map_dma().

[1]: cloud-hypervisor/cloud-hypervisor#7129

Signed-off-by: Demi Marie Obenour <demiobenour@gmail.com>
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