Skip to content

Commit b6907ec

Browse files
boustrophedonalindima
authored andcommitted
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 <[email protected]>
1 parent bde51c7 commit b6907ec

File tree

3 files changed

+10
-23
lines changed

3 files changed

+10
-23
lines changed

src/backend/bpf.rs

+1-12
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ pub(crate) fn build_arch_validation_sequence(target_arch: TargetArch) -> Vec<soc
7575
vec![
7676
bpf_stmt(BPF_LD | BPF_W | BPF_ABS, SECCOMP_DATA_ARCH_OFFSET as u32),
7777
bpf_jump(BPF_JMP | BPF_JEQ | BPF_K, audit_arch_value, 1, 0),
78-
bpf_stmt(BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS),
78+
bpf_stmt(BPF_RET | BPF_K, libc::SECCOMP_RET_KILL_PROCESS),
7979
]
8080
}
8181

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

115-
// Return codes for BPF programs.
116-
// See /usr/include/linux/seccomp.h .
117-
pub const SECCOMP_RET_ALLOW: u32 = 0x7fff_0000;
118-
pub const SECCOMP_RET_ERRNO: u32 = 0x0005_0000;
119-
pub const SECCOMP_RET_KILL_THREAD: u32 = 0x0000_0000;
120-
pub const SECCOMP_RET_KILL_PROCESS: u32 = 0x8000_0000;
121-
pub const SECCOMP_RET_LOG: u32 = 0x7ffc_0000;
122-
pub const SECCOMP_RET_TRACE: u32 = 0x7ff0_0000;
123-
pub const SECCOMP_RET_TRAP: u32 = 0x0003_0000;
124-
pub const SECCOMP_RET_MASK: u32 = 0x0000_ffff;
125-
126115
// Architecture identifier for x86_64 LE.
127116
// See /usr/include/linux/audit.h .
128117
// Defined as:

src/backend/mod.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@ use serde::Deserialize;
1919
use core::fmt::Formatter;
2020
use std::fmt::Display;
2121

22-
use bpf::{
23-
ARG_NUMBER_MAX, AUDIT_ARCH_AARCH64, AUDIT_ARCH_X86_64, BPF_MAX_LEN, SECCOMP_RET_ALLOW,
24-
SECCOMP_RET_ERRNO, SECCOMP_RET_KILL_PROCESS, SECCOMP_RET_KILL_THREAD, SECCOMP_RET_LOG,
25-
SECCOMP_RET_MASK, SECCOMP_RET_TRACE, SECCOMP_RET_TRAP,
22+
// See /usr/include/linux/seccomp.h
23+
use libc::{
24+
SECCOMP_RET_ALLOW, SECCOMP_RET_DATA, SECCOMP_RET_ERRNO, SECCOMP_RET_KILL_PROCESS,
25+
SECCOMP_RET_KILL_THREAD, SECCOMP_RET_LOG, SECCOMP_RET_TRACE, SECCOMP_RET_TRAP,
2626
};
2727

28+
use bpf::{ARG_NUMBER_MAX, AUDIT_ARCH_AARCH64, AUDIT_ARCH_X86_64, BPF_MAX_LEN};
29+
2830
pub use bpf::{sock_filter, BpfProgram, BpfProgramRef};
2931

3032
/// Backend Result type.
@@ -173,11 +175,11 @@ impl From<SeccompAction> for u32 {
173175
fn from(action: SeccompAction) -> Self {
174176
match action {
175177
SeccompAction::Allow => SECCOMP_RET_ALLOW,
176-
SeccompAction::Errno(x) => SECCOMP_RET_ERRNO | (x & SECCOMP_RET_MASK),
178+
SeccompAction::Errno(x) => SECCOMP_RET_ERRNO | (x & SECCOMP_RET_DATA),
177179
SeccompAction::KillThread => SECCOMP_RET_KILL_THREAD,
178180
SeccompAction::KillProcess => SECCOMP_RET_KILL_PROCESS,
179181
SeccompAction::Log => SECCOMP_RET_LOG,
180-
SeccompAction::Trace(x) => SECCOMP_RET_TRACE | (x & SECCOMP_RET_MASK),
182+
SeccompAction::Trace(x) => SECCOMP_RET_TRACE | (x & SECCOMP_RET_DATA),
181183
SeccompAction::Trap => SECCOMP_RET_TRAP,
182184
}
183185
}

src/lib.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,6 @@ pub use backend::{
208208
SeccompCmpOp, SeccompCondition, SeccompFilter, SeccompRule, TargetArch,
209209
};
210210

211-
// Until https://github.com/rust-lang/libc/issues/3342 is fixed, define locally
212-
// From <linux/seccomp.h>
213-
const SECCOMP_SET_MODE_FILTER: libc::c_int = 1;
214-
215211
// BPF structure definition for filter array.
216212
// See /usr/include/linux/filter.h .
217213
#[repr(C)]
@@ -361,7 +357,7 @@ fn apply_filter_with_flags(bpf_filter: BpfProgramRef, flags: libc::c_ulong) -> R
361357
let rc = unsafe {
362358
libc::syscall(
363359
libc::SYS_seccomp,
364-
SECCOMP_SET_MODE_FILTER,
360+
libc::SECCOMP_SET_MODE_FILTER,
365361
flags,
366362
bpf_prog_ptr,
367363
)

0 commit comments

Comments
 (0)