Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(hypercall): introduce chdir and uhyve mountpoint restrictions #1485

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion src/fs/uhyve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ const UHYVE_PORT_OPEN: u16 = 0x440;
const UHYVE_PORT_CLOSE: u16 = 0x480;
const UHYVE_PORT_READ: u16 = 0x500;
const UHYVE_PORT_LSEEK: u16 = 0x580;
const UHYVE_PORT_CHDIR: u16 = 0x820;
const UHYVE_PORT_UNLINK: u16 = 0x840;

#[repr(C, packed)]
Expand Down Expand Up @@ -142,6 +143,22 @@ impl SysLseek {
}
}

#[repr(C, packed)]
struct SysChdir {
name: PhysAddr,
ret: i32,
}

impl SysChdir {
fn new(name: VirtAddr) -> SysChdir {
SysChdir {
name: paging::virtual_to_physical(name).unwrap(),
ret: -1,
}
}
}


#[repr(C, packed)]
struct SysUnlink {
name: PhysAddr,
Expand Down Expand Up @@ -321,7 +338,17 @@ impl VfsNode for UhyveDirectory {
pub(crate) fn init() {
info!("Try to initialize uhyve filesystem");
if is_uhyve() {
let mount_point = hermit_var_or!("UHYVE_MOUNT", "/root").to_string();
// TODO: Use FDT instead?
let mut mount_point = hermit_var_or!("UHYVE_MOUNTPOINT", "/root").to_string();
if ["/tmp", "/proc", ".", ".."].iter().any(|path| mount_point.starts_with(*path)) {
error!("UHYVE_MOUNTPOINT {} invalid, falling back to /root and informing host...", mount_point);
mount_point = "/root".to_owned();
let mut syschdir: SysChdir = SysChdir::new(VirtAddr::from_ptr(mount_point.as_ptr()));
uhyve_send(UHYVE_PORT_CHDIR, &mut syschdir);
if syschdir.ret != 0 {
panic!("Could not change invalid mount point to /root");
}
}
info!("Mounting uhyve filesystem at {}", mount_point);
fs::FILESYSTEM
.get()
Expand Down
Loading