From 276112188e477b79a4487ea2424946c2917c9423 Mon Sep 17 00:00:00 2001 From: Jonathan Klimt Date: Wed, 31 Jan 2024 17:50:27 +0100 Subject: [PATCH] Fixed incorrect type of the data buffers in the two file system hypercalls. Note: I did not increase the interface version, as there are no kernels out there that have used the incorrect type and uhyve has always treated it the way it is now. --- src/hypercall.rs | 16 ++++++++-------- uhyve-interface/src/parameters.rs | 6 +++--- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/hypercall.rs b/src/hypercall.rs index 05d5eaae..47921ec6 100644 --- a/src/hypercall.rs +++ b/src/hypercall.rs @@ -1,13 +1,15 @@ use std::{ ffi::{OsStr, OsString}, - io, - io::Write, + io::{self, Error, ErrorKind, Write}, os::unix::ffi::OsStrExt, }; use uhyve_interface::{parameters::*, GuestPhysAddr, Hypercall, HypercallAddress, MAX_ARGC_ENVC}; -use crate::mem::MmapMemory; +use crate::{ + mem::{MemoryError, MmapMemory}, + virt_to_phys, +}; /// `addr` is the address of the hypercall parameter in the guest's memory space. `data` is the /// parameter that was send to that address by the guest. @@ -99,7 +101,8 @@ pub fn read(mem: &MmapMemory, sysread: &mut ReadPrams) { unsafe { let bytes_read = libc::read( sysread.fd, - mem.host_address(sysread.buf).unwrap() as *mut libc::c_void, + mem.host_address(virt_to_phys(sysread.buf, mem).unwrap()) + .unwrap() as *mut libc::c_void, sysread.len, ); if bytes_read >= 0 { @@ -115,12 +118,9 @@ pub fn write(mem: &MmapMemory, syswrite: &WriteParams) -> io::Result<()> { let mut bytes_written: usize = 0; while bytes_written != syswrite.len { unsafe { - use std::io::{Error, ErrorKind}; - - use crate::mem::MemoryError; let step = libc::write( syswrite.fd, - mem.host_address(syswrite.buf + bytes_written) + mem.host_address(virt_to_phys(syswrite.buf + bytes_written as u64, mem).unwrap()) .map_err(|e| match e { MemoryError::BoundsViolation => { unreachable!("Bounds violation after host_address function") diff --git a/uhyve-interface/src/parameters.rs b/uhyve-interface/src/parameters.rs index 1d279b68..2f3887fe 100644 --- a/uhyve-interface/src/parameters.rs +++ b/uhyve-interface/src/parameters.rs @@ -2,7 +2,7 @@ use std::path::Path; -use crate::{GuestPhysAddr, MAX_ARGC_ENVC}; +use crate::{GuestPhysAddr, GuestVirtAddr, MAX_ARGC_ENVC}; /// Parameters for a [`Cmdsize`](crate::Hypercall::Cmdsize) hypercall which provides the lengths of the items in the argument end environment vector. #[repr(C, packed)] @@ -84,7 +84,7 @@ pub struct WriteParams { /// File descriptor of the file. pub fd: i32, /// Buffer to be written into the file. - pub buf: GuestPhysAddr, + pub buf: GuestVirtAddr, /// Number of bytes in the buffer to be written. pub len: usize, } @@ -96,7 +96,7 @@ pub struct ReadPrams { /// File descriptor of the file. pub fd: i32, /// Buffer to read the file into. - pub buf: GuestPhysAddr, + pub buf: GuestVirtAddr, /// Number of bytes to read into the buffer. pub len: usize, /// Number of bytes read on success. `-1` on failure.