-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update seccomp program #536
Changes from all commits
c8eb148
c7d323a
6a038ca
8dc6cf4
298812d
7fb2b4b
131ee6a
84a1a37
3516f92
c54e4a3
114e2c0
86efdc8
9971644
43bcdfa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,14 +7,16 @@ use std::{ | |
}, | ||
}; | ||
|
||
use std::str::FromStr; | ||
use nix::{ | ||
errno::Errno, | ||
ioctl_readwrite, ioctl_write_ptr, libc, | ||
libc::{SECCOMP_FILTER_FLAG_NEW_LISTENER, SECCOMP_SET_MODE_FILTER}, | ||
unistd, | ||
}; | ||
|
||
use crate::instruction::{Instruction, SECCOMP_IOC_MAGIC}; | ||
use syscalls::{SyscallArgs}; | ||
use crate::instruction::{*}; | ||
use crate::instruction::{Arch, Instruction, SECCOMP_IOC_MAGIC}; | ||
|
||
#[derive(Debug, thiserror::Error)] | ||
pub enum SeccompError { | ||
|
@@ -198,3 +200,77 @@ struct Filters { | |
pub len: c_ushort, | ||
pub filter: *const Instruction, | ||
} | ||
|
||
fn get_syscall_number(arc: &Arch, name: &str) -> Option<u64> { | ||
match arc { | ||
Arch::X86 => { | ||
match syscalls::x86_64::Sysno::from_str(name) { | ||
Ok(syscall) => Some(syscall as u64), | ||
Err(_) => None, | ||
} | ||
}, | ||
Arch::AArch64 => { | ||
match syscalls::aarch64::Sysno::from_str(name) { | ||
Ok(syscall) => Some(syscall as u64), | ||
Err(_) => None, | ||
} | ||
} | ||
} | ||
} | ||
|
||
#[derive(Debug)] | ||
pub struct InstructionData { | ||
pub arc: Arch, | ||
pub def_action: u32, | ||
pub rule_arr: Vec<Rule> | ||
} | ||
|
||
impl From<InstructionData> for Vec<Instruction> { | ||
fn from(inst_data: InstructionData) -> Self { | ||
let mut bpf_prog = gen_validate(&inst_data.arc); | ||
|
||
for rule in &inst_data.rule_arr { | ||
bpf_prog.append(&mut Rule::to_instruction(&inst_data.arc, inst_data.def_action, rule)); | ||
} | ||
|
||
bpf_prog.append(&mut vec![Instruction::stmt(BPF_RET | BPF_K, SECCOMP_RET_ALLOW)]); | ||
bpf_prog | ||
} | ||
} | ||
|
||
#[derive(Debug)] | ||
pub struct Rule { | ||
pub syscall: String, | ||
pub arg_cnt: u8, | ||
pub args: SyscallArgs, | ||
pub is_notify: bool | ||
} | ||
|
||
impl Rule { | ||
pub fn new(syscall: String, arg_cnt: u8, args: SyscallArgs, is_notify: bool) -> Self { | ||
Self { | ||
syscall, | ||
arg_cnt, | ||
args, | ||
is_notify, | ||
} | ||
} | ||
|
||
pub fn to_instruction(arch: &Arch, action: u32, rule: &Rule) -> Vec<Instruction> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 Fromを提案しておいてなんですが、無理せずこれでも十分使いやすいインタフェースだと思います。ありがとうございます。 |
||
let mut bpf_prog = gen_validate(arch); | ||
bpf_prog.append(&mut vec![Instruction::stmt(BPF_LD | BPF_W | BPF_ABS, 0)]); | ||
bpf_prog.append(&mut vec![Instruction::jump(BPF_JMP | BPF_JEQ | BPF_K, 0, 1, | ||
get_syscall_number(arch, &rule.syscall).unwrap() as c_uint)]); | ||
if rule.arg_cnt != 0 { | ||
bpf_prog.append(&mut vec![Instruction::stmt(BPF_LD | BPF_W | BPF_ABS, seccomp_data_args_offset().into())]); | ||
bpf_prog.append(&mut vec![Instruction::jump(BPF_JMP | BPF_JEQ | BPF_K, 0, 1, rule.args.arg0 as c_uint)]); | ||
} | ||
|
||
if rule.is_notify { | ||
bpf_prog.append(&mut vec![Instruction::stmt(BPF_RET | BPF_K, SECCOMP_RET_USER_NOTIF)]); | ||
} else { | ||
bpf_prog.append(&mut vec![Instruction::stmt(BPF_RET | BPF_K, action)]); | ||
} | ||
bpf_prog | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
もし可能だったら別PRでもいいですし、他の方でもいいんですが unit テスト足したいですね。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unit テストの書き方がまだわからないので、別PRで対応致しますm(- -)m