#[derive(Default, Debug, Clone, PartialEq, Eq)]
#[derive(Deserialize, Serialize)]
#[serde(deny_unknown_fields)]
pub struct SeccompConfiguration
{
#[serde(default = "SeccompConfiguration::default_action_default")] pub default_action: Action,
#[serde(default)] pub bad_architecture_action: Action,
#[serde(default)] pub log_not_allowed_actions: bool,
#[serde(default)] pub rules: HashMap<SYS, Rule>,
}
impl SeccompConfiguration
{
#[inline(always)]
pub fn load(&self) -> Result<(), ()>
{
let seccomp_context = SeccompContext::new(self.default_action)?;
seccomp_context.set_architecture(scmp_arch::SCMP_ARCH_NATIVE)?;
seccomp_context.set_bad_architecture_action(self.bad_architecture_action)?;
seccomp_context.set_no_new_privileges_on_filter_load(true)?;
seccomp_context.synchronize_all_threads_with_same_seccomp_context_on_filter_load(true)?;
seccomp_context.allow_tracing_with_syscall_number_negative_one(false)?;
seccomp_context.log_not_allowed_actions(self.log_not_allowed_actions)?;
seccomp_context.disable_speculative_store_bypass(false)?;
for (system_call, &Rule { action_to_take, priority, ref comparisons }) in self.rules.iter()
{
let system_call_number = system_call as usize as i32;
seccomp_context.set_system_call_priority(system_call_number, priority)?;
seccomp_context.add_rule_for_system_call(system_call_number, action_to_take, &comparisons)?;
}
seccomp_context.load()
}
#[inline(always)]
const fn default_action_default() -> Action
{
Action::Allow
}
}