Crate libseccomp[][src]

Expand description

Rust Language Bindings for the libseccomp Library

The libseccomp library provides an easy to use, platform independent, interface to the Linux Kernel’s syscall filtering mechanism. The libseccomp API is designed to abstract away the underlying BPF based syscall filter language and present a more conventional function-call based filtering interface that should be familiar to, and easily adopted by, application developers.

The libseccomp crate is a high-level safe API for the libseccomp library.

Examples

use libseccomp::*;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut filter = ScmpFilterContext::new_filter(ScmpAction::Allow)?;
    let syscall = get_syscall_from_name("getuid", None)?;

    filter.add_arch(ScmpArch::X8664)?;
    filter.add_rule(ScmpAction::Errno(1), syscall)?;
    filter.load()?;

    Ok(())
}
use libseccomp::*;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut filter = ScmpFilterContext::new_filter(ScmpAction::Allow)?;
    let syscall = get_syscall_from_name("dup3", Some(ScmpArch::X8664))?;
    let cmp = ScmpArgCompare::new(0, ScmpCompareOp::Equal, 1);

    filter.add_arch(ScmpArch::X8664)?;
    filter.add_rule_conditional(ScmpAction::Errno(libc::EPERM), syscall, &[cmp])?;
    filter.load()?;

    Ok(())
}

Modules

Macros

A macro to create ScmpArgCompare in a more elegant way.

Structs

Represents a rule in a libseccomp filter context.

Represents a filter context in the libseccomp.

Represents the version information of the libseccomp library.

Enums

Represents an action to be taken on a filter rule match in the libseccomp.

Represents a CPU architecture. Seccomp can restrict syscalls on a per-architecture basis.

Represents a comparison operator which can be used in a filter rule.

Represents filter attributes.

Functions

Checks that both the libseccomp API level and the libseccomp version being used are equal to or greater than the specified API level and version.

Checks that the libseccomp version being used is equal to or greater than the specified version.

Gets the API level supported by the system.

Deprecated alias for ScmpVersion::current().

get_native_archDeprecated

Deprecated alias for ScmpArch::native().

Gets the number of a syscall by name for a given architecture’s ABI.

Retrieves the name of a syscall from its number for a given architecture.

Sets the API level forcibly.