@@ -7,7 +7,6 @@ use std::slice;
77
88use anyhow:: Result ;
99use nix:: {
10- libc,
1110 sys:: {
1211 signal:: Signal ,
1312 socket:: {
@@ -19,14 +18,11 @@ use nix::{
1918 unistd:: { close, mkdir} ,
2019} ;
2120use oci_spec:: runtime:: {
22- Arch as OciSpecArch , LinuxSeccompAction , LinuxSeccompArgBuilder , LinuxSeccompBuilder ,
23- LinuxSeccompOperator , LinuxSyscallBuilder ,
21+ Arch as OciSpecArch , LinuxSeccompAction , LinuxSeccompBuilder , LinuxSyscallBuilder ,
2422} ;
2523use seccomp:: seccomp:: SeccompProgramPlan ;
26- use seccomp:: testutil:: * ;
2724use syscall_numbers:: x86_64;
2825
29- #[ allow( dead_code) ]
3026fn send_fd < F : AsRawFd > ( sock : OwnedFd , fd : & F ) -> nix:: Result < ( ) > {
3127 let fd = fd. as_raw_fd ( ) ;
3228 let cmsgs = [ ControlMessage :: ScmRights ( slice:: from_ref ( & fd) ) ] ;
@@ -37,7 +33,6 @@ fn send_fd<F: AsRawFd>(sock: OwnedFd, fd: &F) -> nix::Result<()> {
3733 Ok ( ( ) )
3834}
3935
40- #[ allow( dead_code) ]
4136fn recv_fd < F : FromRawFd > ( sock : RawFd ) -> nix:: Result < Option < F > > {
4237 let mut iov_buf = [ ] ;
4338 let mut iov = [ IoSliceMut :: new ( & mut iov_buf) ] ;
@@ -53,7 +48,6 @@ fn recv_fd<F: FromRawFd>(sock: RawFd) -> nix::Result<Option<F>> {
5348 }
5449}
5550
56- #[ allow( dead_code) ]
5751async fn handle_notifications ( notify_fd : NotifyFd ) -> nix:: Result < ( ) > {
5852 loop {
5953 println ! ( "Waiting on next" ) ;
@@ -68,7 +62,6 @@ async fn handle_notifications(notify_fd: NotifyFd) -> nix::Result<()> {
6862 }
6963}
7064
71- #[ allow( dead_code) ]
7265async fn handle_signal ( pid : nix:: unistd:: Pid ) -> Result < ( ) > {
7366 let status = wait:: waitpid ( pid, None ) ?;
7467 match status {
@@ -87,16 +80,8 @@ async fn handle_signal(pid: nix::unistd::Pid) -> Result<()> {
8780 }
8881}
8982
90- fn main ( ) -> Result < ( ) > {
91- if let Err ( e) = generate_seccomp_instruction ( "tests/default_x86_64.json" . as_ref ( ) ) {
92- eprintln ! ( "Something wrong : {}" , e) ;
93- }
94- Ok ( ( ) )
95- }
96-
9783#[ tokio:: main]
98- #[ allow( dead_code) ]
99- async fn sub ( ) -> Result < ( ) > {
84+ async fn main ( ) -> Result < ( ) > {
10085 let ( sock_for_child, sock_for_parent) = socket:: socketpair (
10186 socket:: AddressFamily :: Unix ,
10287 SockType :: Stream ,
@@ -106,36 +91,22 @@ async fn sub() -> Result<()> {
10691
10792 let _ = prctl:: set_no_new_privileges ( true ) ;
10893
109- let _getcwd = LinuxSyscallBuilder :: default ( )
94+ let getcwd = LinuxSyscallBuilder :: default ( )
11095 . names ( vec ! [ "getcwd" . to_string( ) ] )
11196 . build ( ) ?;
112- let _write = LinuxSyscallBuilder :: default ( )
97+ let write = LinuxSyscallBuilder :: default ( )
11398 . names ( vec ! [ "write" . to_string( ) ] )
114- . args ( vec ! [ LinuxSeccompArgBuilder :: default ( )
115- . index( 1usize )
116- . value( libc:: STDERR_FILENO as u64 )
117- . op( LinuxSeccompOperator :: ScmpCmpEq )
118- . build( ) ?] )
11999 . build ( ) ?;
120- let _syscall_mkdir = LinuxSyscallBuilder :: default ( )
100+ let syscall_mkdir = LinuxSyscallBuilder :: default ( )
121101 . names ( vec ! [ "mkdir" . to_string( ) ] )
122102 . action ( LinuxSeccompAction :: ScmpActNotify )
123103 . build ( ) ?;
124- let _personality = LinuxSyscallBuilder :: default ( )
125- . names ( vec ! [ "clone3" . to_string( ) ] )
126- // .args(vec![LinuxSeccompArgBuilder::default()
127- // .index(0usize)
128- // .value(2114060288u64)
129- // .op(LinuxSeccompOperator::ScmpCmpLe)
130- // .build()?])
131- . action ( LinuxSeccompAction :: ScmpActErrno )
132- . build ( ) ?;
133104
134105 let spec_seccomp = LinuxSeccompBuilder :: default ( )
135106 . architectures ( vec ! [ OciSpecArch :: ScmpArchX86_64 ] )
136107 . default_action ( LinuxSeccompAction :: ScmpActErrno )
137108 . default_errno_ret ( 1u32 )
138- . syscalls ( vec ! [ _personality ] )
109+ . syscalls ( vec ! [ getcwd , write , syscall_mkdir ] )
139110 . build ( ) ?;
140111
141112 let inst_data = SeccompProgramPlan :: try_from ( spec_seccomp) ?;
@@ -144,14 +115,6 @@ async fn sub() -> Result<()> {
144115 seccomp. set_flags ( inst_data. flags . clone ( ) ) ;
145116 }
146117 seccomp. filters = Vec :: try_from ( inst_data) ?;
147-
148- for filter in & seccomp. filters {
149- println ! (
150- "code: {:02x}, jt: {:02x}, jf: {:02x}, k: {:08x}" ,
151- filter. code, filter. offset_jump_true, filter. offset_jump_false, filter. multiuse_field
152- )
153- }
154-
155118 tokio:: spawn ( async move {
156119 tokio:: signal:: ctrl_c ( )
157120 . await
0 commit comments