Skip to content

Commit 3eea65f

Browse files
committed
Use libc values for seccomp constants
Now that rust-lang/libc/pull/3343 is merged and released, switch to using libc's constants. 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. Fixes rust-vmm#60
1 parent 80c0723 commit 3eea65f

File tree

3 files changed

+12
-16
lines changed

3 files changed

+12
-16
lines changed

src/backend/bpf.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,14 @@ pub const BPF_K: u16 = 0x00;
114114

115115
// Return codes for BPF programs.
116116
// 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;
117+
pub use libc::SECCOMP_RET_ALLOW;
118+
pub use libc::SECCOMP_RET_ERRNO;
119+
pub use libc::SECCOMP_RET_KILL_THREAD;
120+
pub use libc::SECCOMP_RET_KILL_PROCESS;
121+
pub use libc::SECCOMP_RET_LOG;
122+
pub use libc::SECCOMP_RET_TRACE;
123+
pub use libc::SECCOMP_RET_TRAP;
124+
pub use libc::SECCOMP_RET_DATA;
125125

126126
// Architecture identifier for x86_64 LE.
127127
// See /usr/include/linux/audit.h .

src/backend/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use std::fmt::Display;
2222
use bpf::{
2323
ARG_NUMBER_MAX, AUDIT_ARCH_AARCH64, AUDIT_ARCH_X86_64, BPF_MAX_LEN, SECCOMP_RET_ALLOW,
2424
SECCOMP_RET_ERRNO, SECCOMP_RET_KILL_PROCESS, SECCOMP_RET_KILL_THREAD, SECCOMP_RET_LOG,
25-
SECCOMP_RET_MASK, SECCOMP_RET_TRACE, SECCOMP_RET_TRAP,
25+
SECCOMP_RET_DATA, SECCOMP_RET_TRACE, SECCOMP_RET_TRAP,
2626
};
2727

2828
pub use bpf::{sock_filter, BpfProgram, BpfProgramRef};
@@ -173,11 +173,11 @@ impl From<SeccompAction> for u32 {
173173
fn from(action: SeccompAction) -> Self {
174174
match action {
175175
SeccompAction::Allow => SECCOMP_RET_ALLOW,
176-
SeccompAction::Errno(x) => SECCOMP_RET_ERRNO | (x & SECCOMP_RET_MASK),
176+
SeccompAction::Errno(x) => SECCOMP_RET_ERRNO | (x & SECCOMP_RET_DATA),
177177
SeccompAction::KillThread => SECCOMP_RET_KILL_THREAD,
178178
SeccompAction::KillProcess => SECCOMP_RET_KILL_PROCESS,
179179
SeccompAction::Log => SECCOMP_RET_LOG,
180-
SeccompAction::Trace(x) => SECCOMP_RET_TRACE | (x & SECCOMP_RET_MASK),
180+
SeccompAction::Trace(x) => SECCOMP_RET_TRACE | (x & SECCOMP_RET_DATA),
181181
SeccompAction::Trap => SECCOMP_RET_TRAP,
182182
}
183183
}

src/lib.rs

Lines changed: 1 addition & 5 deletions
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)