Skip to content

Commit f22cc23

Browse files
committed
fix undefined behavior in get_vring_base()
By using ioctl_with_ref() instead of ioctl_with_mut_ref(), we attempted to mutate through an immutable reference, so rustc was well within its rights to assume that `vring_state` does not change across the ioctl call, and hence optimize the return value of the function to simply be the value that `vring_state.num` was initialized to (which is 0). Signed-off-by: Patrick Roy <[email protected]>
1 parent 66a404b commit f22cc23

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

vhost/src/vhost_kern/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,12 +235,12 @@ impl<T: VhostKernBackend> VhostBackend for T {
235235

236236
/// Get a bitmask of supported virtio/vhost features.
237237
fn get_vring_base(&self, queue_index: usize) -> Result<u32> {
238-
let vring_state = vhost_vring_state {
238+
let mut vring_state = vhost_vring_state {
239239
index: queue_index as u32,
240240
num: 0,
241241
};
242242
// SAFETY: This ioctl is called on a valid vhost fd and has its return value checked.
243-
let ret = unsafe { ioctl_with_ref(self, VHOST_GET_VRING_BASE(), &vring_state) };
243+
let ret = unsafe { ioctl_with_mut_ref(self, VHOST_GET_VRING_BASE(), &mut vring_state) };
244244
ioctl_result(ret, vring_state.num)
245245
}
246246

0 commit comments

Comments
 (0)