diff --git a/src/child.rs b/src/child.rs index 4629ceb..3df6afb 100644 --- a/src/child.rs +++ b/src/child.rs @@ -6,10 +6,11 @@ use crate::mounts::setmountpoint; use crate::capabilities::setcapabilities; use crate::syscalls::setsyscalls; -use nix::unistd::{Pid, close}; +use nix::unistd::{Pid, close, execve}; use nix::sched::clone; use nix::sys::signal::Signal; use nix::sched::CloneFlags; +use std::ffi::CString; const STACK_SIZE: usize = 1024 * 1024; fn setup_container_configurations(config: &ContainerOpts) -> Result<(), Errcode> { @@ -36,7 +37,14 @@ fn child(config: ContainerOpts) -> isize { } log::info!("Starting container with command {} and args {:?}", config.path.to_str().unwrap(), config.argv); - 0 + let retcode = match execve::(&config.path, &config.argv, &[]){ + Ok(_) => 0, + Err(e) => { + log::error!("Error while trying to perform execve: {:?}", e); + -1 + } + }; + retcode } pub fn generate_child_process(config: ContainerOpts) -> Result { diff --git a/src/cli.rs b/src/cli.rs index e2c867d..5ab2c0d 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -37,6 +37,10 @@ pub fn parse_args() -> Result { return Err(Errcode::ArgumentInvalid("mount")); } + if args.command.is_empty() { + return Err(Errcode::ArgumentInvalid("command")); + } + Ok(args) } diff --git a/test.sh b/test.sh index ed8c897..2367598 100755 --- a/test.sh +++ b/test.sh @@ -1,4 +1,12 @@ #!/bin/bash +set -e + mkdir -p mountdir -cargo build && clear && sudo ./target/debug/crabcan --debug -u 0 -m ./mountdir/ -c "/bin/bash" +cd testbin +RUSTFLAGS="-C target-feature=+crt-static" cargo build --release --target="x86_64-unknown-linux-gnu" +cp target/x86_64-unknown-linux-gnu/release/testbin ../mountdir/ +cd .. +cargo build +clear +sudo ./target/debug/crabcan --debug -u 0 -m ./mountdir/ -c "/testbin" diff --git a/testbin/.gitignore b/testbin/.gitignore new file mode 100644 index 0000000..eb5a316 --- /dev/null +++ b/testbin/.gitignore @@ -0,0 +1 @@ +target diff --git a/testbin/Cargo.toml b/testbin/Cargo.toml new file mode 100644 index 0000000..50909fd --- /dev/null +++ b/testbin/Cargo.toml @@ -0,0 +1,4 @@ +[package] +name = "testbin" +version = "0.1.0" +edition = "2021" diff --git a/testbin/src/main.rs b/testbin/src/main.rs new file mode 100644 index 0000000..e7a11a9 --- /dev/null +++ b/testbin/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +}