1
1
# Fuzzing
2
2
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.
4
5
5
6
## How does it work?
6
7
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.
12
12
13
13
## How do I run fuzz tests locally?
14
14
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.
17
18
18
19
### Setup
19
-
20
+ #### Honggfuzz
20
21
To install ` honggfuzz ` , simply run
21
22
22
23
``` shell
@@ -31,9 +32,18 @@ cargo update -p honggfuzz --precise "0.5.52"
31
32
cargo install --force honggfuzz --version " 0.5.52"
32
33
```
33
34
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
+
34
43
### Execution
35
44
36
- To run the Hongg fuzzer, do
45
+ #### Honggfuzz
46
+ To run fuzzing using ` honggfuzz ` , do
37
47
38
48
``` shell
39
49
export CPU_COUNT=1 # replace as needed
@@ -46,33 +56,53 @@ cargo hfuzz run $TARGET
46
56
47
57
(Or, for a prettier output, replace the last line with ` cargo --color always hfuzz run $TARGET ` .)
48
58
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
49
78
To see a list of available fuzzing targets, run:
50
79
51
80
``` shell
52
81
ls ./src/bin/
53
82
```
54
83
55
- ## A fuzz test failed on Travis , what do I do?
84
+ ## A fuzz test failed, what do I do?
56
85
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?
58
88
59
89
Worry not, for this is easily traced.
60
90
61
- If your Travis output log looks like this:
91
+ If your output log looks like this:
62
92
63
93
```
64
94
Size:639 (i,b,hw,ed,ip,cmp): 0/0/0/0/0/1, Tot:0/0/0/2036/5/28604
65
95
Seen a crash. Terminating all fuzzing threads
66
96
67
97
… # a lot of lines in between
68
98
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]
70
100
<0x0000000000000000> [func:UNKNOWN file: line:0 module:UNKNOWN]
71
101
=====================================================================
72
102
2d3136383734090101010101010101010101010101010101010101010101
73
103
010101010100040101010101010101010101010103010101010100010101
74
104
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.
76
106
```
77
107
78
108
Note that the penultimate stack trace line ends in ` release/full_stack_target] ` . That indicates that
0 commit comments