From 364b3404728c9e032daf8ef1e8a13bac0768b9d2 Mon Sep 17 00:00:00 2001 From: Daniel Verkamp Date: Mon, 9 Sep 2024 12:49:33 -0700 Subject: [PATCH] hypervisor: kvm: KVM_GET_MSRS writes to its parameter The KVM code that retrieves MSRs was using ioctl_with_ref(), which is supposed to have a read-only reference, but KVM_GET_MSRS needs to write via the provided reference. Change-Id: I2f0972463c99d7d97f19834d23040ab49bbee20d Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5847468 Reviewed-by: Frederick Mayle Commit-Queue: Daniel Verkamp Reviewed-by: Elie Kheirallah --- hypervisor/src/kvm/x86_64.rs | 4 ++-- kvm/src/lib.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/hypervisor/src/kvm/x86_64.rs b/hypervisor/src/kvm/x86_64.rs index 3866a86170..80fa96455d 100644 --- a/hypervisor/src/kvm/x86_64.rs +++ b/hypervisor/src/kvm/x86_64.rs @@ -869,7 +869,7 @@ impl VcpuX86_64 for KvmVcpu { let ret = { // SAFETY: // Here we trust the kernel not to read or write past the end of the kvm_msrs struct. - unsafe { ioctl_with_ref(self, KVM_GET_MSRS, &msrs[0]) } + unsafe { ioctl_with_mut_ref(self, KVM_GET_MSRS, &mut msrs[0]) } }; if ret < 0 { return errno_result(); @@ -909,7 +909,7 @@ impl VcpuX86_64 for KvmVcpu { let ret = { // SAFETY: // Here we trust the kernel not to read or write past the end of the kvm_msrs struct. - unsafe { ioctl_with_ref(self, KVM_GET_MSRS, &kvm_msrs[0]) } + unsafe { ioctl_with_mut_ref(self, KVM_GET_MSRS, &mut kvm_msrs[0]) } }; if ret < 0 { return errno_result(); diff --git a/kvm/src/lib.rs b/kvm/src/lib.rs index 5edcf37b1b..4dcf4b9576 100644 --- a/kvm/src/lib.rs +++ b/kvm/src/lib.rs @@ -1355,7 +1355,7 @@ impl Vcpu { let ret = { // SAFETY: // Here we trust the kernel not to read or write past the end of the kvm_msrs struct. - unsafe { ioctl_with_ref(self, KVM_GET_MSRS, &msrs[0]) } + unsafe { ioctl_with_mut_ref(self, KVM_GET_MSRS, &mut msrs[0]) } }; if ret < 0 { // KVM_SET_MSRS actually returns the number of msr entries written.