Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(fuzzing): Add syscall monitoring to canister sandbox #3420

Merged
merged 20 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 95 additions & 1 deletion Cargo.Bazel.Fuzzing.json.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"checksum": "ee07bd5cde20eb057c9baa703b47a96ece7ed32714378e3b62f6cb2a1bde2d94",
"checksum": "a53d96737556099dd585f83042e6bc5d0eb99828d34f4bf0033b0b3583b2789b",
"crates": {
"abnf 0.12.0": {
"name": "abnf",
Expand Down Expand Up @@ -19398,6 +19398,10 @@
"id": "syn 1.0.109",
"target": "syn"
},
{
"id": "syscalls 0.6.18",
"target": "syscalls"
},
{
"id": "tar 0.4.39",
"target": "tar"
Expand Down Expand Up @@ -69707,6 +69711,95 @@
],
"license_file": "LICENSE"
},
"syscalls 0.6.18": {
"name": "syscalls",
"version": "0.6.18",
"package_url": "https://github.com/jasonwhite/syscalls",
"repository": {
"Http": {
"url": "https://static.crates.io/crates/syscalls/0.6.18/download",
"sha256": "43d0e35dc7d73976a53c7e6d7d177ef804a0c0ee774ec77bcc520c2216fd7cbe"
}
},
"targets": [
{
"Library": {
"crate_name": "syscalls",
"crate_root": "src/lib.rs",
"srcs": {
"allow_empty": true,
"include": [
"**/*.rs"
]
}
}
},
{
"BuildScript": {
"crate_name": "build_script_build",
"crate_root": "build.rs",
"srcs": {
"allow_empty": true,
"include": [
"**/*.rs"
]
}
}
}
],
"library_target_name": "syscalls",
"common_attrs": {
"compile_data_glob": [
"**"
],
"crate_features": {
"common": [
"default",
"serde",
"serde_repr",
"std"
],
"selects": {}
},
"deps": {
"common": [
{
"id": "serde 1.0.217",
"target": "serde"
},
{
"id": "syscalls 0.6.18",
"target": "build_script_build"
}
],
"selects": {}
},
"edition": "2021",
"proc_macro_deps": {
"common": [
{
"id": "serde_repr 0.1.19",
"target": "serde_repr"
}
],
"selects": {}
},
"version": "0.6.18"
},
"build_script_attrs": {
"compile_data_glob": [
"**"
],
"data_glob": [
"**"
]
},
"license": "BSD-2-Clause",
"license_ids": [
"BSD-2-Clause"
],
"license_file": "LICENSE"
},
"system-configuration 0.5.1": {
"name": "system-configuration",
"version": "0.5.1",
Expand Down Expand Up @@ -87579,6 +87672,7 @@
"stubborn-io 0.3.2",
"subtle 2.6.1",
"syn 1.0.109",
"syscalls 0.6.18",
"tar 0.4.39",
"tarpc 0.34.0",
"tempfile 3.12.0",
Expand Down
11 changes: 11 additions & 0 deletions Cargo.Bazel.Fuzzing.toml.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3244,6 +3244,7 @@ dependencies = [
"stubborn-io",
"subtle",
"syn 1.0.109",
"syscalls",
"tar",
"tarpc",
"tempfile",
Expand Down Expand Up @@ -10892,6 +10893,16 @@ dependencies = [
"syn 2.0.87",
]

[[package]]
name = "syscalls"
version = "0.6.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "43d0e35dc7d73976a53c7e6d7d177ef804a0c0ee774ec77bcc520c2216fd7cbe"
dependencies = [
"serde",
"serde_repr",
]

[[package]]
name = "system-configuration"
version = "0.5.1"
Expand Down
96 changes: 95 additions & 1 deletion Cargo.Bazel.json.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"checksum": "af5e4debd1243293865e30a9b64a67f317d54d2087da3adf9fd816ffdd8b1262",
"checksum": "b9642475d0faabe29f70c002aaede852562dae05dad3bda705eee7103ddce811",
"crates": {
"abnf 0.12.0": {
"name": "abnf",
Expand Down Expand Up @@ -19226,6 +19226,10 @@
"id": "syn 1.0.109",
"target": "syn"
},
{
"id": "syscalls 0.6.18",
"target": "syscalls"
},
{
"id": "tar 0.4.39",
"target": "tar"
Expand Down Expand Up @@ -69553,6 +69557,95 @@
],
"license_file": "LICENSE"
},
"syscalls 0.6.18": {
"name": "syscalls",
"version": "0.6.18",
"package_url": "https://github.com/jasonwhite/syscalls",
"repository": {
"Http": {
"url": "https://static.crates.io/crates/syscalls/0.6.18/download",
"sha256": "43d0e35dc7d73976a53c7e6d7d177ef804a0c0ee774ec77bcc520c2216fd7cbe"
}
},
"targets": [
{
"Library": {
"crate_name": "syscalls",
"crate_root": "src/lib.rs",
"srcs": {
"allow_empty": true,
"include": [
"**/*.rs"
]
}
}
},
{
"BuildScript": {
"crate_name": "build_script_build",
"crate_root": "build.rs",
"srcs": {
"allow_empty": true,
"include": [
"**/*.rs"
]
}
}
}
],
"library_target_name": "syscalls",
"common_attrs": {
"compile_data_glob": [
"**"
],
"crate_features": {
"common": [
"default",
"serde",
"serde_repr",
"std"
],
"selects": {}
},
"deps": {
"common": [
{
"id": "serde 1.0.217",
"target": "serde"
},
{
"id": "syscalls 0.6.18",
"target": "build_script_build"
}
],
"selects": {}
},
"edition": "2021",
"proc_macro_deps": {
"common": [
{
"id": "serde_repr 0.1.19",
"target": "serde_repr"
}
],
"selects": {}
},
"version": "0.6.18"
},
"build_script_attrs": {
"compile_data_glob": [
"**"
],
"data_glob": [
"**"
]
},
"license": "BSD-2-Clause",
"license_ids": [
"BSD-2-Clause"
],
"license_file": "LICENSE"
},
"system-configuration 0.5.1": {
"name": "system-configuration",
"version": "0.5.1",
Expand Down Expand Up @@ -87458,6 +87551,7 @@
"stubborn-io 0.3.2",
"subtle 2.6.1",
"syn 1.0.109",
"syscalls 0.6.18",
"tar 0.4.39",
"tarpc 0.34.0",
"tempfile 3.12.0",
Expand Down
11 changes: 11 additions & 0 deletions Cargo.Bazel.toml.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3233,6 +3233,7 @@ dependencies = [
"stubborn-io",
"subtle",
"syn 1.0.109",
"syscalls",
"tar",
"tarpc",
"tempfile",
Expand Down Expand Up @@ -10888,6 +10889,16 @@ dependencies = [
"syn 2.0.87",
]

[[package]]
name = "syscalls"
version = "0.6.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "43d0e35dc7d73976a53c7e6d7d177ef804a0c0ee774ec77bcc520c2216fd7cbe"
dependencies = [
"serde",
"serde_repr",
]

[[package]]
name = "system-configuration"
version = "0.5.1"
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ minicbor-derive = "0.13.0"
mockall = "0.13.0"
mockito = "1.2.0"
nftables = "0.4"
nix = "0.24.3"
nix = { version = "0.24.3", features = ["ptrace"] }
num_cpus = "1.16.0"
num-bigint = "0.4.6"
num-traits = { version = "0.2.12", features = ["libm"] }
Expand Down
6 changes: 6 additions & 0 deletions bazel/external_crates.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,9 @@ def external_crates_repository(name, cargo_lockfile, lockfile, sanitizers_enable
),
"nix": crate.spec(
version = "^0.24.3",
features = [
"ptrace",
],
),
"num-bigint": crate.spec(
version = "^0.4.6",
Expand Down Expand Up @@ -1240,6 +1243,9 @@ def external_crates_repository(name, cargo_lockfile, lockfile, sanitizers_enable
"full",
],
),
"syscalls": crate.spec(
version = "^0.6.18",
),
"tar": crate.spec(
version = "^0.4.38",
),
Expand Down
5 changes: 2 additions & 3 deletions rs/embedders/fuzz/src/ic_wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,8 @@ pub fn ic_wasm_config(embedder_config: EmbeddersConfig) -> Config {
max_funcs: embedder_config.max_functions,
max_instructions: WASM_FUNCTION_SIZE_LIMIT,

// TODO: Ignore data segments for now
min_data_segments: 0,
max_data_segments: 0,
min_data_segments: 2,
max_data_segments: 10,

allow_start_export: true,
export_everything: true,
Expand Down
9 changes: 8 additions & 1 deletion rs/execution_environment/fuzz/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,14 @@ rust_library(
deps = [
"//rs/canister_sandbox:backend_lib",
"@crate_index//:libfuzzer-sys",
],
"@crate_index//:nix",
] + select({
"@rules_rust//rust/platform:linux": [
"@crate_index//:procfs",
"@crate_index//:syscalls",
],
"//conditions:default": [],
}),
)

rust_fuzz_test_binary(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ use libfuzzer_sys::{fuzz_target, Corpus};
// bazel run --config=sandbox_fuzzing //rs/execution_environment/fuzz:execute_subnet_message_update_settings

fn main() {
fuzzer_sandbox::fuzzer_main();
let features = fuzzer_sandbox::SandboxFeatures {
syscall_tracing: false,
};
fuzzer_sandbox::fuzzer_main(features);
}

fuzz_target!(|args: UpdateSettingsArgs| -> Corpus {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ const HELLO_WORLD_WAT: &str = r#"
// bazel run --config=sandbox_fuzzing //rs/execution_environment/fuzz:execute_with_wasm_executor_system_api_call

fn main() {
fuzzer_sandbox::fuzzer_main();
let features = fuzzer_sandbox::SandboxFeatures {
syscall_tracing: true,
};
fuzzer_sandbox::fuzzer_main(features);
}

fuzz_target!(|data: ICWasmModule| {
Expand Down
Loading
Loading