hypervisor: geniezone: GZVM_CHECK_EXTENSION mutates its parameter

For GZVM_CAP_PROTECTED_VM at least, the GZVM_CHECK_EXTENSION ioctl
ovewrites its parameter with the result rather than using the return
value, so its parameter needs to be a mutable reference.

Change-Id: Ief9f153804ebb57e2b247f2b6a5f04b429c77a7d
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5847469
Reviewed-by: Frederick Mayle <fmayle@google.com>
Commit-Queue: Frederick Mayle <fmayle@google.com>
This commit is contained in:
Daniel Verkamp 2024-09-09 12:37:37 -07:00 committed by crosvm LUCI
parent 7e3e8f8ccb
commit 52f0f63d87

View file

@ -19,6 +19,7 @@ use std::sync::Arc;
use base::errno_result;
use base::error;
use base::ioctl;
use base::ioctl_with_mut_ref;
use base::ioctl_with_ref;
use base::ioctl_with_val;
use base::pagesize;
@ -805,12 +806,12 @@ impl GeniezoneVm {
/// Checks whether a particular GZVM-specific capability is available for this VM.
fn check_raw_capability(&self, capability: GeniezoneCap) -> bool {
let cap: u64 = capability as u64;
let mut cap: u64 = capability as u64;
// SAFETY:
// Safe because we know that our file is a GZVM fd, and if the cap is invalid GZVM assumes
// it's an unavailable extension and returns 0.
unsafe {
ioctl_with_ref(self, GZVM_CHECK_EXTENSION, &cap);
ioctl_with_mut_ref(self, GZVM_CHECK_EXTENSION, &mut cap);
}
cap == 1
}