-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <lliljenberg@microsoft.com>
- Loading branch information
Showing
19 changed files
with
158 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
[package] | ||
name = "hyperlight-fuzz" | ||
version = "0.0.0" | ||
publish = false | ||
edition = { workspace = true } | ||
|
||
[package.metadata] | ||
cargo-fuzz = true | ||
|
||
[dependencies] | ||
libfuzzer-sys = "0.4" | ||
hyperlight-testing = { workspace = true } | ||
hyperlight-host = { workspace = true, default-features = true, features = ["fuzzing"]} | ||
|
||
[[bin]] | ||
name = "host_print" | ||
path = "fuzz_targets/host_print.rs" | ||
test = false | ||
doc = false | ||
bench = false | ||
|
||
[[bin]] | ||
name = "guest_call" | ||
path = "fuzz_targets/guest_call.rs" | ||
test = false | ||
doc = false | ||
bench = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#![no_main] | ||
|
||
use std::sync::{Mutex, OnceLock}; | ||
|
||
use hyperlight_host::func::{ParameterValue, ReturnType, ReturnValue}; | ||
use hyperlight_host::sandbox::uninitialized::GuestBinary; | ||
use hyperlight_host::sandbox_state::sandbox::EvolvableSandbox; | ||
use hyperlight_host::sandbox_state::transition::Noop; | ||
use hyperlight_host::{MultiUseSandbox, UninitializedSandbox}; | ||
use hyperlight_testing::simple_guest_as_string; | ||
use libfuzzer_sys::{fuzz_target, Corpus}; | ||
|
||
static SANDBOX: OnceLock<Mutex<MultiUseSandbox>> = OnceLock::new(); | ||
|
||
// This fuzz target is used to test the HostPrint host function. We generate | ||
// an arbitrary ParameterValue::String, which is passed to the guest, which passes | ||
// it without modification to the host function. | ||
// For fuzzing efficiency, we create one Sandbox and reuse it for all fuzzing iterations. | ||
fuzz_target!( | ||
init: { | ||
let u_sbox = UninitializedSandbox::new( | ||
GuestBinary::FilePath(simple_guest_as_string().expect("Guest Binary Missing")), | ||
None, | ||
None, | ||
None, | ||
) | ||
.unwrap(); | ||
|
||
let mu_sbox: MultiUseSandbox = u_sbox.evolve(Noop::default()).unwrap(); | ||
SANDBOX.set(Mutex::new(mu_sbox)).unwrap(); | ||
}, | ||
|
||
|data: ParameterValue| -> Corpus { | ||
// only interested in String types | ||
if !matches!(data, ParameterValue::String(_)) { | ||
return Corpus::Reject; | ||
} | ||
|
||
let mut sandbox = SANDBOX.get().unwrap().lock().unwrap(); | ||
let res = sandbox.call_guest_function_by_name( | ||
"PrintOutput", | ||
ReturnType::Int, | ||
Some(vec![data.clone()]), | ||
); | ||
match res { | ||
Ok(ReturnValue::Int(len)) => assert!(len >= 0), | ||
_ => panic!("Unexpected return value: {:?}", res), | ||
} | ||
|
||
Corpus::Keep | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,2 @@ | ||
[toolchain] | ||
channel = "1.81.0" | ||
# if you update this, don't forget to change the pinned version | ||
# of nightly we use in the fuzzing workflow. | ||
channel = "1.81.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.