|
| 1 | +# The oss-fuzz infrastructure # |
| 2 | + |
| 3 | +# How we use it # |
| 4 | + |
| 5 | +For fuzzing purposes, we use _vsprintf_ to format the output to a |
| 6 | +static buffer. This is because during the |
| 7 | +fuzzing process, we sometimes get *EINTR* if writing to stdout. |
| 8 | +However, in order to replicate a crash, it can help to see what the |
| 9 | +printer was doing before it crashed, so if you set the environment |
| 10 | +variable *TCPDUMP_PRINT* to any value before running the replicator, |
| 11 | +the printer will print to stdout. If you set the environment |
| 12 | +variable *REPLICATE_TRUNCATE* to any value before running the |
| 13 | +replicator, the code will try the given packet and all prefixes |
| 14 | +(to try to find additional related truncated-packet problems). |
| 15 | + |
| 16 | +# Reproducing a crash using an example # |
| 17 | + |
| 18 | +The binaries that we build in this directory can take a data file |
| 19 | +as generated by the fuzzing infrastructure and run it through the |
| 20 | +same function. If you don't understand the output from the |
| 21 | +sanitizer that oss-fuzz provides, you can run again using valgrind: |
| 22 | + |
| 23 | + ~/src/tcpdump/fuzzing @us157.sjc> TCPDUMP_PRINT=1 valgrind ./ether_print_fuzzer ../../oss-fuzz/build/out/tcpdump/crash-20aa211fc54fda2cca155539d1d5189990e6bd4e |
| 24 | + ==2963== Memcheck, a memory error detector |
| 25 | + ==2963== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. |
| 26 | + ==2963== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info |
| 27 | + ==2963== Command: ./ether_print_fuzzer ../../oss-fuzz/build/out/tcpdump/crash-20aa211fc54fda2cca155539d1d5189990e6bd4e |
| 28 | + ==2963== |
| 29 | + StandaloneFuzzTargetMain: running 1 inputs |
| 30 | + Running: ../../oss-fuzz/build/out/tcpdump/crash-20aa211fc54fda2cca155539d1d5189990e6bd4e |
| 31 | + ==2963== Invalid read of size 1 |
| 32 | + ==2963== at 0x454E26: rpl_dio_printopt (print-icmp6.c:665) |
| 33 | + ==2963== by 0x456C7F: rpl_dio_print (print-icmp6.c:714) |
| 34 | + ==2963== by 0x456C7F: rpl_print (print-icmp6.c:839) |
| 35 | + ==2963== by 0x456C7F: icmp6_print (print-icmp6.c:1148) |
| 36 | + ==2963== by 0x4103EB: ip6_print (print-ip6.c:351) |
| 37 | + ==2963== by 0x40C599: ethertype_print (print-ether.c:370) |
| 38 | + ==2963== by 0x40CCCD: ether_print (print-ether.c:237) |
| 39 | + ==2963== by 0x403AAF: LLVMFuzzerTestOneInput (in /home/fenner/src/tcpdump/fuzzing/ether_print_fuzzer) |
| 40 | + ==2963== by 0x403D75: main (in /home/fenner/src/tcpdump/fuzzing/ether_print_fuzzer) |
| 41 | + ==2963== Address 0x5d24b1c is 0 bytes after a block of size 156 alloc'd |
| 42 | + ==2963== at 0x4C2AC36: malloc (vg_replace_malloc.c:299) |
| 43 | + ==2963== by 0x403D12: main (in /home/fenner/src/tcpdump/fuzzing/ether_print_fuzzer) |
| 44 | + ==2963== |
| 45 | + Done: ../../oss-fuzz/build/out/tcpdump/crash-20aa211fc54fda2cca155539d1d5189990e6bd4e: (156 bytes) |
| 46 | + IP6 truncated-ip6 - 4962 bytes missing!(class 0x10, hlim 58, next-header ICMPv6 (58) payload length: 14906) 793a:3a3a:3a3a:28ab:ab00:: > ce:dada:dada:dada:dada:dada:dada:9b9b: ICMP6, RPL, (CLR)DODAG Information Object [dagid:4ff:ffff:ffff:fffe:a08:d5:dada:8e61,seq:5,instance:255,rank:65344,mop:mop4,prf:4] opt:subopt:113 len:2 opt:destprefix len:7 opt:subopt:52 len:54 opt:subopt:255 len:4 opt:subopt:7 len:2 opt:pad0 opt:pad0==2963== |
| 47 | + |
| 48 | +and, of course, when the bug is fixed you can validate it using the |
| 49 | +same sequence. |
| 50 | + |
| 51 | +# Reproducing a crash inside the oss-fuzz infrastructure # |
| 52 | + |
| 53 | + ~/src/oss-fuzz @us157.sjc> python infra/helper.py reproduce -e TCPDUMP_PRINT=1 tcpdump ether_print_fuzzer build/out/tcpdump/crash-20aa211fc54fda2cca155539d1d5189990e6bd4e |
| 54 | + |
| 55 | +# Turning the example into a pcap # |
| 56 | + |
| 57 | +Of course, the tcpdump regression tests use pcap files as input. |
| 58 | +When the oss-fuzz framework creates a replication example, it is |
| 59 | +the raw data that the specific fuzzer accepts (see below). The |
| 60 | +script `corpus/corpus2pcap` converts an example into a pcap, using |
| 61 | +a heuristic as to what type of packet it is. (E.g., if it starts |
| 62 | +with 16 0xff's, then it's a BGP packet; if it starts with 0x45 then |
| 63 | +it is an IPv4 packet). If it guesses wrong, there is a `--type` |
| 64 | +argument to tell it what the type of the input is. |
| 65 | + |
| 66 | +# When fixing a bug found by this infrastructure # |
| 67 | + |
| 68 | +Remember to assign credit to "OSS-Fuzz" |
| 69 | + |
| 70 | +# ip\_print\_fuzzer # |
| 71 | + |
| 72 | +## Input ## |
| 73 | + |
| 74 | +The ip\_print\_fuzzer takes an IPv4 packet as input. |
| 75 | + |
| 76 | +## Corpus ## |
| 77 | + |
| 78 | +The `pcap2corpus` run extracts all IPv4 packets from tests/\*.pcap |
| 79 | +into the ip\_print\_fuzzer\_seed\_corpus.zip |
| 80 | + |
| 81 | +# ip6\_print\_fuzzer # |
| 82 | + |
| 83 | +## Input ## |
| 84 | + |
| 85 | +The ip6\_print\_fuzzer takes an IPv6 packet as input. |
| 86 | + |
| 87 | +## Corpus ## |
| 88 | + |
| 89 | +The `pcap2corpus` run extracts all IPv6 packets from tests/\*.pcap |
| 90 | +into the ip6\_print\_fuzzer\_seed\_corpus.zip |
| 91 | + |
| 92 | +# bgp\_print\_fuzzer # |
| 93 | + |
| 94 | +## Input ## |
| 95 | + |
| 96 | +The bgp\_print\_fuzzer takes a BGP message, starting with marker, |
| 97 | +as input. |
| 98 | + |
| 99 | +## Corpus ## |
| 100 | + |
| 101 | +The `pcap2corpus` run extracts all BGP TCP payloads from tests/\*.pcap |
| 102 | +into the bgp\_print\_fuzzer\_seed\_corpus.zip |
| 103 | + |
| 104 | +TODO: It would be nice to also extract individual messages split at the |
| 105 | +marker, to allow TCP payloads with multiple BGP messages to be parsed |
| 106 | +as individual BGP messages. |
| 107 | + |
| 108 | +TODO: write a tool that takes MRT dump in and outputs every BGP message |
| 109 | +to an individual file |
| 110 | + |
| 111 | +# ether\_print\_fuzzer # |
| 112 | + |
| 113 | +## Input ## |
| 114 | + |
| 115 | +The ether\_print\_fuzzer takes an Ethernet packet, starting with |
| 116 | +14-byte header, as input. |
| 117 | + |
| 118 | +## Corpus ## |
| 119 | + |
| 120 | +The `pcap2corpus` run extracts all Ethernet packets that do not match |
| 121 | +a more-specific type above into the ether\_print\_fuzzer\_seed\_corpus.zip |
| 122 | + |
0 commit comments