Skip to content

Commit

Permalink
test: 🧪 add warning for false nsjail configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
Eason0729 committed Nov 24, 2023
1 parent ea3e4e9 commit b360939
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 11 deletions.
5 changes: 4 additions & 1 deletion judger/plugins/gcc-13/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
/rootfs
/rootfs
/src.cpp
/src.out
/compile
14 changes: 11 additions & 3 deletions judger/plugins/gcc-13/compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
#include <spawn.h>
#include <errno.h>
#include <sys/wait.h>
// #define CC "/usr/lib64/ccache/g++"
// #define SRC "src.cpp"
// #define OUT "src.out"
#define CC "/usr/local/bin/g++"
#define SRC "/src/src.cpp"
#define OUT "/src/src.out"
Expand All @@ -13,6 +16,11 @@
int main()
{
FILE *source = fopen(SRC, "w");
if (source == NULL)
{
printf("2: %m\n", errno);
return 1;
}

char *code = malloc(MAX_SIZE * sizeof(char));
size_t len = fread(code, sizeof(char), MAX_SIZE, stdin);
Expand All @@ -21,10 +29,10 @@ int main()
fclose(source);

char *args[] = {CC, SRC, "-lm", "-o", OUT, NULL};
int pid, status, spawn_ret;
if (execvp(CC, args) != -1)
int pid, status;
if (execv(CC, args) != -1)
{
printf("1: success execvp!\n");
printf("1: success execv!\n");
if (wait(NULL) != -1)
{
printf("0: success!\n");
Expand Down
2 changes: 2 additions & 0 deletions judger/src/langs/artifact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ impl ArtifactFactory {
let process = process.wait().await?;

if !process.succeed() {
#[cfg(debug_assertions)]
log::debug!("stdout: {}", String::from_utf8_lossy(&process.stdout));
return Err(Error::Report(JudgerCode::Ce));
}

Expand Down
2 changes: 1 addition & 1 deletion judger/src/sandbox/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl<'a> Container<'a> {
.cgroup(&cg_name)
.done()
.presist_vol(&self.id)
.mount("src", limit.lockdown)
.mount("src", false)
.done()
.common()
.cmds(args)
Expand Down
1 change: 1 addition & 0 deletions judger/src/sandbox/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ impl RunningProc {
}
}

#[derive(Debug)]
pub struct ExitProc {
pub status: ExitStatus,
pub stdout: Vec<u8>,
Expand Down
2 changes: 1 addition & 1 deletion judger/src/sandbox/utils/limiter/mem.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use cgroups_rs::{memory::MemController, Cgroup};

#[derive(Default, Clone)]
#[derive(Default, Clone, Debug)]
pub struct MemStatistics {
pub oom: bool,
pub peak: u64,
Expand Down
13 changes: 11 additions & 2 deletions judger/src/sandbox/utils/nsjail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ impl LimitBuilder {
self.cmds.push(Cow::Borrowed("--cgroup_mem_swap_max"));
self.cmds.push(Cow::Borrowed("0"));
self.cmds.push(Cow::Borrowed("--disable_clone_newcgroup"));
self.cmds.push(Cow::Borrowed("--user"));
self.cmds.push(Cow::Borrowed("9999"));
self.cmds.push(Cow::Borrowed("--group"));
self.cmds.push(Cow::Borrowed("9999"));

NaJailBuilder { cmds: self.cmds }
}
}
Expand Down Expand Up @@ -92,7 +97,7 @@ impl MountBuilder {
let source = source.to_str().unwrap();
let dist = vol.as_ref();

self.cmds.push(Cow::Owned(format!("{}:{}", source, dist)));
self.cmds.push(Cow::Owned(format!("{}:/{}", source, dist)));

self
}
Expand Down Expand Up @@ -185,7 +190,11 @@ impl NsJail {
let root = root.as_ref().canonicalize().unwrap();
let root = root.to_str().unwrap();
LimitBuilder {
cmds: vec![Cow::Borrowed("--chroot"), Cow::Owned(root.to_owned())],
cmds: vec![
Cow::Borrowed("--rw"),
Cow::Borrowed("--chroot"),
Cow::Owned(root.to_owned()),
],
}
}
pub async fn wait(&self) -> TermStatus {
Expand Down
6 changes: 3 additions & 3 deletions judger/src/test/langs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
grpc::proto::prelude::JudgeMatchRule, init::config::CONFIG, langs::prelude::ArtifactFactory,
};

async fn lua(factory:&mut ArtifactFactory){
async fn lua(factory: &mut ArtifactFactory) {
let uuid = Uuid::parse_str("f060f3c5-b2b2-46be-97ba-a128e5922aee").unwrap();

let mut compiled = factory
Expand All @@ -20,7 +20,7 @@ async fn lua(factory:&mut ArtifactFactory){
assert!(result.assert(b"hello world", JudgeMatchRule::SkipSnl));
}

async fn cpp(factory:&mut ArtifactFactory){
async fn cpp(factory: &mut ArtifactFactory) {
let uuid = Uuid::parse_str("8a9e1daf-ff89-42c3-b011-bf6fb4bd8b26").unwrap();

let mut compiled = factory
Expand All @@ -47,6 +47,6 @@ async fn test() {

factory.load_dir(config.plugin.path.clone()).await;

lua(&mut factory).await;
// lua(&mut factory).await;
cpp(&mut factory).await;
}

0 comments on commit b360939

Please sign in to comment.