Skip to content
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

Libc update #71

Merged
merged 2 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ edition = "2021"
json = ["serde", "serde_json"]

[dependencies]
libc = "^0.2.39"
libc = "^0.2.153"
serde = { version = "^1.0.27", features = ["derive"], optional = true}
serde_json = {version = "^1.0.9", optional = true}
13 changes: 1 addition & 12 deletions src/backend/bpf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ pub(crate) fn build_arch_validation_sequence(target_arch: TargetArch) -> Vec<soc
vec![
bpf_stmt(BPF_LD | BPF_W | BPF_ABS, SECCOMP_DATA_ARCH_OFFSET as u32),
bpf_jump(BPF_JMP | BPF_JEQ | BPF_K, audit_arch_value, 1, 0),
bpf_stmt(BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS),
bpf_stmt(BPF_RET | BPF_K, libc::SECCOMP_RET_KILL_PROCESS),
]
}

Expand Down Expand Up @@ -112,17 +112,6 @@ pub const BPF_JGE: u16 = 0x30;
// Test against the value in the K register.
pub const BPF_K: u16 = 0x00;

// Return codes for BPF programs.
// See /usr/include/linux/seccomp.h .
pub const SECCOMP_RET_ALLOW: u32 = 0x7fff_0000;
pub const SECCOMP_RET_ERRNO: u32 = 0x0005_0000;
pub const SECCOMP_RET_KILL_THREAD: u32 = 0x0000_0000;
pub const SECCOMP_RET_KILL_PROCESS: u32 = 0x8000_0000;
pub const SECCOMP_RET_LOG: u32 = 0x7ffc_0000;
pub const SECCOMP_RET_TRACE: u32 = 0x7ff0_0000;
pub const SECCOMP_RET_TRAP: u32 = 0x0003_0000;
pub const SECCOMP_RET_MASK: u32 = 0x0000_ffff;

// Architecture identifier for x86_64 LE.
// See /usr/include/linux/audit.h .
// Defined as:
Expand Down
14 changes: 8 additions & 6 deletions src/backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ use serde::Deserialize;
use core::fmt::Formatter;
use std::fmt::Display;

use bpf::{
ARG_NUMBER_MAX, AUDIT_ARCH_AARCH64, AUDIT_ARCH_X86_64, BPF_MAX_LEN, SECCOMP_RET_ALLOW,
SECCOMP_RET_ERRNO, SECCOMP_RET_KILL_PROCESS, SECCOMP_RET_KILL_THREAD, SECCOMP_RET_LOG,
SECCOMP_RET_MASK, SECCOMP_RET_TRACE, SECCOMP_RET_TRAP,
// See /usr/include/linux/seccomp.h
use libc::{
SECCOMP_RET_ALLOW, SECCOMP_RET_DATA, SECCOMP_RET_ERRNO, SECCOMP_RET_KILL_PROCESS,
SECCOMP_RET_KILL_THREAD, SECCOMP_RET_LOG, SECCOMP_RET_TRACE, SECCOMP_RET_TRAP,
};

use bpf::{ARG_NUMBER_MAX, AUDIT_ARCH_AARCH64, AUDIT_ARCH_X86_64, BPF_MAX_LEN};

pub use bpf::{sock_filter, BpfProgram, BpfProgramRef};

/// Backend Result type.
Expand Down Expand Up @@ -173,11 +175,11 @@ impl From<SeccompAction> for u32 {
fn from(action: SeccompAction) -> Self {
match action {
SeccompAction::Allow => SECCOMP_RET_ALLOW,
SeccompAction::Errno(x) => SECCOMP_RET_ERRNO | (x & SECCOMP_RET_MASK),
SeccompAction::Errno(x) => SECCOMP_RET_ERRNO | (x & SECCOMP_RET_DATA),
SeccompAction::KillThread => SECCOMP_RET_KILL_THREAD,
SeccompAction::KillProcess => SECCOMP_RET_KILL_PROCESS,
SeccompAction::Log => SECCOMP_RET_LOG,
SeccompAction::Trace(x) => SECCOMP_RET_TRACE | (x & SECCOMP_RET_MASK),
SeccompAction::Trace(x) => SECCOMP_RET_TRACE | (x & SECCOMP_RET_DATA),
SeccompAction::Trap => SECCOMP_RET_TRAP,
}
}
Expand Down
6 changes: 1 addition & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,6 @@ pub use backend::{
SeccompCmpOp, SeccompCondition, SeccompFilter, SeccompRule, TargetArch,
};

// Until https://github.com/rust-lang/libc/issues/3342 is fixed, define locally
// From <linux/seccomp.h>
const SECCOMP_SET_MODE_FILTER: libc::c_int = 1;

// BPF structure definition for filter array.
// See /usr/include/linux/filter.h .
#[repr(C)]
Expand Down Expand Up @@ -361,7 +357,7 @@ fn apply_filter_with_flags(bpf_filter: BpfProgramRef, flags: libc::c_ulong) -> R
let rc = unsafe {
libc::syscall(
libc::SYS_seccomp,
SECCOMP_SET_MODE_FILTER,
libc::SECCOMP_SET_MODE_FILTER,
flags,
bpf_prog_ptr,
)
Expand Down