Skip to content

Commit 4e8db7d

Browse files
committed
Adds fuzzing target to fuzz the ParameterValue and ReturnType. Rename
existing target to host_print. Move fuzz directory to root directory. Signed-off-by: Ludvig Liljenberg <[email protected]>
1 parent 63fa7c6 commit 4e8db7d

File tree

18 files changed

+161
-69
lines changed

18 files changed

+161
-69
lines changed

.github/workflows/Fuzzing.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,13 @@ jobs:
1414
fuzzing:
1515
uses: ./.github/workflows/dep_fuzzing.yml
1616
with:
17+
target: "host_print"
18+
max_total_time: 18000 # 5 hours in seconds
19+
secrets: inherit
20+
21+
fuzzing:
22+
uses: ./.github/workflows/dep_fuzzing.yml
23+
with:
24+
target: "guest_call"
1725
max_total_time: 18000 # 5 hours in seconds
1826
secrets: inherit

.github/workflows/dep_fuzzing.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ on:
77
description: Maximum total time for the fuzz run in seconds
88
required: true
99
type: number
10+
target:
11+
description: Fuzz target to run
12+
required: true
13+
type: string
1014
docs_only:
1115
description: Skip fuzzing if docs only
1216
required: false
@@ -44,7 +48,7 @@ jobs:
4448
run: cargo install cargo-fuzz
4549

4650
- name: Run Fuzzing
47-
run: cargo +nightly fuzz run --release fuzz_target_1 -- -max_total_time=300
51+
run: just fuzz-timed ${{inputs.target}} ${{ inputs.max_total_time }}
4852
working-directory: src/hyperlight_host
4953

5054
- name: Upload Crash Artifacts

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"Cargo.toml",
44
// guest crates for testing, not part of the workspace
55
"src/tests/rust_guests/simpleguest/Cargo.toml",
6-
"src/tests/rust_guests/callbackguest/Cargo.toml"
6+
"src/tests/rust_guests/callbackguest/Cargo.toml",
7+
"src/hyperlight_host/fuzz/Cargo.toml"
78
]
89
}

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ members = [
1111
"src/hyperlight_host",
1212
"src/hyperlight_guest_capi",
1313
"src/hyperlight_testing",
14-
"src/hyperlight_host/fuzz",
14+
"fuzz",
1515
]
1616
# Because hyperlight-guest has custom linker flags,
1717
# we exclude it from the default-members list

Justfile

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,11 @@ bench target=default-target features="":
186186
cargo bench --profile={{ if target == "debug" { "dev" } else { target } }} {{ if features =="" {''} else { "--features " + features } }} -- --verbose
187187

188188
# FUZZING
189-
fuzz:
190-
cd src/hyperlight_host && cargo +nightly fuzz run fuzz_target_1
191189

192-
fuzz-timed:
193-
cd src/hyperlight_host && cargo +nightly fuzz run fuzz_target_1 -- -max_total_time=300
190+
# Fuzzes the given target
191+
fuzz fuzz-target:
192+
cargo +nightly fuzz run {{ fuzz-target }} --release
193+
194+
# Fuzzes the given target. Stops after `max_time` seconds
195+
fuzz-timed fuzz-target max_time:
196+
cargo +nightly fuzz run {{ fuzz-target }} --release -- -max_total_time={{ max_time }}
File renamed without changes.

fuzz/Cargo.toml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
[package]
2+
name = "hyperlight-fuzz"
3+
version = "0.0.0"
4+
publish = false
5+
edition = { workspace = true }
6+
7+
[package.metadata]
8+
cargo-fuzz = true
9+
10+
[dependencies]
11+
libfuzzer-sys = "0.4"
12+
hyperlight-testing = { workspace = true }
13+
hyperlight-host = { workspace = true, default-features = true, features = ["fuzzing"]}
14+
15+
[[bin]]
16+
name = "host_print"
17+
path = "fuzz_targets/host_print.rs"
18+
test = false
19+
doc = false
20+
bench = false
21+
22+
[[bin]]
23+
name = "guest_call"
24+
path = "fuzz_targets/guest_call.rs"
25+
test = false
26+
doc = false
27+
bench = false

src/hyperlight_host/fuzz/README.md renamed to fuzz/README.md

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,19 @@ This directory contains the fuzzing infrastructure for Hyperlight. We use `cargo
44

55
You can run the fuzzers with:
66
```sh
7-
cargo +nightly-2023-11-28-x86_64-unknown-linux-gnu fuzz run --release <fuzzer_name>
7+
just fuzz
88
```
9-
10-
> Note: Because nightly toolchains are not stable, we pin the nightly version to `2023-11-28`. To install this toolchain, run:
11-
> ```sh
12-
> rustup toolchain install nightly-2023-11-28-x86_64-unknown-linux-gnu
13-
> ```
9+
which evaluates to the following command `cargo +nightly fuzz run host_print --release`. We use the release profile to make sure the release-optimized guest is used. The default fuzz profile which is release+debugsymbols would cause our debug guests to be loaded, since we currently determine which test guest to load based on whether debug symbols are present.
1410

1511
As per Microsoft's Offensive Research & Security Engineering (MORSE) team, all host exposed functions that receive or interact with guest data must be continuously fuzzed for, at least, 500 million fuzz test cases without any crashes. Because `cargo-fuzz` doesn't support setting a maximum number of iterations; instead, we use the `--max_total_time` flag to set a maximum time to run the fuzzer. We have a GitHub action (acting like a CRON job) that runs the fuzzers for 24 hours every week.
1612

17-
Currently, we only fuzz the `PrintOutput` function. We plan to add more fuzzers in the future.
13+
Currently, we fuzz the parameters and return type to a hardcoded `PrintOutput` guest function, and the `HostPrint` host function. We plan to add more fuzzers in the future.
1814

1915
## On Failure
2016

2117
If you encounter a failure, you can re-run an entire seed (i.e., group of inputs) with:
2218
```sh
23-
cargo +nightly-2023-11-28-x86_64-unknown-linux-gnu fuzz run --release <fuzzer_name> -- -seed=<seed-number>
19+
cargo +nightly fuzz run <fuzzer_name> -- -seed=<seed-number>
2420
```
2521

2622
The seed number can be seed in a specific run, like:
@@ -29,5 +25,5 @@ The seed number can be seed in a specific run, like:
2925
Or, if repro-ing a failure from CI, you can download the artifact from the fuzzing run, and run it like:
3026

3127
```sh
32-
cargo +nightly-2023-11-28-x86_64-unknown-linux-gnu fuzz run --release -O <fuzzer_name> <fuzzer-input (e.g., fuzz/artifacts/fuzz_target_1/crash-93c522e64ee822034972ccf7026d3a8f20d5267c>
28+
cargo +nightly fuzz run -O <fuzzer_name> <fuzzer-input (e.g., fuzz/artifacts/fuzz_target_1/crash-93c522e64ee822034972ccf7026d3a8f20d5267c>
3329
```

0 commit comments

Comments
 (0)