Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use correct ioctl wrapper for create_device #298

Merged
merged 1 commit into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions kvm-ioctls/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
- [[#288](https://github.com/rust-vmm/kvm-ioctls/pull/288)]: Introduce `Cap::GuestMemfd`, `Cap::MemoryAttributes` and
`Cap::UserMemory2` capabilities enum variants for use with `VmFd::check_extension`.

### Fixed

- [[#298](https://github.com/rust-vmm/kvm/pull/298)]: Fixed incorrect usage of `ioctl_wit_ref` in the
`create_device` method. Replace it with `ioctl_wit_mut_ref` as the passed parameter may be mutated by the
ioctl.

## v0.19.0

### Added
Expand Down
8 changes: 4 additions & 4 deletions kvm-ioctls/src/ioctls/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ use crate::ioctls::{KvmRunWrapper, Result};
use crate::kvm_ioctls::*;
use vmm_sys_util::errno;
use vmm_sys_util::eventfd::EventFd;
#[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))]
use vmm_sys_util::ioctl::ioctl;
#[cfg(target_arch = "x86_64")]
use vmm_sys_util::ioctl::ioctl_with_mut_ptr;
#[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))]
use vmm_sys_util::ioctl::{ioctl, ioctl_with_mut_ref};
use vmm_sys_util::ioctl::{ioctl_with_ref, ioctl_with_val};
use vmm_sys_util::ioctl::{ioctl_with_mut_ref, ioctl_with_ref, ioctl_with_val};

/// An address either in programmable I/O space or in memory mapped I/O space.
///
Expand Down Expand Up @@ -1300,7 +1300,7 @@ impl VmFd {
/// ```
pub fn create_device(&self, device: &mut kvm_create_device) -> Result<DeviceFd> {
// SAFETY: Safe because we are calling this with the VM fd and we trust the kernel.
let ret = unsafe { ioctl_with_ref(self, KVM_CREATE_DEVICE(), device) };
let ret = unsafe { ioctl_with_mut_ref(self, KVM_CREATE_DEVICE(), device) };
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a test that would trigger the error? As we discussed offline this would not be triggering in the CI because we're not using the latest Rust version. It's enough if we can trigger it locally because eventually we'll be using the latest version in the CI as well.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We already have tests which can trigger this behavior. Tests are: test_register_unregister_irqfd and test_set_irq_line.

if ret == 0 {
// SAFETY: We validated the return of the function creating the fd and we trust the
// kernel.
Expand Down