blob: 7f7cd3407cd256607f27e9835e40b27b93a86eca [file] [log] [blame] [view]
aizatsky9c8c5b02016-03-30 22:09:091# libFuzzer Integration Reference
aizatsky88a677d2016-03-18 23:18:242
Max Moroz9b370752018-03-20 22:05:323## Additional Sanitizer Configuration
Oliver Changd6ead472017-10-02 19:50:344
5### MSan
6
Jonathan Metzman15e88e72018-11-16 19:40:137Memory Sanitizer (MSan) in Chromium only supports Ubuntu Precise/Trusty and not
8Rodete.
9Thus, our [reproduce tool] cannot reproduce bugs found using MSan.
10You can try to reproduce them manually by using [these instructions] on how to
11run MSan-instrumented code in docker.
Oliver Changd6ead472017-10-02 19:50:3412
13### UBSan
14
Abhishek Arya9e4a72c2017-11-29 16:23:3315By default, UBSan does not crash when undefined behavior is detected.
16To make it crash, the following option needs to be set in environment:
Oliver Changd6ead472017-10-02 19:50:3417```bash
18UBSAN_OPTIONS=halt_on_error=1 ./fuzzer <corpus_directory_or_single_testcase_path>
Oliver Changd6ead472017-10-02 19:50:3419```
Abhishek Arya9e4a72c2017-11-29 16:23:3320Other useful options are (also used by ClusterFuzz):
Oliver Changd6ead472017-10-02 19:50:3421```bash
22UBSAN_OPTIONS=symbolize=1:halt_on_error=1:print_stacktrace=1 ./fuzzer <corpus_directory_or_single_testcase_path>
23```
24
aizatsky62c7a842016-05-13 19:23:0125## Supported Platforms and Configurations
26
Oliver Changd6ead472017-10-02 19:50:3427### Builder configurations
aizatsky62c7a842016-05-13 19:23:0128
Jonathan Metzman5f37d982019-01-03 17:39:0229The exact GN arguments that are used on our builders can be generated by running
30(from Chromium's `src` directory):
Oliver Changd6ead472017-10-02 19:50:3431
32| Builder | Description |
33|---------|-------------|
Jonathan Metzman5f37d982019-01-03 17:39:0234|Linux ASan | `tools/mb/mb.py gen -m chromium.fuzz -b 'Libfuzzer Upload Linux ASan' out/libfuzzer` |
35|Linux ASan (x86) | `tools/mb/mb.py gen -m chromium.fuzz -b 'Libfuzzer Upload Linux32 ASan' out/libfuzzer` |
36|Linux ASan Debug | `tools/mb/mb.py gen -m chromium.fuzz -b 'Libfuzzer Upload Linux ASan Debug' out/libfuzzer` |
Jonathan Metzman9c73a7b2019-01-27 17:03:3837|Linux MSan[*](#MSan) | `tools/mb/mb.py gen -m chromium.fuzz -b 'Libfuzzer Upload Linux MSan' out/libfuzzer` |
38|Linux UBSan[*](#UBSan)| `tools/mb/mb.py gen -m chromium.fuzz -b 'Libfuzzer Upload Linux UBSan' out/libfuzzer` |
Jonathan Metzman5f37d982019-01-03 17:39:0239|Chrome OS ASan | `tools/mb/mb.py gen -m chromium.fuzz -b 'Libfuzzer Upload Chrome OS ASan' out/libfuzzer` |
40|Mac ASan | `tools/mb/mb.py gen -m chromium.fuzz -b 'Libfuzzer Upload Mac ASan' out/libfuzzer` |
41|Windows ASan | `python tools\mb\mb.py gen -m chromium.fuzz -b "Libfuzzer Upload Windows ASan" out\libfuzzer` |
Jonathan Metzman9c73a7b2019-01-27 17:03:3842|Linux ASan V8 ARM Simulator[*](#ARM-and-ARM64)| `tools/mb/mb.py gen -m chromium.fuzz -b 'Libfuzzer Upload Linux32 V8-ARM ASan' out/libfuzzer` |
43|Linux ASan V8 ARM64 Simulator[*](#ARM-and-ARM64)| `tools/mb/mb.py gen -m chromium.fuzz -b 'Libfuzzer Upload Linux V8-ARM64 ASan' out/libfuzzer` |
44|Linux ASan Debug V8 ARM Simulator[*](#ARM-and-ARM64)| `tools/mb/mb.py gen -m chromium.fuzz -b 'Libfuzzer Upload Linux32 V8-ARM ASan Debug' out/libfuzzer` |
45|Linux ASan Debug V8 ARM64 Simulator[*](#ARM-and-ARM64)| `tools/mb/mb.py gen -m chromium.fuzz -b 'Libfuzzer Upload Linux V8-ARM64 ASan Debug' out/libfuzzer` |
Oliver Changd6ead472017-10-02 19:50:3446
47
48### Linux
Oliver Chang93dae57a2017-10-02 16:41:5849Linux is fully supported by libFuzzer and ClusterFuzz with following sanitizer
aizatsky62c7a842016-05-13 19:23:0150configurations:
51
52| GN Argument | Description |
53|--------------|----|
54| is_asan=true | enables [Address Sanitizer] to catch problems like buffer overruns. |
Oliver Changd6ead472017-10-02 19:50:3455| is_msan=true | enables [Memory Sanitizer] to catch problems like uninitialized reads. \[[*](#MSan)\] |
56| is_ubsan_security=true | enables [Undefined Behavior Sanitizer] to catch undefined behavior like integer overflow. \[[*](#UBSan)\] |
aizatsky62c7a842016-05-13 19:23:0157
58Configuration example:
59
60```bash
61# With address sanitizer
Jonathan Metzmandf29cec2018-10-11 23:12:4162gn gen out/libfuzzer '--args=use_libfuzzer=true is_asan=true' --check
aizatsky62c7a842016-05-13 19:23:0163```
64
Jonathan Metzman5f37d982019-01-03 17:39:0265### Linux x86 (32-bit)
66Fuzzing targets built for x86 can discover bugs that are not found by x64
67builds. Linux x86 is supported by libFuzzer with `is_asan` configuration.
68
69Configuration example:
70
71```bash
72gn gen out/libfuzzer --args="use_libfuzzer=true is_asan=true host_cpu=\"x86\" target_cpu=\"x86\"" --check
73```
74
Jonathan Metzmanf8a8a422018-11-29 21:45:5275### Chrome OS
76Chrome OS is supported by libFuzzer with `is_asan` configuration.
77
78Configuration example:
79
80```bash
81gn gen out/libfuzzer '--args=use_libfuzzer=true is_asan=true target_os="chromeos"' --check
82```
83
84To do a Chrome OS build on Linux (not just for libFuzzer), your `.gclient` file
85must be configured appropriately, see the [Chrome OS build docs] for more
86details.
87
aizatsky62c7a842016-05-13 19:23:0188### Mac
89
Oliver Chang93dae57a2017-10-02 16:41:5890Mac is supported by libFuzzer with `is_asan` configuration.
aizatsky62c7a842016-05-13 19:23:0191
92Configuration example:
93
94```bash
Jonathan Metzmandf29cec2018-10-11 23:12:4195gn gen out/libfuzzer '--args=use_libfuzzer=true is_asan=true mac_deployment_target="10.7"' --check
aizatsky62c7a842016-05-13 19:23:0196```
97
Jonathan Metzmandf29cec2018-10-11 23:12:4198### Windows
99
100Windows is supported by libFuzzer with `is_asan` configuration.
101
102Configuration example:
103
104```bash
Bruce Dawson3817e992018-10-31 23:36:55105gn gen out/libfuzzer "--args=use_libfuzzer=true is_asan=true is_debug=false is_component_build=false" --check
Jonathan Metzmandf29cec2018-10-11 23:12:41106```
107
Marijn Kruisselbrinkd0b14c3ef2018-12-12 01:33:54108On Windows you must use `is_component_build=false` as libFuzzer does not support
Jonathan Metzmandf29cec2018-10-11 23:12:41109component builds on Windows. If you are using `is_asan=true` then you must use
110`is_debug=false` as ASan does not support debug builds on Windows.
111You may also want to consider using `symbol_level=1` which will reduce build
112size by reducing symbol level to the level necessary for libFuzzer (useful
113if building many fuzz targets).
114
Jonathan Metzman9c73a7b2019-01-27 17:03:38115### ARM and ARM64
116
117The V8 ARM and ARM64 simulators are supported by libFuzzer with `is_asan`
118configuration. Note that there is nothing special about these builds for non-V8
119fuzz targets.
120
121ARM configuration example:
122
123
124```bash
125gn gen out/libfuzzer --args="use_libfuzzer=true is_asan=true host_cpu=\"x86\" target_cpu=\"x86\" v8_target_cpu=\"arm\"" --check
126```
127
128ARM64 configuration example:
129
130```bash
131gn gen out/libfuzzer --args="use_libfuzzer=true is_asan=true target_cpu=\"x64\" v8_target_cpu=\"arm64\"" --check
132```
133
aizatsky88a677d2016-03-18 23:18:24134## fuzzer_test GN Template
135
aizatsky9c8c5b02016-03-30 22:09:09136Use `fuzzer_test` to define libFuzzer targets:
aizatsky88a677d2016-03-18 23:18:24137
138```
139fuzzer_test("my_fuzzer") {
140 ...
141}
142```
143
144Following arguments are supported:
145
146| Argument | Description |
147|----------|-------------|
Max Moroz9b370752018-03-20 22:05:32148| `sources` | **required** list of fuzzer test source files |
149| `deps` | fuzzer dependencies |
150| `additional_configs` | additional GN configurations to be used for compilation |
151| `dict` | a dictionary file for the fuzzer |
152| `libfuzzer_options` | runtime options file for the fuzzer. See [Fuzzer Runtime Options](#Fuzzer-Runtime-Options) |
153| `seed_corpus` | single directory containing test inputs, parsed recursively |
154| `seed_corpuses` | multiple directories with the same purpose as `seed_corpus` |
Jonathan Metzman5f37d982019-01-03 17:39:02155| `libs` | additional libraries to link. Same as [libs] for gn targets. |
aizatsky88a677d2016-03-18 23:18:24156
157
158## Fuzzer Runtime Options
159
aizatsky9c8c5b02016-03-30 22:09:09160There are many different runtime options supported by libFuzzer. Options
aizatsky88a677d2016-03-18 23:18:24161are passed as command line arguments:
162
163```
164./fuzzer [-flag1=val1 [-flag2=val2 ...] ] [dir1 [dir2 ...] ]
165```
166
167Most common flags are:
168
169| Flag | Description |
170|------|-------------|
171| max_len | Maximum length of test input. |
172| timeout | Timeout of seconds. Units slower than this value will be reported as bugs. |
Brendon Tiszka965370052024-02-05 21:14:58173| rss_limit_mb | Memory usage limit in Mb, default 2048. Some Chrome targets, such as Blink, require more than the default to initialize. |
aizatsky88a677d2016-03-18 23:18:24174
Abhishek Arya9e4a72c2017-11-29 16:23:33175Full list of options can be found at [libFuzzer options] page and by running
aizatsky88a677d2016-03-18 23:18:24176the binary with `-help=1`.
177
mmoroz062a4a62016-04-12 09:02:33178To specify these options for ClusterFuzz, list all parameters in
179`libfuzzer_options` target attribute:
aizatsky88a677d2016-03-18 23:18:24180
181```
mmoroz062a4a62016-04-12 09:02:33182fuzzer_test("my_fuzzer") {
183 ...
184 libfuzzer_options = [
Max Morozc6fce8a2019-05-15 15:12:35185 # Suppress stdout and stderr output (not recommended, as it may silence useful info).
186 "close_fd_mask=3",
mmoroz062a4a62016-04-12 09:02:33187 ]
188}
aizatsky88a677d2016-03-18 23:18:24189```
190
Abhishek Arya9e4a72c2017-11-29 16:23:33191[libFuzzer options]: http://llvm.org/docs/LibFuzzer.html#options
aizatsky62c7a842016-05-13 19:23:01192[Address Sanitizer]: http://clang.llvm.org/docs/AddressSanitizer.html
193[Memory Sanitizer]: http://clang.llvm.org/docs/MemorySanitizer.html
194[Undefined Behavior Sanitizer]: http://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html
Jonathan Metzman15e88e72018-11-16 19:40:13195[reproduce tool]: https://github.com/google/clusterfuzz-tools
196[these instructions]: https://www.chromium.org/developers/testing/memorysanitizer#TOC-Running-on-other-distros-using-Docker
Jonathan Metzmanf8a8a422018-11-29 21:45:52197[Chrome OS build docs]: https://chromium.googlesource.com/chromium/src/+/HEAD/docs/chromeos_build_instructions.md#updating-your-gclient-config
Jonathan Metzman5f37d982019-01-03 17:39:02198[libs]: https://gn.googlesource.com/gn/+/master/docs/reference.md#libs