Skip to content

Commit 0756497

Browse files
committed
feat(seccomp): update seccompiler to use libseccomp
libseccomp provides better quality compiler for bpf seccomp programs than our current implementation. Signed-off-by: Egor Lazarchuk <[email protected]>
1 parent 4352366 commit 0756497

File tree

14 files changed

+356
-3825
lines changed

14 files changed

+356
-3825
lines changed

Cargo.lock

Lines changed: 26 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/firecracker/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,12 @@ serde = { version = "1.0.215", features = ["derive"] }
4242
userfaultfd = "0.8.1"
4343

4444
[build-dependencies]
45-
bincode = "1.2.1"
4645
seccompiler = { path = "../seccompiler" }
4746
serde = { version = "1.0.215" }
4847
serde_json = "1.0.133"
4948

5049
[features]
51-
tracing = ["log-instrument", "seccompiler/tracing", "utils/tracing", "vmm/tracing"]
50+
tracing = ["log-instrument", "utils/tracing", "vmm/tracing"]
5251
gdb = ["vmm/gdb"]
5352

5453
[lints]

src/firecracker/build.rs

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
// Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
33

4-
use std::collections::BTreeMap;
5-
use std::fs::File;
64
use std::path::Path;
75

8-
use seccompiler::common::BpfProgram;
9-
use seccompiler::compiler::{Compiler, JsonFile};
10-
116
const ADVANCED_BINARY_FILTER_FILE_NAME: &str = "seccomp_filter.bpf";
127

138
const JSON_DIR: &str = "../../resources/seccomp";
@@ -44,19 +39,7 @@ fn main() {
4439
// Also retrigger the build script on any seccompiler source code change.
4540
println!("cargo:rerun-if-changed={}", SECCOMPILER_SRC_DIR);
4641

47-
let input = std::fs::read_to_string(seccomp_json_path).expect("Correct input file");
48-
let filters: JsonFile = serde_json::from_str(&input).expect("Input read");
49-
50-
let arch = target_arch.as_str().try_into().expect("Target");
51-
let compiler = Compiler::new(arch);
52-
53-
// transform the IR into a Map of BPFPrograms
54-
let bpf_data: BTreeMap<String, BpfProgram> = compiler
55-
.compile_blob(filters.0, false)
56-
.expect("Successfull compilation");
57-
58-
// serialize the BPF programs & output them to a file
5942
let out_path = format!("{}/{}", out_dir, ADVANCED_BINARY_FILTER_FILE_NAME);
60-
let output_file = File::create(out_path).expect("Create seccompiler output path");
61-
bincode::serialize_into(output_file, &bpf_data).expect("Seccompiler serialization");
43+
seccompiler::compile_bpf(&seccomp_json_path, &target_arch, &out_path, false)
44+
.expect("Cannot compile seccomp filters");
6245
}

src/seccompiler/Cargo.toml

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,18 @@ bench = false
1212

1313
[[bin]]
1414
name = "seccompiler-bin"
15-
path = "src/seccompiler_bin.rs"
15+
path = "src/bin.rs"
1616
bench = false
1717

1818
[dependencies]
19+
clap = { version = "4.5.21", features = ["derive", "string"] }
1920
bincode = "1.2.1"
20-
displaydoc = "0.2.5"
2121
libc = "0.2.164"
22-
log-instrument = { path = "../log-instrument", optional = true }
22+
libseccomp = "0.3.0"
2323
serde = { version = "1.0.215", features = ["derive"] }
2424
serde_json = "1.0.133"
25+
displaydoc = "0.2.5"
2526
thiserror = "2.0.3"
2627

27-
utils = { path = "../utils" }
28-
29-
[dev-dependencies]
30-
vmm-sys-util = "0.12.1"
31-
32-
[features]
33-
tracing = ["log-instrument", "utils/tracing"]
34-
3528
[lints]
3629
workspace = true

0 commit comments

Comments
 (0)