@@ -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 (
0 commit comments