From 1ab58a21fb6ffcbd90ff5374599d0e80fed2d906 Mon Sep 17 00:00:00 2001 From: Harry Stern Date: Sun, 3 Mar 2024 23:14:38 -0500 Subject: [PATCH 1/2] Update libc Signed-off-by: Harry Stern --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index a1f4bfc..88dae9b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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} From a7a9a7baa56e90add8a4d3f5b6ecc2f6dc3fc1bc Mon Sep 17 00:00:00 2001 From: Harry Stern Date: Sun, 3 Mar 2024 23:15:03 -0500 Subject: [PATCH 2/2] Use libc seccomp constants Use libc constants now that rust-lang/libc/pull/3343 is merged and released. SECCOMP_RET_MASK does not exist anymore and appears to have not existed for a while. SECCOMP_RET_DATA is exactly the same mask value, and the usage here is in line with the man page. Completes #60 Signed-off-by: Harry Stern --- src/backend/bpf.rs | 13 +------------ src/backend/mod.rs | 14 ++++++++------ src/lib.rs | 6 +----- 3 files changed, 10 insertions(+), 23 deletions(-) diff --git a/src/backend/bpf.rs b/src/backend/bpf.rs index a29422a..aef397a 100644 --- a/src/backend/bpf.rs +++ b/src/backend/bpf.rs @@ -75,7 +75,7 @@ pub(crate) fn build_arch_validation_sequence(target_arch: TargetArch) -> Vec 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, } } diff --git a/src/lib.rs b/src/lib.rs index 2e93b78..10f3a79 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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 -const SECCOMP_SET_MODE_FILTER: libc::c_int = 1; - // BPF structure definition for filter array. // See /usr/include/linux/filter.h . #[repr(C)] @@ -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, )