VirtualBox

source: vbox/trunk/src/libs/libslirp-4.8.0/fuzzing/README.md@ 105529

Last change on this file since 105529 was 105529, checked in by vboxsync, 8 months ago

libs/libslirp: libslirp 4.8.0 fixed exports. bugref:10268

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.4 KB
Line 
1# Fuzzing libslirp state and instructions
2
3## Current state
4We chose to use libFuzzer because of its custom mutator feature, which allows to keep coherent informations inside the packets being sent to libslirp. This ease the process of fuzzing as packets are less likely to be rejected early during processing them.
5
6In the current state, the `meson.build` file is not compatible with the original one used by libSlirp main repository but it should be easy to merge them in a clean way. Also **in the current state, it seems that there is a memory leak inside the fuzzing code**, which make it run out of memory. The current goal is to find and get rid of this leak to allow fuzzing for longer without the process being interrupted because of it.
7
8Six harness are currently available, more are to be added later to focus on other parts of the code :
9
10- **fuzz-ip-header** : the mutator focuses on the ip header field informations,
11- **fuzz-udp** : the mutator only work on udp packets, mutating the udp header and content, or only one or the other (-h,-d),
12- **fuzz-tcp** : the mutator targets tcp packets, header+data or only one or the other, or only one or the other (-h,-d),
13- **fuzz-icmp** : the mutator focuses on icmp packets,
14
15These harness should be good starting examples on how to fuzz libslirp using libFuzzer.
16
17## Running the fuzzer
18
19Building the fuzzers/harness requires the use of clang as libFuzzer is part of LLVM.
20You can build it running :
21
22`CC=clang meson build && ninja -C build`
23
24It will build the fuzzer in the ./build/fuzzing/ directory.
25
26A script named `fuzzing/coverage.py` is available to generate coverage informations. **It makes a lot of assumptions on the directory structure** and should be read before use.
27
28To run the fuzzer, simply run some of:
29
30- `build/fuzzing/fuzz-ip-header fuzzing/IN_ip-header`
31- `build/fuzzing/fuzz-udp fuzzing/IN_udp`
32- `build/fuzzing/fuzz-udp-h fuzzing/IN_udp-h`
33- `build/fuzzing/fuzz-tftp fuzzing/IN_tftp`
34- `build/fuzzing/fuzz-dhcp fuzzing/IN_dhcp`
35- `build/fuzzing/fuzz-icmp fuzzing/IN_icmp`
36- `build/fuzzing/fuzz-tcp fuzzing/IN_tcp`
37
38Your current directory should be a separate directory as crashes to it. New inputs found by the fuzzer will go directly in the `IN` folder.
39
40# Adding new files to the corpus
41
42In its current state, the fuzzing code is taking pcap files as input, we produced some using `tcpdump` on linux inside qemu with default settings.
43Those files should be captured using the `EN10MB (Ethernet)` data link type, this can be set with the flag `-y` but it seems this can't be done while listening on all interfaces (`-i any`).
44New files should give new coverage, to ensure a new file is usefull the `coverage.py` script (see next section) can be used to compare the coverage with and without that new file.
45
46# Coverage
47
48The `coverage.py` script allows to see coverage informations about the corpus. It makes a lot of assumptions on the directory structure so it should be read and probably modified before running it.
49It must be called with the protocol to cover: `python coverage.py udp report`.
50To generate coverage informations, the following flags are passed to the fuzzer and libslirp :
51
52- g
53- fsanitize-coverage=edge,indirect-calls,trace-cmp
54- fprofile-instr-generate
55- fcoverage-mapping
56
57The last 2 arguments should also be passed to the linker.
58
59Then the `llvm-profdata` and `llvm-cov` tools can be used to generate a report and a fancy set of HTML files with line-coverage informations.
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette