Skip to content

Commit abe42f1

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 f7927c6 commit abe42f1

File tree

18 files changed

+171
-70
lines changed

18 files changed

+171
-70
lines changed

.github/workflows/Fuzzing.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,16 @@ permissions:
1010
contents: read
1111

1212
jobs:
13+
fuzzing-1:
14+
uses: ./.github/workflows/dep_fuzzing.yml
15+
with:
16+
target: "host_print"
17+
max_total_time: 18000 # 5 hours in seconds
18+
secrets: inherit
1319

14-
fuzzing:
20+
fuzzing-2:
1521
uses: ./.github/workflows/dep_fuzzing.yml
1622
with:
23+
target: "guest_call"
1724
max_total_time: 18000 # 5 hours in seconds
1825
secrets: inherit

.github/workflows/ValidatePullRequest.yml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,22 @@ jobs:
4949
with:
5050
docs_only: ${{needs.docs-pr.outputs.docs-only}}
5151

52-
fuzzing:
52+
fuzzing-1:
5353
needs:
5454
- docs-pr
5555
uses: ./.github/workflows/dep_fuzzing.yml
5656
with:
57+
target: host_print
58+
max_total_time: 300 # 5 minutes in seconds
59+
docs_only: ${{needs.docs-pr.outputs.docs-only}}
60+
secrets: inherit
61+
62+
fuzzing-2:
63+
needs:
64+
- docs-pr
65+
uses: ./.github/workflows/dep_fuzzing.yml
66+
with:
67+
target: guest_call
5768
max_total_time: 300 # 5 minutes in seconds
5869
docs_only: ${{needs.docs-pr.outputs.docs-only}}
5970
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

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
@@ -190,8 +190,11 @@ bench target=default-target features="":
190190
cargo bench --profile={{ if target == "debug" { "dev" } else { target } }} {{ if features =="" {''} else { "--features " + features } }} -- --verbose
191191

192192
# FUZZING
193-
fuzz:
194-
cd src/hyperlight_host && cargo +nightly fuzz run fuzz_target_1
195193

196-
fuzz-timed:
197-
cd src/hyperlight_host && cargo +nightly fuzz run fuzz_target_1 -- -max_total_time=300
194+
# Fuzzes the given target
195+
fuzz fuzz-target:
196+
cargo +nightly fuzz run {{ fuzz-target }} --release
197+
198+
# Fuzzes the given target. Stops after `max_time` seconds
199+
fuzz-timed fuzz-target max_time:
200+
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
```
File renamed without changes.

0 commit comments

Comments
 (0)