Skip to content

Commit f69f47a

Browse files
authored
Merge pull request #9 from jjs-dev/secutiry
Add security test
2 parents 8b6ae57 + 8147bd4 commit f69f47a

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

minion-tests/src/tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ fn get_tests() -> Vec<&'static dyn TestCase> {
1515
extend_lifetime(simple::TIdle),
1616
extend_lifetime(simple::TRet1),
1717
extend_lifetime(simple::TOom),
18+
extend_lifetime(simple::TSecurity),
1819
]
1920
}
2021

minion-tests/src/tests/simple.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,38 @@ impl crate::TestCase for TOom {
140140
}
141141
}
142142

143+
pub(crate) struct TSecurity;
144+
impl crate::TestCase for TSecurity {
145+
fn name(&self) -> &'static str {
146+
"test_security_restrictions"
147+
}
148+
fn description(&self) -> &'static str {
149+
"verifies that isolated program can not make certain bad things"
150+
}
151+
fn test(&self) -> ! {
152+
// Check we can not read pid1's environment.
153+
let err = std::fs::read("/proc/1/environ").unwrap_err();
154+
assert_eq!(err.kind(), std::io::ErrorKind::PermissionDenied);
155+
// Check we can not create mounts.
156+
std::fs::create_dir("/prcfs").unwrap();
157+
let err = nix::mount::mount(
158+
Some("proc"),
159+
"/prcfs",
160+
Some("proc"),
161+
nix::mount::MsFlags::empty(),
162+
None::<&str>,
163+
)
164+
.unwrap_err();
165+
assert!(matches!(err, nix::Error::Sys(nix::errno::Errno::EPERM)));
166+
std::process::exit(24)
167+
}
168+
fn check(&self, cp: &mut dyn minion::ChildProcess, d: minion::DominionRef) {
169+
super::assert_exit_code(cp, 24);
170+
super::assert_empty(&mut cp.stdout().unwrap());
171+
super::assert_empty(&mut cp.stderr().unwrap());
172+
}
173+
}
174+
143175
fn exceed_time_limit() -> ! {
144176
loop {
145177
unsafe {

0 commit comments

Comments
 (0)