Skip to content

Commit 23b1511

Browse files
committed
Remove seccomp related tests
Signed-off-by: Doru Blânzeanu <dblnz@pm.me>
1 parent 09bed26 commit 23b1511

File tree

3 files changed

+0
-184
lines changed

3 files changed

+0
-184
lines changed

src/hyperlight_host/src/sandbox/initialized_multi_use.rs

Lines changed: 0 additions & 157 deletions
Original file line numberDiff line numberDiff line change
@@ -655,163 +655,6 @@ mod tests {
655655
assert_eq!(res, 0);
656656
}
657657

658-
#[test]
659-
// TODO: Investigate why this test fails with an incorrect error when run alongside other tests
660-
#[ignore]
661-
#[cfg(target_os = "linux")]
662-
fn test_violate_seccomp_filters() -> Result<()> {
663-
fn make_get_pid_syscall() -> Result<u64> {
664-
let pid = unsafe { libc::syscall(libc::SYS_getpid) };
665-
Ok(pid as u64)
666-
}
667-
668-
// First, run to make sure it fails.
669-
{
670-
let mut usbox = UninitializedSandbox::new(
671-
GuestBinary::FilePath(simple_guest_as_string().expect("Guest Binary Missing")),
672-
None,
673-
)
674-
.unwrap();
675-
676-
usbox.register("MakeGetpidSyscall", make_get_pid_syscall)?;
677-
678-
let mut sbox: MultiUseSandbox = usbox.evolve()?;
679-
680-
let res: Result<u64> = sbox.call("ViolateSeccompFilters", ());
681-
682-
#[cfg(seccomp)]
683-
match res {
684-
Ok(_) => panic!("Expected to fail due to seccomp violation"),
685-
Err(e) => match e {
686-
HyperlightError::GuestError(t, msg)
687-
if t == ErrorCode::HostFunctionError
688-
&& msg.contains("Seccomp filter trapped on disallowed syscall") => {}
689-
_ => panic!("Expected DisallowedSyscall error: {}", e),
690-
},
691-
}
692-
693-
#[cfg(not(seccomp))]
694-
match res {
695-
Ok(_) => (),
696-
Err(e) => panic!("Expected to succeed without seccomp: {}", e),
697-
}
698-
}
699-
700-
// Second, run with allowing `SYS_getpid`
701-
#[cfg(seccomp)]
702-
{
703-
let mut usbox = UninitializedSandbox::new(
704-
GuestBinary::FilePath(simple_guest_as_string().expect("Guest Binary Missing")),
705-
None,
706-
)
707-
.unwrap();
708-
709-
usbox.register_with_extra_allowed_syscalls(
710-
"MakeGetpidSyscall",
711-
make_get_pid_syscall,
712-
vec![libc::SYS_getpid],
713-
)?;
714-
// ^^^ note, we are allowing SYS_getpid
715-
716-
let mut sbox: MultiUseSandbox = usbox.evolve()?;
717-
718-
let res: Result<u64> = sbox.call("ViolateSeccompFilters", ());
719-
720-
match res {
721-
Ok(_) => {}
722-
Err(e) => panic!("Expected to succeed due to seccomp violation: {}", e),
723-
}
724-
}
725-
726-
Ok(())
727-
}
728-
729-
// We have a secomp specifically for `openat`, but we don't want to crash on `openat`, but rather make sure `openat` returns `EACCES`
730-
#[test]
731-
#[cfg(target_os = "linux")]
732-
fn violate_seccomp_filters_openat() -> Result<()> {
733-
// Hostcall to call `openat`.
734-
fn make_openat_syscall() -> Result<i64> {
735-
use std::ffi::CString;
736-
737-
let path = CString::new("/proc/sys/vm/overcommit_memory").unwrap();
738-
739-
let fd_or_err = unsafe {
740-
libc::syscall(
741-
libc::SYS_openat,
742-
libc::AT_FDCWD,
743-
path.as_ptr(),
744-
libc::O_RDONLY,
745-
)
746-
};
747-
748-
if fd_or_err == -1 {
749-
Ok((-std::io::Error::last_os_error().raw_os_error().unwrap()).into())
750-
} else {
751-
Ok(fd_or_err)
752-
}
753-
}
754-
{
755-
// First make sure a regular call to `openat` on /proc/sys/vm/overcommit_memory succeeds
756-
let ret = make_openat_syscall()?;
757-
assert!(
758-
ret >= 0,
759-
"Expected openat syscall to succeed, got: {:?}",
760-
ret
761-
);
762-
763-
let mut ubox = UninitializedSandbox::new(
764-
GuestBinary::FilePath(simple_guest_as_string().expect("Guest Binary Missing")),
765-
None,
766-
)
767-
.unwrap();
768-
ubox.register("Openat_Hostfunc", make_openat_syscall)?;
769-
770-
let mut sbox = ubox.evolve().unwrap();
771-
let host_func_result = sbox
772-
.call::<i64>(
773-
"CallGivenParamlessHostFuncThatReturnsI64",
774-
"Openat_Hostfunc".to_string(),
775-
)
776-
.expect("Expected to call host function that returns i64");
777-
778-
if cfg!(seccomp) {
779-
// If seccomp is enabled, we expect the syscall to return EACCES, as setup by our seccomp filter
780-
assert_eq!(host_func_result, -libc::EACCES as i64);
781-
} else {
782-
// If seccomp is not enabled, we expect the syscall to succeed
783-
assert!(host_func_result >= 0);
784-
}
785-
}
786-
787-
#[cfg(seccomp)]
788-
{
789-
// Now let's make sure if we register the `openat` syscall as an extra allowed syscall, it will succeed
790-
let mut ubox = UninitializedSandbox::new(
791-
GuestBinary::FilePath(simple_guest_as_string().expect("Guest Binary Missing")),
792-
None,
793-
)
794-
.unwrap();
795-
ubox.register_with_extra_allowed_syscalls(
796-
"Openat_Hostfunc",
797-
make_openat_syscall,
798-
[libc::SYS_openat],
799-
)?;
800-
let mut sbox = ubox.evolve().unwrap();
801-
let host_func_result: i64 = sbox
802-
.call::<i64>(
803-
"CallGivenParamlessHostFuncThatReturnsI64",
804-
"Openat_Hostfunc".to_string(),
805-
)
806-
.expect("Expected to call host function that returns i64");
807-
808-
// should pass regardless of seccomp feature
809-
assert!(host_func_result >= 0);
810-
}
811-
812-
Ok(())
813-
}
814-
815658
#[test]
816659
fn test_trigger_exception_on_guest() {
817660
let usbox = UninitializedSandbox::new(

src/hyperlight_host/tests/integration_test.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,8 @@ fn interrupt_host_call() {
4949
Ok(())
5050
};
5151

52-
#[cfg(any(target_os = "windows", not(seccomp)))]
5352
usbox.register("Spin", spin).unwrap();
5453

55-
#[cfg(seccomp)]
56-
usbox
57-
.register_with_extra_allowed_syscalls("Spin", spin, vec![libc::SYS_clock_nanosleep])
58-
.unwrap();
59-
6054
let mut sandbox: MultiUseSandbox = usbox.evolve().unwrap();
6155
let interrupt_handle = sandbox.interrupt_handle();
6256
assert!(!interrupt_handle.dropped()); // not yet dropped

src/tests/rust_guests/simpleguest/src/main.rs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -720,19 +720,6 @@ fn twenty_four_k_in_eight_k_out(function_call: &FunctionCall) -> Result<Vec<u8>>
720720
}
721721
}
722722

