Skip to content

Commit 6e40e5f

Browse files
authored
Merge pull request #2702 from G8XSU/libFuzzer
Update fuzzing instructions for libFuzzer/cargo-fuzz
2 parents 1e25979 + dabe4af commit 6e40e5f

File tree

1 file changed

+45
-15
lines changed

1 file changed

+45
-15
lines changed

fuzz/README.md

+45-15
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
# Fuzzing
22

3-
Fuzz tests generate a ton of random parameter arguments to the program and then validate that none cause it to crash.
3+
Fuzz tests generate a ton of random parameter arguments to the program and then validate that none
4+
cause it to crash.
45

56
## How does it work?
67

7-
Typically, Travis CI will run `travis-fuzz.sh` on one of the environments the automated tests are configured for.
8-
This is the most time-consuming component of the continuous integration workflow, so it is recommended that you detect
9-
issues locally, and Travis merely acts as a sanity check. Fuzzing is further only effective with
10-
a lot of CPU time, indicating that if crash scenarios are discovered on Travis with its low
11-
runtime constraints, the crash is caused relatively easily.
8+
Typically, CI will run `ci-fuzz.sh` on one of the environments the automated tests are
9+
configured for. Fuzzing is further only effective with a lot of CPU time, indicating that if crash
10+
scenarios are discovered on CI with its low runtime constraints, the crash is caused relatively
11+
easily.
1212

1313
## How do I run fuzz tests locally?
1414

15-
You typically won't need to run the entire combination of different fuzzing tools. For local execution, `honggfuzz`
16-
should be more than sufficient.
15+
We support multiple fuzzing engines such as `honggfuzz`, `libFuzzer` and `AFL`. You typically won't
16+
need to run the entire suite of different fuzzing tools. For local execution, `honggfuzz`should be
17+
more than sufficient.
1718

1819
### Setup
19-
20+
#### Honggfuzz
2021
To install `honggfuzz`, simply run
2122

2223
```shell
@@ -31,9 +32,18 @@ cargo update -p honggfuzz --precise "0.5.52"
3132
cargo install --force honggfuzz --version "0.5.52"
3233
```
3334

35+
#### cargo-fuzz / libFuzzer
36+
To install `cargo-fuzz`, simply run
37+
38+
```shell
39+
cargo update
40+
cargo install --force cargo-fuzz
41+
```
42+
3443
### Execution
3544

36-
To run the Hongg fuzzer, do
45+
#### Honggfuzz
46+
To run fuzzing using `honggfuzz`, do
3747

3848
```shell
3949
export CPU_COUNT=1 # replace as needed
@@ -46,33 +56,53 @@ cargo hfuzz run $TARGET
4656

4757
(Or, for a prettier output, replace the last line with `cargo --color always hfuzz run $TARGET`.)
4858

59+
#### cargo-fuzz / libFuzzer
60+
To run fuzzing using `cargo-fuzz / libFuzzer`, run
61+
62+
```shell
63+
rustup install nightly # Note: libFuzzer requires a nightly version of rust.
64+
cargo +nightly fuzz run --features "libfuzzer_fuzz" msg_ping_target
65+
```
66+
Note: If you encounter a `SIGKILL` during run/build check for OOM in kernel logs and consider
67+
increasing RAM size for VM.
68+
69+
If you wish to just generate fuzzing binary executables for `libFuzzer` and not run them:
70+
```shell
71+
cargo +nightly fuzz build --features "libfuzzer_fuzz" msg_ping_target
72+
# Generates binary artifact in path ./target/aarch64-unknown-linux-gnu/release/msg_ping_target
73+
# Exact path depends on your system architecture.
74+
```
75+
You can upload the build artifact generated above to `ClusterFuzz` for distributed fuzzing.
76+
77+
### List Fuzzing Targets
4978
To see a list of available fuzzing targets, run:
5079

5180
```shell
5281
ls ./src/bin/
5382
```
5483

55-
## A fuzz test failed on Travis, what do I do?
84+
## A fuzz test failed, what do I do?
5685

57-
You're trying to create a PR, but need to find the underlying cause of that pesky fuzz failure blocking the merge?
86+
You're trying to create a PR, but need to find the underlying cause of that pesky fuzz failure
87+
blocking the merge?
5888

5989
Worry not, for this is easily traced.
6090

61-
If your Travis output log looks like this:
91+
If your output log looks like this:
6292

6393
```
6494
Size:639 (i,b,hw,ed,ip,cmp): 0/0/0/0/0/1, Tot:0/0/0/2036/5/28604
6595
Seen a crash. Terminating all fuzzing threads
6696
6797
… # a lot of lines in between
6898
69-
<0x0000555555565559> [func:UNKNOWN file: line:0 module:/home/travis/build/rust-bitcoin/rust-lightning/fuzz/hfuzz_target/x86_64-unknown-linux-gnu/release/full_stack_target]
99+
<0x0000555555565559> [func:UNKNOWN file: line:0 module:./rust-lightning/fuzz/hfuzz_target/x86_64-unknown-linux-gnu/release/full_stack_target]
70100
<0x0000000000000000> [func:UNKNOWN file: line:0 module:UNKNOWN]
71101
=====================================================================
72102
2d3136383734090101010101010101010101010101010101010101010101
73103
010101010100040101010101010101010101010103010101010100010101
74104
0069d07c319a4961
75-
The command "if [ "$(rustup show | grep default | grep stable)" != "" ]; then cd fuzz && cargo test --verbose && ./travis-fuzz.sh; fi" exited with 1.
105+
The command "if [ "$(rustup show | grep default | grep stable)" != "" ]; then cd fuzz && cargo test --verbose && ./ci-fuzz.sh; fi" exited with 1.
76106
```
77107

78108
Note that the penultimate stack trace line ends in `release/full_stack_target]`. That indicates that

0 commit comments

Comments
 (0)