Skip to content

Commit ade910b

Browse files
committed
This is a combination of 2 commits.
fix: use correct ioctl wrapper for `create_device` Use `ioctl_with_mut_ref` instead of `ioctl_with_ref` in the `create_device` method as it needs to write to the `kvm_create_device` struct passed to it. This incorrect usage of `ioctl_with_ref` causes newer versions of Rust compiler (1.82 and above) to treat the `kvm_create_device` struct as read-only and bypass following reads from it. This optimization lead to incorrect value being passed to the `File::from_raw_fd` call. Signed-off-by: Egor Lazarchuk <[email protected]>
1 parent 4508a0f commit ade910b

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

kvm-ioctls/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77
- [[#288](https://github.com/rust-vmm/kvm-ioctls/pull/288)]: Introduce `Cap::GuestMemfd`, `Cap::MemoryAttributes` and
88
`Cap::UserMemory2` capabilities enum variants for use with `VmFd::check_extension`.
99

10+
### Fixed
11+
12+
- [[#298](https://github.com/rust-vmm/kvm/pull/298)]: Fixed incorrect usage of `ioctl_wit_ref` in the
13+
`create_device` method. Replace it with `ioctl_wit_mut_ref` as the passed parameter may be mutated by the
14+
ioctl.
15+
1016
## v0.19.0
1117

1218
### Added

kvm-ioctls/src/ioctls/vm.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ use crate::ioctls::{KvmRunWrapper, Result};
2222
use crate::kvm_ioctls::*;
2323
use vmm_sys_util::errno;
2424
use vmm_sys_util::eventfd::EventFd;
25+
#[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))]
26+
use vmm_sys_util::ioctl::ioctl;
2527
#[cfg(target_arch = "x86_64")]
2628
use vmm_sys_util::ioctl::ioctl_with_mut_ptr;
27-
#[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))]
28-
use vmm_sys_util::ioctl::{ioctl, ioctl_with_mut_ref};
29-
use vmm_sys_util::ioctl::{ioctl_with_ref, ioctl_with_val};
29+
use vmm_sys_util::ioctl::{ioctl_with_mut_ref, ioctl_with_ref, ioctl_with_val};
3030

3131
/// An address either in programmable I/O space or in memory mapped I/O space.
3232
///
@@ -1300,7 +1300,7 @@ impl VmFd {
13001300
/// ```
13011301
pub fn create_device(&self, device: &mut kvm_create_device) -> Result<DeviceFd> {
13021302
// SAFETY: Safe because we are calling this with the VM fd and we trust the kernel.
1303-
let ret = unsafe { ioctl_with_ref(self, KVM_CREATE_DEVICE(), device) };
1303+
let ret = unsafe { ioctl_with_mut_ref(self, KVM_CREATE_DEVICE(), device) };
13041304
if ret == 0 {
13051305
// SAFETY: We validated the return of the function creating the fd and we trust the
13061306
// kernel.

0 commit comments

Comments
 (0)