Skip to content

Commit 94970e2

Browse files
committed
create example dir and move main.rs
Signed-off-by: sat0ken <15720506+sat0ken@users.noreply.github.com>
1 parent a2a5f2d commit 94970e2

File tree

4 files changed

+17
-45
lines changed

4 files changed

+17
-45
lines changed
Lines changed: 6 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use std::slice;
77

88
use anyhow::Result;
99
use nix::{
10-
libc,
1110
sys::{
1211
signal::Signal,
1312
socket::{
@@ -19,14 +18,11 @@ use nix::{
1918
unistd::{close, mkdir},
2019
};
2120
use oci_spec::runtime::{
22-
Arch as OciSpecArch, LinuxSeccompAction, LinuxSeccompArgBuilder, LinuxSeccompBuilder,
23-
LinuxSeccompOperator, LinuxSyscallBuilder,
21+
Arch as OciSpecArch, LinuxSeccompAction, LinuxSeccompBuilder, LinuxSyscallBuilder,
2422
};
2523
use seccomp::seccomp::SeccompProgramPlan;
26-
use seccomp::testutil::*;
2724
use syscall_numbers::x86_64;
2825

29-
#[allow(dead_code)]
3026
fn 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)]
4136
fn 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)]
5751
async 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)]
7265
async 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
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
use anyhow::Result;
2+
#[path = "../tests/testutil.rs"]
3+
mod testutil;
4+
5+
fn main() -> Result<()> {
6+
if let Err(e) = testutil::generate_seccomp_instruction("tests/default_x86_64.json".as_ref()) {
7+
eprintln!("Something wrong : {}", e);
8+
}
9+
Ok(())
10+
}

experiment/seccomp/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
pub mod instruction;
22
pub mod seccomp;
3-
pub mod testutil;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
use crate::seccomp::{Seccomp, SeccompProgramPlan};
21
use oci_spec::runtime::{
32
Arch as OciSpecArch, LinuxSeccomp, LinuxSeccompBuilder, LinuxSyscall, LinuxSyscallBuilder,
43
};
54

5+
use seccomp::seccomp::{Seccomp, SeccompProgramPlan};
66
use std::fs;
77
use std::io;
88
use std::path::Path;

0 commit comments

Comments
 (0)