Filter

Struct Filter 

Source
pub struct Filter { /* private fields */ }
Expand description

The Filter is a wrapper around a SECCOMP Context.

This implementation has first-class support for the SECCOMP Notify API, but a lot of the logic needs to be implemented in the application. Firstly, implement the Notifier trait for the calling process (The one that loads the filter). Then, use a notify::Pair on the monitoring process. A working implementation of both exist in Antimony.

§Examples

Load a basic rule that logs everything but read.

use seccomp::{filter::Filter, action::Action, attribute::Attribute, syscall::Syscall};
let mut filter = Filter::new(Action::Log).unwrap();
filter.set_attribute(Attribute::NoNewPrivileges(true)).unwrap();
filter.add_rule(Action::Allow, Syscall::from_name("read").unwrap()).unwrap();
filter.load();

Implementations§

Source§

impl Filter

Source

pub fn new(def_action: Action) -> Result<Self, Error>

Construct a new filter with a default action.

Source

pub fn set_notifier(&mut self, f: impl Notifier)

Set a notifier monitor process. See the Notifier trait for more information.

Source

pub fn set_attribute(&mut self, attr: Attribute) -> Result<(), Error>

Set an attribute.

Source

pub fn add_rule( &mut self, action: Action, syscall: Syscall, ) -> Result<(), Error>

Add a rule. Complex rules are not supported.

Source

pub fn write(&self, path: &Path) -> Result<OwnedFd, Error>

Write the filter to a new file with the BPF format of the filter.

Source

pub fn setup(&mut self) -> Result<(), Error>

Execute the notifier’s setup functions. This is necessary to call before calling load().

Source

pub fn load(self)

Loads the policy, optionally executing a Notifier function.

Note that this function treats failure as fatal. It will panic the program if the policy cannot be loaded.

Trait Implementations§

Source§

impl Drop for Filter

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Send for Filter

Source§

impl Sync for Filter

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.