723-
fn violate_seccomp_filters(function_call: &FunctionCall) -> Result<Vec<u8>> {
724-
if function_call.parameters.is_none() {
725-
let res = call_host_function::<u64>("MakeGetpidSyscall", None, ReturnType::ULong)?;
726-
727-
Ok(get_flatbuffer_result(res))
728-
} else {
729-
Err(HyperlightGuestError::new(
730-
ErrorCode::GuestFunctionParameterTypeMismatch,
731-
"Invalid parameters passed to violate_seccomp_filters".to_string(),
732-
))
733-
}
734-
}
735-
736723
fn call_given_paramless_hostfunc_that_returns_i64(function_call: &FunctionCall) -> Result<Vec<u8>> {
737724
if let ParameterValue::String(hostfuncname) =
738725
function_call.parameters.clone().unwrap()[0].clone()
@@ -1416,14 +1403,6 @@ pub extern "C" fn hyperlight_main() {
14161403
);
14171404
register_function(add_to_static_and_fail_def);
14181405

1419-
let violate_seccomp_filters_def = GuestFunctionDefinition::new(
1420-
"ViolateSeccompFilters".to_string(),
1421-
Vec::new(),
1422-
ReturnType::ULong,
1423-
violate_seccomp_filters as usize,
1424-
);
1425-
register_function(violate_seccomp_filters_def);
1426-
14271406
let echo_float_def = GuestFunctionDefinition::new(
14281407
"EchoFloat".to_string(),
14291408
Vec::from(&[ParameterType::Float]),

0 commit comments

Comments
 (0)