Skip to content

Commit 8055e0a

Browse files
authored
Merge branch 'main' into guest-mem-in-vm
2 parents 1fc262b + 1f1c5c0 commit 8055e0a

File tree

18 files changed

+197
-204
lines changed

18 files changed

+197
-204
lines changed

Cargo.lock

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

src/clippy-tracing/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ name = "clippy-tracing"
1010
bench = false
1111

1212
[dependencies]
13-
clap = { version = "4.5.32", features = ["derive"] }
13+
clap = { version = "4.5.35", features = ["derive"] }
1414
itertools = "0.14.0"
1515
proc-macro2 = { version = "1.0.94", features = ["span-locations"] }
1616
quote = "1.0.40"

src/cpu-template-helper/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ name = "cpu-template-helper"
1010
bench = false
1111

1212
[dependencies]
13-
clap = { version = "4.5.32", features = ["derive", "string"] }
13+
clap = { version = "4.5.35", features = ["derive", "string"] }
1414
displaydoc = "0.2.5"
1515
libc = "0.2.171"
1616
log-instrument = { path = "../log-instrument", optional = true }

src/firecracker/examples/seccomp/jailer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ fn main() {
1313
let bpf_path = &args[2];
1414

1515
let filter_file = File::open(bpf_path).unwrap();
16-
let map = deserialize_binary(&filter_file, None).unwrap();
16+
let map = deserialize_binary(&filter_file).unwrap();
1717

1818
// Loads filters.
1919
apply_filter(map.get("main").unwrap()).unwrap();

src/firecracker/examples/seccomp/panic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ fn main() {
1111
let filter_thread = &args[2];
1212

1313
let filter_file = File::open(bpf_path).unwrap();
14-
let map = deserialize_binary(&filter_file, None).unwrap();
14+
let map = deserialize_binary(&filter_file).unwrap();
1515
apply_filter(map.get(filter_thread).unwrap()).unwrap();
1616
panic!("Expected panic.");
1717
}

src/firecracker/src/seccomp.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,6 @@ use vmm::seccomp::{BpfThreadMap, DeserializationError, deserialize_binary, get_e
99

1010
const THREAD_CATEGORIES: [&str; 3] = ["vmm", "api", "vcpu"];
1111

12-
// This byte limit is passed to `bincode` to guard against a potential memory
13-
// allocation DOS caused by binary filters that are too large.
14-
// This limit can be safely determined since the maximum length of a BPF
15-
// filter is 4096 instructions and Firecracker has a finite number of threads.
16-
const DESERIALIZATION_BYTES_LIMIT: Option<u64> = Some(100_000);
17-
1812
/// Error retrieving seccomp filters.
1913
#[derive(Debug, thiserror::Error, displaydoc::Display)]
2014
pub enum FilterError {
@@ -72,15 +66,13 @@ pub fn get_filters(config: SeccompConfig) -> Result<BpfThreadMap, FilterError> {
7266
fn get_default_filters() -> Result<BpfThreadMap, FilterError> {
7367
// Retrieve, at compile-time, the serialized binary filter generated with seccompiler.
7468
let bytes: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/seccomp_filter.bpf"));
75-
let map = deserialize_binary(bytes, DESERIALIZATION_BYTES_LIMIT)
76-
.map_err(FilterError::Deserialization)?;
69+
let map = deserialize_binary(bytes).map_err(FilterError::Deserialization)?;
7770
filter_thread_categories(map)
7871
}
7972

8073
/// Retrieve custom seccomp filters.
8174
fn get_custom_filters<R: Read + Debug>(reader: R) -> Result<BpfThreadMap, FilterError> {
82-
let map = deserialize_binary(BufReader::new(reader), DESERIALIZATION_BYTES_LIMIT)
83-
.map_err(FilterError::Deserialization)?;
75+
let map = deserialize_binary(BufReader::new(reader)).map_err(FilterError::Deserialization)?;
8476
filter_thread_categories(map)
8577
}
8678

src/log-instrument/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ log = "0.4.27"
3232
log-instrument-macros = { path = "../log-instrument-macros" }
3333

3434
[dev-dependencies]
35-
env_logger = "0.11.7"
35+
env_logger = "0.11.8"
3636

3737
[lints]
3838
workspace = true

src/seccompiler/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ path = "src/bin.rs"
1616
bench = false
1717

1818
[dependencies]
19-
bincode = "1.2.1"
20-
clap = { version = "4.5.32", features = ["derive", "string"] }
19+
bincode = { version = "2.0.1", features = ["serde"] }
20+
clap = { version = "4.5.35", features = ["derive", "string"] }
2121
displaydoc = "0.2.5"
2222
libc = "0.2.171"
2323
serde = { version = "1.0.219", features = ["derive"] }

src/seccompiler/src/lib.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ use std::os::fd::{AsRawFd, FromRawFd};
88
use std::os::unix::fs::MetadataExt;
99
use std::str::FromStr;
1010

11-
use bincode::Error as BincodeError;
11+
use bincode::config;
12+
use bincode::config::{Configuration, Fixint, Limit, LittleEndian};
13+
use bincode::error::EncodeError as BincodeError;
1214

1315
mod bindings;
1416
use bindings::*;
@@ -17,6 +19,18 @@ pub mod types;
1719
pub use types::*;
1820
use zerocopy::IntoBytes;
1921

22+
// This byte limit is passed to `bincode` to guard against a potential memory
23+
// allocation DOS caused by binary filters that are too large.
24+
// This limit can be safely determined since the maximum length of a BPF
25+
// filter is 4096 instructions and Firecracker has a finite number of threads.
26+
const DESERIALIZATION_BYTES_LIMIT: usize = 100_000;
27+
28+
pub const BINCODE_CONFIG: Configuration<LittleEndian, Fixint, Limit<DESERIALIZATION_BYTES_LIMIT>> =
29+
config::standard()
30+
.with_fixed_int_encoding()
31+
.with_limit::<DESERIALIZATION_BYTES_LIMIT>()
32+
.with_little_endian();
33+
2034
/// Binary filter compilation errors.
2135
#[derive(Debug, thiserror::Error, displaydoc::Display)]
2236
pub enum CompilationError {
@@ -174,8 +188,9 @@ pub fn compile_bpf(
174188
bpf_map.insert(name.clone(), bpf);
175189
}
176190

177-
let output_file = File::create(out_path).map_err(CompilationError::OutputCreate)?;
191+
let mut output_file = File::create(out_path).map_err(CompilationError::OutputCreate)?;
178192

179-
bincode::serialize_into(output_file, &bpf_map).map_err(CompilationError::BincodeSerialize)?;
193+
bincode::encode_into_std_write(&bpf_map, &mut output_file, BINCODE_CONFIG)
194+
.map_err(CompilationError::BincodeSerialize)?;
180195
Ok(())
181196
}

src/snapshot-editor/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ name = "snapshot-editor"
1010
bench = false
1111

1212
[dependencies]
13-
clap = { version = "4.5.32", features = ["derive", "string"] }
13+
clap = { version = "4.5.35", features = ["derive", "string"] }
1414
displaydoc = "0.2.5"
1515

1616
fc_utils = { package = "utils", path = "../utils" }

0 commit comments

Comments
 (0)