Skip to content

Commit 42f6f6c

Browse files
committed
Change fuzzing target to fuzz turn type and parameters
Signed-off-by: Ludvig Liljenberg <[email protected]>
1 parent 63fa7c6 commit 42f6f6c

File tree

11 files changed

+39
-31
lines changed

11 files changed

+39
-31
lines changed

.github/workflows/dep_fuzzing.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ jobs:
4444
run: cargo install cargo-fuzz
4545

4646
- name: Run Fuzzing
47-
run: cargo +nightly fuzz run --release fuzz_target_1 -- -max_total_time=300
47+
run: just fuzz-timed ${{ inputs.max_total_time }}
4848
working-directory: src/hyperlight_host
4949

5050
- 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: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Justfile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,8 @@ bench target=default-target features="":
187187

188188
# FUZZING
189189
fuzz:
190-
cd src/hyperlight_host && cargo +nightly fuzz run fuzz_target_1
190+
cd src/hyperlight_host && cargo +nightly fuzz run fuzz_target_1 --release
191191

192-
fuzz-timed:
193-
cd src/hyperlight_host && cargo +nightly fuzz run fuzz_target_1 -- -max_total_time=300
192+
# Stop fuzzing after `max_time` seconds
193+
fuzz-timed max_time:
194+
cd src/hyperlight_host && cargo +nightly fuzz run fuzz_target_1 --release -- -max_total_time={{ max_time }}

src/hyperlight_common/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@ anyhow = { version = "1.0.96", default-features = false }
2020
log = "0.4.25"
2121
tracing = { version = "0.1.41", optional = true }
2222
strum = {version = "0.27", default-features = false, features = ["derive"]}
23+
arbitrary = {version = "1.4.1", optional = true, features = ["derive"]}
2324

2425
[features]
2526
default = ["tracing"]
27+
fuzzing = ["dep:arbitrary"]
2628

2729
[dev-dependencies]
2830
hyperlight-testing = { workspace = true }

src/hyperlight_common/src/flatbuffer_wrappers/function_types.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ use crate::flatbuffers::hyperlight::generated::{
3232
};
3333

3434
/// Supported parameter types with values for function calling.
35+
#[cfg_attr(feature = "fuzzing", derive(arbitrary::Arbitrary))]
3536
#[derive(Debug, Clone, PartialEq)]
3637
pub enum ParameterValue {
3738
/// i32
@@ -104,6 +105,7 @@ pub enum ReturnValue {
104105
}
105106

106107
/// Supported return types from function calling.
108+
#[cfg_attr(feature = "fuzzing", derive(arbitrary::Arbitrary))]
107109
#[derive(Debug, Copy, Clone, PartialEq, Eq, Default)]
108110
#[repr(C)]
109111
pub enum ReturnType {

src/hyperlight_common/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
#![no_std]
17+
// We use Arbitrary during fuzzing, which requires std
18+
#![cfg_attr(not(feature = "fuzzing"), no_std)]
1819

1920
extern crate alloc;
2021

src/hyperlight_host/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ mshv3 = ["dep:mshv-bindings3", "dep:mshv-ioctls3"]
132132
inprocess = []
133133
# This enables easy debug in the guest
134134
gdb = ["dep:gdbstub", "dep:gdbstub_arch"]
135+
fuzzing = ["hyperlight-common/fuzzing"]
135136

136137
[[bench]]
137138
name = "benchmarks"

src/hyperlight_host/fuzz/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ cargo-fuzz = true
1010
[dependencies]
1111
libfuzzer-sys = "0.4"
1212
hyperlight-testing = { workspace = true }
13-
hyperlight-host = { workspace = true, default-features = true }
13+
hyperlight-host = { workspace = true, default-features = true, features = ["fuzzing"]}
1414

1515
[[bin]]
1616
name = "fuzz_target_1"

src/hyperlight_host/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 `cd src/hyperlight_host && cargo +nightly fuzz run fuzz_target_1 --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 only fuzz the parameters and return type to a hardcoded `PrintOutput` guest 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)