robert.swiecki | 3bb518c | 2010-10-14 00:48:24 +0000 | [diff] [blame] | 1 | /* |
robert.swiecki@gmail.com | 3b630b4 | 2015-02-16 10:53:53 +0000 | [diff] [blame] | 2 | * |
robert.swiecki@gmail.com | 90e9911 | 2015-02-15 02:05:14 +0000 | [diff] [blame] | 3 | * honggfuzz - fuzzing routines |
| 4 | * ----------------------------------------- |
robert.swiecki@gmail.com | 3b630b4 | 2015-02-16 10:53:53 +0000 | [diff] [blame] | 5 | * |
robert.swiecki@gmail.com | 8531f69 | 2015-02-17 12:25:36 +0000 | [diff] [blame] | 6 | * Author: |
| 7 | * Robert Swiecki <swiecki@google.com> |
| 8 | * Felix Gröbert <groebert@google.com> |
robert.swiecki@gmail.com | 3b630b4 | 2015-02-16 10:53:53 +0000 | [diff] [blame] | 9 | * |
robert.swiecki@gmail.com | 772b33d | 2015-02-14 20:35:00 +0000 | [diff] [blame] | 10 | * Copyright 2010-2015 by Google Inc. All Rights Reserved. |
robert.swiecki@gmail.com | 3b630b4 | 2015-02-16 10:53:53 +0000 | [diff] [blame] | 11 | * |
| 12 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 13 | * not use this file except in compliance with the License. You may obtain |
robert.swiecki@gmail.com | 772b33d | 2015-02-14 20:35:00 +0000 | [diff] [blame] | 14 | * a copy of the License at |
robert.swiecki@gmail.com | 3b630b4 | 2015-02-16 10:53:53 +0000 | [diff] [blame] | 15 | * |
robert.swiecki@gmail.com | 772b33d | 2015-02-14 20:35:00 +0000 | [diff] [blame] | 16 | * http://www.apache.org/licenses/LICENSE-2.0 |
robert.swiecki@gmail.com | 3b630b4 | 2015-02-16 10:53:53 +0000 | [diff] [blame] | 17 | * |
robert.swiecki@gmail.com | 772b33d | 2015-02-14 20:35:00 +0000 | [diff] [blame] | 18 | * Unless required by applicable law or agreed to in writing, software |
| 19 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or |
| 21 | * implied. See the License for the specific language governing |
| 22 | * permissions and limitations under the License. |
robert.swiecki@gmail.com | 3b630b4 | 2015-02-16 10:53:53 +0000 | [diff] [blame] | 23 | * |
robert.swiecki@gmail.com | 772b33d | 2015-02-14 20:35:00 +0000 | [diff] [blame] | 24 | */ |
robert.swiecki | 3bb518c | 2010-10-14 00:48:24 +0000 | [diff] [blame] | 25 | |
robert.swiecki@gmail.com | ba85c3e | 2015-02-02 14:55:16 +0000 | [diff] [blame] | 26 | #include "common.h" |
| 27 | #include "fuzz.h" |
| 28 | |
| 29 | #include <errno.h> |
| 30 | #include <fcntl.h> |
robert.swiecki@gmail.com | 90e9911 | 2015-02-15 02:05:14 +0000 | [diff] [blame] | 31 | #include <inttypes.h> |
robert.swiecki@gmail.com | 882900b | 2015-02-11 13:56:22 +0000 | [diff] [blame] | 32 | #include <pthread.h> |
robert.swiecki@gmail.com | ba85c3e | 2015-02-02 14:55:16 +0000 | [diff] [blame] | 33 | #include <signal.h> |
| 34 | #include <stddef.h> |
| 35 | #include <stdint.h> |
| 36 | #include <stdio.h> |
| 37 | #include <stdlib.h> |
| 38 | #include <string.h> |
robert.swiecki | 3bb518c | 2010-10-14 00:48:24 +0000 | [diff] [blame] | 39 | #include <sys/param.h> |
Robert Swiecki | 1e1b353 | 2016-03-10 18:43:28 +0100 | [diff] [blame] | 40 | #include <sys/resource.h> |
Jagger | 08816fd | 2016-03-11 01:32:38 +0100 | [diff] [blame] | 41 | #include <sys/mman.h> |
robert.swiecki | 3bb518c | 2010-10-14 00:48:24 +0000 | [diff] [blame] | 42 | #include <sys/stat.h> |
robert.swiecki@gmail.com | ba85c3e | 2015-02-02 14:55:16 +0000 | [diff] [blame] | 43 | #include <sys/time.h> |
| 44 | #include <sys/types.h> |
| 45 | #include <sys/wait.h> |
robert.swiecki | 3bb518c | 2010-10-14 00:48:24 +0000 | [diff] [blame] | 46 | #include <time.h> |
robert.swiecki@gmail.com | ba85c3e | 2015-02-02 14:55:16 +0000 | [diff] [blame] | 47 | #include <unistd.h> |
robert.swiecki | 3bb518c | 2010-10-14 00:48:24 +0000 | [diff] [blame] | 48 | |
robert.swiecki | 3bb518c | 2010-10-14 00:48:24 +0000 | [diff] [blame] | 49 | #include "arch.h" |
robert.swiecki | 3bb518c | 2010-10-14 00:48:24 +0000 | [diff] [blame] | 50 | #include "files.h" |
robert.swiecki@gmail.com | e7190b9 | 2015-02-14 23:05:42 +0000 | [diff] [blame] | 51 | #include "log.h" |
robert.swiecki@gmail.com | 36700b5 | 2015-02-22 05:03:16 +0000 | [diff] [blame] | 52 | #include "mangle.h" |
robert.swiecki@gmail.com | e7190b9 | 2015-02-14 23:05:42 +0000 | [diff] [blame] | 53 | #include "report.h" |
Jagger | 0026560 | 2016-03-10 02:36:27 +0100 | [diff] [blame] | 54 | #include "sancov.h" |
robert.swiecki@gmail.com | e7190b9 | 2015-02-14 23:05:42 +0000 | [diff] [blame] | 55 | #include "util.h" |
robert.swiecki | 3bb518c | 2010-10-14 00:48:24 +0000 | [diff] [blame] | 56 | |
Jagger | 1e05f74 | 2016-03-10 21:36:27 +0100 | [diff] [blame] | 57 | extern char **environ; |
| 58 | |
Jagger | 6113c43 | 2015-09-24 05:00:28 +0200 | [diff] [blame] | 59 | static pthread_t fuzz_mainThread; |
| 60 | |
robert.swiecki | 3bb518c | 2010-10-14 00:48:24 +0000 | [diff] [blame] | 61 | static void fuzz_getFileName(honggfuzz_t * hfuzz, char *fileName) |
| 62 | { |
robert.swiecki | ba51263 | 2011-01-28 11:57:26 +0000 | [diff] [blame] | 63 | struct timeval tv; |
| 64 | gettimeofday(&tv, NULL); |
| 65 | |
Anestis Bechtsoudis | d968053 | 2015-09-06 17:37:05 +0300 | [diff] [blame] | 66 | snprintf(fileName, PATH_MAX, "%s/.honggfuzz.%d.%lu.%llx.%s", hfuzz->workDir, (int)getpid(), |
robert.swiecki@gmail.com | 6f31991 | 2015-02-28 05:01:37 +0000 | [diff] [blame] | 67 | (unsigned long int)tv.tv_sec, (unsigned long long int)util_rndGet(0, 1ULL << 62), |
robert.swiecki@gmail.com | bb5d264 | 2015-02-25 20:00:00 +0000 | [diff] [blame] | 68 | hfuzz->fileExtn); |
robert.swiecki | 3bb518c | 2010-10-14 00:48:24 +0000 | [diff] [blame] | 69 | } |
| 70 | |
Robert Swiecki | 1e1b353 | 2016-03-10 18:43:28 +0100 | [diff] [blame] | 71 | static bool fuzz_prepareExecve(honggfuzz_t * hfuzz, const char *fileName) |
| 72 | { |
| 73 | /* |
| 74 | * Set timeout (prof), real timeout (2*prof), and rlimit_cpu (2*prof) |
| 75 | */ |
| 76 | if (hfuzz->tmOut) { |
| 77 | struct itimerval it; |
| 78 | |
| 79 | /* |
| 80 | * The hfuzz->tmOut is real CPU usage time... |
| 81 | */ |
| 82 | it.it_value.tv_sec = hfuzz->tmOut; |
| 83 | it.it_value.tv_usec = 0; |
| 84 | it.it_interval.tv_sec = 0; |
| 85 | it.it_interval.tv_usec = 0; |
| 86 | if (setitimer(ITIMER_PROF, &it, NULL) == -1) { |
Robert Swiecki | c6a48b1 | 2016-03-11 17:41:57 +0100 | [diff] [blame] | 87 | PLOG_D("Couldn't set the ITIMER_PROF timer"); |
Robert Swiecki | 1e1b353 | 2016-03-10 18:43:28 +0100 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | /* |
| 91 | * ...so, if a process sleeps, this one should |
| 92 | * trigger a signal... |
| 93 | */ |
| 94 | it.it_value.tv_sec = hfuzz->tmOut; |
| 95 | it.it_value.tv_usec = 0; |
| 96 | it.it_interval.tv_sec = 0; |
| 97 | it.it_interval.tv_usec = 0; |
| 98 | if (setitimer(ITIMER_REAL, &it, NULL) == -1) { |
| 99 | PLOG_E("Couldn't set the ITIMER_REAL timer"); |
| 100 | return false; |
| 101 | } |
| 102 | |
| 103 | /* |
| 104 | * ..if a process sleeps and catches SIGPROF/SIGALRM |
| 105 | * rlimits won't help either. However, arch_checkTimeLimit |
| 106 | * will send a SIGKILL at tmOut + 2 seconds. That should |
| 107 | * do it :) |
| 108 | */ |
| 109 | struct rlimit rl; |
| 110 | |
| 111 | rl.rlim_cur = hfuzz->tmOut + 1; |
| 112 | rl.rlim_max = hfuzz->tmOut + 1; |
| 113 | if (setrlimit(RLIMIT_CPU, &rl) == -1) { |
Robert Swiecki | c6a48b1 | 2016-03-11 17:41:57 +0100 | [diff] [blame] | 114 | PLOG_D("Couldn't enforce the RLIMIT_CPU resource limit"); |
Robert Swiecki | 1e1b353 | 2016-03-10 18:43:28 +0100 | [diff] [blame] | 115 | } |
| 116 | } |
| 117 | |
| 118 | /* |
| 119 | * The address space limit. If big enough - roughly the size of RAM used |
| 120 | */ |
| 121 | if (hfuzz->asLimit) { |
Jagger | 06a4bbc | 2016-03-10 21:19:23 +0100 | [diff] [blame] | 122 | struct rlimit rl = { |
Robert Swiecki | 1e1b353 | 2016-03-10 18:43:28 +0100 | [diff] [blame] | 123 | .rlim_cur = hfuzz->asLimit * 1024ULL * 1024ULL, |
| 124 | .rlim_max = hfuzz->asLimit * 1024ULL * 1024ULL, |
| 125 | }; |
Jagger | 06a4bbc | 2016-03-10 21:19:23 +0100 | [diff] [blame] | 126 | if (setrlimit(RLIMIT_AS, &rl) == -1) { |
Robert Swiecki | 1e1b353 | 2016-03-10 18:43:28 +0100 | [diff] [blame] | 127 | PLOG_D("Couldn't enforce the RLIMIT_AS resource limit, ignoring"); |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | if (hfuzz->nullifyStdio) { |
| 132 | util_nullifyStdio(); |
| 133 | } |
| 134 | |
| 135 | if (hfuzz->fuzzStdin) { |
| 136 | /* |
| 137 | * Uglyyyyyy ;) |
| 138 | */ |
| 139 | if (!util_redirectStdin(fileName)) { |
| 140 | return false; |
| 141 | } |
| 142 | } |
| 143 | |
Jagger | 80041fe | 2016-03-10 21:32:35 +0100 | [diff] [blame] | 144 | if (hfuzz->clearEnv) { |
Jagger | 1e05f74 | 2016-03-10 21:36:27 +0100 | [diff] [blame] | 145 | environ = NULL; |
Jagger | 80041fe | 2016-03-10 21:32:35 +0100 | [diff] [blame] | 146 | } |
Robert Swiecki | 1e1b353 | 2016-03-10 18:43:28 +0100 | [diff] [blame] | 147 | if (sancov_prepareExecve(hfuzz) == false) { |
| 148 | LOG_E("sancov_prepareExecve() failed"); |
| 149 | return false; |
| 150 | } |
| 151 | for (size_t i = 0; i < ARRAYSIZE(hfuzz->envs) && hfuzz->envs[i]; i++) { |
| 152 | putenv(hfuzz->envs[i]); |
| 153 | } |
| 154 | setsid(); |
| 155 | |
| 156 | return true; |
| 157 | } |
| 158 | |
Robert Swiecki | a96d78d | 2016-03-14 16:50:50 +0100 | [diff] [blame] | 159 | static bool fuzz_prepareFileDynamically(honggfuzz_t * hfuzz, fuzzer_t * fuzzer) |
robert.swiecki@gmail.com | 6d6f756 | 2015-02-17 22:18:51 +0000 | [diff] [blame] | 160 | { |
Robert Swiecki | 3bfc33c | 2016-03-14 18:12:41 +0100 | [diff] [blame] | 161 | struct dynfile_t *dynfile; |
Robert Swiecki | a08ab1c | 2016-03-14 18:29:21 +0100 | [diff] [blame] | 162 | |
| 163 | { |
Robert Swiecki | 76ecd5e | 2016-03-16 14:57:03 +0100 | [diff] [blame] | 164 | MX_SCOPED_LOCK(&hfuzz->dynfileq_mutex); |
Robert Swiecki | 4b0390a | 2016-03-14 18:44:05 +0100 | [diff] [blame] | 165 | |
Jagger | b070b81 | 2016-03-15 05:31:30 +0100 | [diff] [blame] | 166 | if (hfuzz->dynfileqCnt == 0) { |
Jagger | e449651 | 2016-03-16 01:55:46 +0100 | [diff] [blame] | 167 | LOG_F("The dynamic file corpus is empty. Apparently, the initial fuzzing of the " |
| 168 | "provided file corpus (-f) has not produced any follow-up files with positive " |
| 169 | "coverage and/or CPU counters"); |
Jagger | b070b81 | 2016-03-15 05:31:30 +0100 | [diff] [blame] | 170 | } |
| 171 | |
Robert Swiecki | 4b0390a | 2016-03-14 18:44:05 +0100 | [diff] [blame] | 172 | size_t i = 0U; |
Robert Swiecki | a08ab1c | 2016-03-14 18:29:21 +0100 | [diff] [blame] | 173 | size_t dynFilePos = util_rndGet(0, hfuzz->dynfileqCnt - 1); |
| 174 | TAILQ_FOREACH(dynfile, &hfuzz->dynfileq, pointers) { |
| 175 | if (i++ == dynFilePos) { |
| 176 | break; |
| 177 | } |
Robert Swiecki | 3bfc33c | 2016-03-14 18:12:41 +0100 | [diff] [blame] | 178 | } |
| 179 | } |
| 180 | |
| 181 | memcpy(fuzzer->dynamicFile, dynfile->data, dynfile->size); |
Robert Swiecki | a08ab1c | 2016-03-14 18:29:21 +0100 | [diff] [blame] | 182 | fuzzer->dynamicFileSz = dynfile->size; |
Robert Swiecki | 3bfc33c | 2016-03-14 18:12:41 +0100 | [diff] [blame] | 183 | |
Anestis Bechtsoudis | 6ef24e4 | 2016-01-13 13:05:53 +0200 | [diff] [blame] | 184 | mangle_Resize(hfuzz, fuzzer->dynamicFile, &fuzzer->dynamicFileSz); |
Robert Swiecki | a96d78d | 2016-03-14 16:50:50 +0100 | [diff] [blame] | 185 | mangle_mangleContent(hfuzz, fuzzer); |
robert.swiecki@gmail.com | 6d6f756 | 2015-02-17 22:18:51 +0000 | [diff] [blame] | 186 | |
robert.swiecki@gmail.com | dc8403e | 2015-03-01 01:33:00 +0000 | [diff] [blame] | 187 | if (files_writeBufToFile |
robert.swiecki@gmail.com | 62e34ae | 2015-03-05 03:39:32 +0000 | [diff] [blame] | 188 | (fuzzer->fileName, fuzzer->dynamicFile, fuzzer->dynamicFileSz, |
| 189 | O_WRONLY | O_CREAT | O_EXCL | O_TRUNC) == false) { |
Robert Swiecki | c8c32db | 2015-10-09 18:06:22 +0200 | [diff] [blame] | 190 | LOG_E("Couldn't write buffer to file '%s'", fuzzer->fileName); |
robert.swiecki@gmail.com | 3b6c629 | 2015-02-26 11:48:46 +0000 | [diff] [blame] | 191 | return false; |
| 192 | } |
robert.swiecki@gmail.com | 6d6f756 | 2015-02-17 22:18:51 +0000 | [diff] [blame] | 193 | |
robert.swiecki@gmail.com | 6d6f756 | 2015-02-17 22:18:51 +0000 | [diff] [blame] | 194 | return true; |
robert.swiecki@gmail.com | d7aed31 | 2015-02-03 21:26:37 +0000 | [diff] [blame] | 195 | } |
| 196 | |
robert.swiecki@gmail.com | 4a7a9d8 | 2015-03-01 01:25:16 +0000 | [diff] [blame] | 197 | static bool fuzz_prepareFile(honggfuzz_t * hfuzz, fuzzer_t * fuzzer, int rnd_index) |
robert.swiecki | 3bb518c | 2010-10-14 00:48:24 +0000 | [diff] [blame] | 198 | { |
robert.swiecki@gmail.com | 4a7a9d8 | 2015-03-01 01:25:16 +0000 | [diff] [blame] | 199 | size_t fileSz = |
| 200 | files_readFileToBufMax(hfuzz->files[rnd_index], fuzzer->dynamicFile, hfuzz->maxFileSz); |
| 201 | if (fileSz == 0UL) { |
Robert Swiecki | c8c32db | 2015-10-09 18:06:22 +0200 | [diff] [blame] | 202 | LOG_E("Couldn't read contents of '%s'", hfuzz->files[rnd_index]); |
robert.swiecki@gmail.com | bb5d264 | 2015-02-25 20:00:00 +0000 | [diff] [blame] | 203 | return false; |
robert.swiecki | 3bb518c | 2010-10-14 00:48:24 +0000 | [diff] [blame] | 204 | } |
Robert Swiecki | a96d78d | 2016-03-14 16:50:50 +0100 | [diff] [blame] | 205 | fuzzer->dynamicFileSz = fileSz; |
robert.swiecki | 3bb518c | 2010-10-14 00:48:24 +0000 | [diff] [blame] | 206 | |
Anestis Bechtsoudis | 25262b3 | 2015-11-07 22:39:47 +0200 | [diff] [blame] | 207 | /* If flip rate is 0.0, early abort file mangling */ |
Robert Swiecki | a96d78d | 2016-03-14 16:50:50 +0100 | [diff] [blame] | 208 | if (fuzzer->flipRate != 0.0L) { |
| 209 | mangle_Resize(hfuzz, fuzzer->dynamicFile, &fuzzer->dynamicFileSz); |
| 210 | mangle_mangleContent(hfuzz, fuzzer); |
Anestis Bechtsoudis | 25262b3 | 2015-11-07 22:39:47 +0200 | [diff] [blame] | 211 | } |
robert.swiecki@gmail.com | c070b94 | 2015-02-25 18:29:19 +0000 | [diff] [blame] | 212 | |
robert.swiecki@gmail.com | dc8403e | 2015-03-01 01:33:00 +0000 | [diff] [blame] | 213 | if (files_writeBufToFile |
Robert Swiecki | a96d78d | 2016-03-14 16:50:50 +0100 | [diff] [blame] | 214 | (fuzzer->fileName, fuzzer->dynamicFile, fuzzer->dynamicFileSz, |
| 215 | O_WRONLY | O_CREAT | O_EXCL) == false) { |
Robert Swiecki | c8c32db | 2015-10-09 18:06:22 +0200 | [diff] [blame] | 216 | LOG_E("Couldn't write buffer to file '%s'", fuzzer->fileName); |
robert.swiecki@gmail.com | e768052 | 2015-02-22 22:22:37 +0000 | [diff] [blame] | 217 | return false; |
| 218 | } |
| 219 | |
robert.swiecki | 3bb518c | 2010-10-14 00:48:24 +0000 | [diff] [blame] | 220 | return true; |
| 221 | } |
| 222 | |
robert.swiecki@gmail.com | 2085120 | 2015-03-01 01:48:15 +0000 | [diff] [blame] | 223 | static bool fuzz_prepareFileExternally(honggfuzz_t * hfuzz, fuzzer_t * fuzzer, int rnd_index) |
robert.swiecki | 3bb518c | 2010-10-14 00:48:24 +0000 | [diff] [blame] | 224 | { |
Robert Swiecki | e48811e | 2016-03-09 18:31:19 +0100 | [diff] [blame] | 225 | { |
| 226 | int dstfd = open(fuzzer->fileName, O_CREAT | O_EXCL | O_RDWR, 0644); |
| 227 | if (dstfd == -1) { |
| 228 | PLOG_E("Couldn't create a temporary file '%s'", fuzzer->fileName); |
robert.swiecki@gmail.com | ebc1cac | 2011-07-02 03:15:51 +0000 | [diff] [blame] | 229 | return false; |
| 230 | } |
Jagger | 28aebbd | 2016-03-10 22:58:51 +0100 | [diff] [blame] | 231 | DEFER(close(dstfd)); |
robert.swiecki@gmail.com | ebc1cac | 2011-07-02 03:15:51 +0000 | [diff] [blame] | 232 | |
Robert Swiecki | e48811e | 2016-03-09 18:31:19 +0100 | [diff] [blame] | 233 | LOG_D("Created '%s' as an input file", fuzzer->fileName); |
| 234 | |
| 235 | if (hfuzz->inputFile) { |
| 236 | size_t fileSz = files_readFileToBufMax(hfuzz->files[rnd_index], fuzzer->dynamicFile, |
| 237 | hfuzz->maxFileSz); |
| 238 | if (fileSz == 0UL) { |
| 239 | LOG_E("Couldn't read '%s'", hfuzz->files[rnd_index]); |
| 240 | unlink(fuzzer->fileName); |
| 241 | return false; |
| 242 | } |
| 243 | |
| 244 | if (files_writeToFd(dstfd, fuzzer->dynamicFile, fileSz) == false) { |
| 245 | unlink(fuzzer->fileName); |
| 246 | return false; |
| 247 | } |
robert.swiecki@gmail.com | ebc1cac | 2011-07-02 03:15:51 +0000 | [diff] [blame] | 248 | } |
robert.swiecki | 3d505e2 | 2010-10-14 01:17:17 +0000 | [diff] [blame] | 249 | |
Robert Swiecki | e48811e | 2016-03-09 18:31:19 +0100 | [diff] [blame] | 250 | } |
robert.swiecki | 3d505e2 | 2010-10-14 01:17:17 +0000 | [diff] [blame] | 251 | |
Anestis Bechtsoudis | 3541b47 | 2015-10-08 09:52:44 -0700 | [diff] [blame] | 252 | pid_t pid = arch_fork(hfuzz); |
robert.swiecki | 3bb518c | 2010-10-14 00:48:24 +0000 | [diff] [blame] | 253 | if (pid == -1) { |
Robert Swiecki | c8c32db | 2015-10-09 18:06:22 +0200 | [diff] [blame] | 254 | PLOG_E("Couldn't fork"); |
robert.swiecki | 3bb518c | 2010-10-14 00:48:24 +0000 | [diff] [blame] | 255 | return false; |
| 256 | } |
| 257 | |
| 258 | if (!pid) { |
| 259 | /* |
robert.swiecki@gmail.com | cdf18f9 | 2015-02-11 22:22:18 +0000 | [diff] [blame] | 260 | * child performs the external file modifications |
robert.swiecki | 3bb518c | 2010-10-14 00:48:24 +0000 | [diff] [blame] | 261 | */ |
robert.swiecki@gmail.com | 2085120 | 2015-03-01 01:48:15 +0000 | [diff] [blame] | 262 | execl(hfuzz->externalCommand, hfuzz->externalCommand, fuzzer->fileName, NULL); |
Robert Swiecki | c8c32db | 2015-10-09 18:06:22 +0200 | [diff] [blame] | 263 | PLOG_F("Couldn't execute '%s %s'", hfuzz->externalCommand, fuzzer->fileName); |
robert.swiecki | 3bb518c | 2010-10-14 00:48:24 +0000 | [diff] [blame] | 264 | return false; |
robert.swiecki@gmail.com | 757ee19 | 2015-02-13 16:54:02 +0000 | [diff] [blame] | 265 | } |
robert.swiecki@gmail.com | 8a9df0e | 2015-02-13 17:08:06 +0000 | [diff] [blame] | 266 | |
robert.swiecki@gmail.com | 757ee19 | 2015-02-13 16:54:02 +0000 | [diff] [blame] | 267 | /* |
| 268 | * parent waits until child is done fuzzing the input file |
| 269 | */ |
robert.swiecki@gmail.com | 757ee19 | 2015-02-13 16:54:02 +0000 | [diff] [blame] | 270 | int childStatus; |
| 271 | int flags = 0; |
robert.swiecki@gmail.com | a229118 | 2015-02-13 16:56:27 +0000 | [diff] [blame] | 272 | #if defined(__WNOTHREAD) |
| 273 | flags |= __WNOTHREAD; |
robert.swiecki@gmail.com | 8a9df0e | 2015-02-13 17:08:06 +0000 | [diff] [blame] | 274 | #endif /* defined(__WNOTHREAD) */ |
robert.swiecki@gmail.com | 757ee19 | 2015-02-13 16:54:02 +0000 | [diff] [blame] | 275 | while (wait4(pid, &childStatus, flags, NULL) != pid) ; |
robert.swiecki@gmail.com | 757ee19 | 2015-02-13 16:54:02 +0000 | [diff] [blame] | 276 | if (WIFEXITED(childStatus)) { |
Robert Swiecki | c8c32db | 2015-10-09 18:06:22 +0200 | [diff] [blame] | 277 | LOG_D("External command exited with status %d", WEXITSTATUS(childStatus)); |
robert.swiecki@gmail.com | 757ee19 | 2015-02-13 16:54:02 +0000 | [diff] [blame] | 278 | return true; |
| 279 | } |
| 280 | if (WIFSIGNALED(childStatus)) { |
Robert Swiecki | c8c32db | 2015-10-09 18:06:22 +0200 | [diff] [blame] | 281 | LOG_E("External command terminated with signal %d", WTERMSIG(childStatus)); |
robert.swiecki | 3d505e2 | 2010-10-14 01:17:17 +0000 | [diff] [blame] | 282 | return false; |
robert.swiecki | 3bb518c | 2010-10-14 00:48:24 +0000 | [diff] [blame] | 283 | } |
Robert Swiecki | c8c32db | 2015-10-09 18:06:22 +0200 | [diff] [blame] | 284 | LOG_F("External command terminated abnormally, status: %d", childStatus); |
robert.swiecki@gmail.com | 757ee19 | 2015-02-13 16:54:02 +0000 | [diff] [blame] | 285 | return false; |
robert.swiecki | 3bb518c | 2010-10-14 00:48:24 +0000 | [diff] [blame] | 286 | } |
| 287 | |
Anestis Bechtsoudis | 5c86ebc | 2015-09-27 18:06:43 +0300 | [diff] [blame] | 288 | static bool fuzz_runVerifier(honggfuzz_t * hfuzz, fuzzer_t * crashedFuzzer) |
| 289 | { |
Anestis Bechtsoudis | 5c86ebc | 2015-09-27 18:06:43 +0300 | [diff] [blame] | 290 | int crashFd = -1; |
| 291 | uint8_t *crashBuf = NULL; |
| 292 | off_t crashFileSz = 0; |
| 293 | |
| 294 | crashBuf = files_mapFile(crashedFuzzer->crashFileName, &crashFileSz, &crashFd, false); |
| 295 | if (crashBuf == NULL) { |
Anestis Bechtsoudis | 0cde66f | 2015-10-11 19:37:11 -0700 | [diff] [blame] | 296 | LOG_E("Couldn't open and map '%s' in R/O mode", crashedFuzzer->crashFileName); |
Robert Swiecki | e48811e | 2016-03-09 18:31:19 +0100 | [diff] [blame] | 297 | return false; |
Anestis Bechtsoudis | 5c86ebc | 2015-09-27 18:06:43 +0300 | [diff] [blame] | 298 | } |
Jagger | 28aebbd | 2016-03-10 22:58:51 +0100 | [diff] [blame] | 299 | DEFER(munmap(crashBuf, crashFileSz)); |
| 300 | DEFER(close(crashFd)); |
Anestis Bechtsoudis | 5c86ebc | 2015-09-27 18:06:43 +0300 | [diff] [blame] | 301 | |
Anestis Bechtsoudis | 0cde66f | 2015-10-11 19:37:11 -0700 | [diff] [blame] | 302 | LOG_I("Launching verifier for %" PRIx64 " hash", crashedFuzzer->backtrace); |
Anestis Bechtsoudis | 5c86ebc | 2015-09-27 18:06:43 +0300 | [diff] [blame] | 303 | for (int i = 0; i < _HF_VERIFIER_ITER; i++) { |
| 304 | fuzzer_t vFuzzer = { |
| 305 | .pid = 0, |
| 306 | .timeStartedMillis = util_timeNowMillis(), |
Anestis Bechtsoudis | ecb0a66 | 2015-09-27 18:19:46 +0300 | [diff] [blame] | 307 | .crashFileName = {0}, |
Anestis Bechtsoudis | 5c86ebc | 2015-09-27 18:06:43 +0300 | [diff] [blame] | 308 | .pc = 0ULL, |
| 309 | .backtrace = 0ULL, |
| 310 | .access = 0ULL, |
| 311 | .exception = 0, |
| 312 | .dynamicFileSz = 0, |
| 313 | .dynamicFile = NULL, |
| 314 | .hwCnts = { |
| 315 | .cpuInstrCnt = 0ULL, |
| 316 | .cpuBranchCnt = 0ULL, |
Anestis Bechtsoudis | 5c86ebc | 2015-09-27 18:06:43 +0300 | [diff] [blame] | 317 | .customCnt = 0ULL, |
Robert Swiecki | 3bfc33c | 2016-03-14 18:12:41 +0100 | [diff] [blame] | 318 | .bbCnt = 0ULL, |
Anestis Bechtsoudis | 5c86ebc | 2015-09-27 18:06:43 +0300 | [diff] [blame] | 319 | }, |
Anestis Bechtsoudis | be0ac7b | 2015-12-26 15:38:47 +0200 | [diff] [blame] | 320 | .sanCovCnts = { |
Anestis Bechtsoudis | 56e360f | 2016-01-11 14:29:17 +0200 | [diff] [blame] | 321 | .hitBBCnt = 0ULL, |
| 322 | .totalBBCnt = 0ULL, |
Anestis Bechtsoudis | a16f70f | 2016-01-03 13:03:21 +0200 | [diff] [blame] | 323 | .dsoCnt = 0ULL, |
| 324 | .iDsoCnt = 0ULL, |
Anestis Bechtsoudis | 56e360f | 2016-01-11 14:29:17 +0200 | [diff] [blame] | 325 | .newBBCnt = 0ULL, |
Anestis Bechtsoudis | a16f70f | 2016-01-03 13:03:21 +0200 | [diff] [blame] | 326 | .crashesCnt = 0ULL, |
Anestis Bechtsoudis | be0ac7b | 2015-12-26 15:38:47 +0200 | [diff] [blame] | 327 | }, |
Anestis Bechtsoudis | 5c86ebc | 2015-09-27 18:06:43 +0300 | [diff] [blame] | 328 | .report = {'\0'}, |
Anestis Bechtsoudis | 6b9e83d | 2015-10-02 11:10:50 -0700 | [diff] [blame] | 329 | .mainWorker = false |
Anestis Bechtsoudis | 5c86ebc | 2015-09-27 18:06:43 +0300 | [diff] [blame] | 330 | }; |
| 331 | |
| 332 | fuzz_getFileName(hfuzz, vFuzzer.fileName); |
| 333 | if (files_writeBufToFile |
| 334 | (vFuzzer.fileName, crashBuf, crashFileSz, O_WRONLY | O_CREAT | O_EXCL) == false) { |
Anestis Bechtsoudis | 0cde66f | 2015-10-11 19:37:11 -0700 | [diff] [blame] | 335 | LOG_E("Couldn't write buffer to file '%s'", vFuzzer.fileName); |
Robert Swiecki | e48811e | 2016-03-09 18:31:19 +0100 | [diff] [blame] | 336 | return false; |
Anestis Bechtsoudis | 5c86ebc | 2015-09-27 18:06:43 +0300 | [diff] [blame] | 337 | } |
| 338 | |
Anestis Bechtsoudis | 3541b47 | 2015-10-08 09:52:44 -0700 | [diff] [blame] | 339 | vFuzzer.pid = arch_fork(hfuzz); |
Anestis Bechtsoudis | 5c86ebc | 2015-09-27 18:06:43 +0300 | [diff] [blame] | 340 | if (vFuzzer.pid == -1) { |
Anestis Bechtsoudis | 0cde66f | 2015-10-11 19:37:11 -0700 | [diff] [blame] | 341 | PLOG_F("Couldn't fork"); |
Anestis Bechtsoudis | 5c86ebc | 2015-09-27 18:06:43 +0300 | [diff] [blame] | 342 | return false; |
| 343 | } |
| 344 | |
| 345 | if (!vFuzzer.pid) { |
Robert Swiecki | 1e1b353 | 2016-03-10 18:43:28 +0100 | [diff] [blame] | 346 | if (fuzz_prepareExecve(hfuzz, crashedFuzzer->crashFileName) == false) { |
| 347 | LOG_E("fuzz_prepareExecve() failed"); |
Jagger | 2b97dc9 | 2016-03-10 04:28:18 +0100 | [diff] [blame] | 348 | return false; |
| 349 | } |
Anestis Bechtsoudis | 5c86ebc | 2015-09-27 18:06:43 +0300 | [diff] [blame] | 350 | if (!arch_launchChild(hfuzz, crashedFuzzer->crashFileName)) { |
Anestis Bechtsoudis | 0cde66f | 2015-10-11 19:37:11 -0700 | [diff] [blame] | 351 | LOG_E("Error launching verifier child process"); |
Robert Swiecki | e48811e | 2016-03-09 18:31:19 +0100 | [diff] [blame] | 352 | return false; |
Anestis Bechtsoudis | 5c86ebc | 2015-09-27 18:06:43 +0300 | [diff] [blame] | 353 | } |
| 354 | } |
| 355 | |
| 356 | arch_reapChild(hfuzz, &vFuzzer); |
| 357 | unlink(vFuzzer.fileName); |
| 358 | |
Anestis Bechtsoudis | ecb0a66 | 2015-09-27 18:19:46 +0300 | [diff] [blame] | 359 | /* If stack hash doesn't match skip name tag and exit */ |
Anestis Bechtsoudis | 5c86ebc | 2015-09-27 18:06:43 +0300 | [diff] [blame] | 360 | if (crashedFuzzer->backtrace != vFuzzer.backtrace) { |
Anestis Bechtsoudis | 0cde66f | 2015-10-11 19:37:11 -0700 | [diff] [blame] | 361 | LOG_D("Verifier stack hash mismatch"); |
Robert Swiecki | e48811e | 2016-03-09 18:31:19 +0100 | [diff] [blame] | 362 | return false; |
Anestis Bechtsoudis | 5c86ebc | 2015-09-27 18:06:43 +0300 | [diff] [blame] | 363 | } |
| 364 | } |
| 365 | |
| 366 | /* Workspace is inherited, just append a extra suffix */ |
| 367 | char verFile[PATH_MAX] = { 0 }; |
| 368 | snprintf(verFile, sizeof(verFile), "%s.verified", crashedFuzzer->crashFileName); |
Anestis Bechtsoudis | ecb0a66 | 2015-09-27 18:19:46 +0300 | [diff] [blame] | 369 | |
Anestis Bechtsoudis | d86e660 | 2015-11-07 18:34:06 +0200 | [diff] [blame] | 370 | /* Copy file with new suffix & remove original copy */ |
| 371 | bool dstFileExists = false; |
| 372 | if (files_copyFile(crashedFuzzer->crashFileName, verFile, &dstFileExists)) { |
| 373 | LOG_I("Successfully verified, saving as (%s)", verFile); |
Jagger | d34417d | 2016-03-16 01:26:54 +0100 | [diff] [blame] | 374 | ATOMIC_POST_INC(hfuzz->verifiedCrashesCnt); |
Anestis Bechtsoudis | d86e660 | 2015-11-07 18:34:06 +0200 | [diff] [blame] | 375 | unlink(crashedFuzzer->crashFileName); |
| 376 | } else { |
| 377 | if (dstFileExists) { |
| 378 | LOG_I("It seems that '%s' already exists, skipping", verFile); |
| 379 | } else { |
| 380 | LOG_E("Couldn't copy '%s' to '%s'", crashedFuzzer->crashFileName, verFile); |
Robert Swiecki | e48811e | 2016-03-09 18:31:19 +0100 | [diff] [blame] | 381 | return false; |
Anestis Bechtsoudis | d86e660 | 2015-11-07 18:34:06 +0200 | [diff] [blame] | 382 | } |
Anestis Bechtsoudis | 5c86ebc | 2015-09-27 18:06:43 +0300 | [diff] [blame] | 383 | } |
Anestis Bechtsoudis | ecb0a66 | 2015-09-27 18:19:46 +0300 | [diff] [blame] | 384 | |
Robert Swiecki | e48811e | 2016-03-09 18:31:19 +0100 | [diff] [blame] | 385 | return true; |
Anestis Bechtsoudis | 5c86ebc | 2015-09-27 18:06:43 +0300 | [diff] [blame] | 386 | } |
| 387 | |
Robert Swiecki | a4a6805 | 2016-03-17 16:51:01 +0100 | [diff] [blame^] | 388 | static void fuzz_addFileToFileQLocked(honggfuzz_t * hfuzz, uint8_t * data, size_t size, |
| 389 | uint64_t cov) |
Robert Swiecki | f3534bb | 2016-03-14 18:55:10 +0100 | [diff] [blame] | 390 | { |
Robert Swiecki | 7084e65 | 2016-03-14 19:47:00 +0100 | [diff] [blame] | 391 | struct dynfile_t *dynfile = (struct dynfile_t *)util_Malloc(sizeof(struct dynfile_t)); |
Robert Swiecki | f3534bb | 2016-03-14 18:55:10 +0100 | [diff] [blame] | 392 | dynfile->size = size; |
Robert Swiecki | 7084e65 | 2016-03-14 19:47:00 +0100 | [diff] [blame] | 393 | dynfile->data = (uint8_t *) util_Malloc(size); |
Robert Swiecki | f3534bb | 2016-03-14 18:55:10 +0100 | [diff] [blame] | 394 | memcpy(dynfile->data, data, size); |
| 395 | TAILQ_INSERT_TAIL(&hfuzz->dynfileq, dynfile, pointers); |
| 396 | hfuzz->dynfileqCnt++; |
| 397 | |
| 398 | char fname[PATH_MAX]; |
Robert Swiecki | a4a6805 | 2016-03-17 16:51:01 +0100 | [diff] [blame^] | 399 | snprintf(fname, sizeof(fname), |
| 400 | "%s/COVERAGE.PID.%d.COVBB.%09" PRId64 ".TIME.%" PRIu64 ".RND.%" PRIx64, hfuzz->workDir, |
| 401 | getpid(), cov, (uint64_t) time(NULL), util_rndGet(0, 0xFFFFFFFFFFFF)); |
Robert Swiecki | f3534bb | 2016-03-14 18:55:10 +0100 | [diff] [blame] | 402 | if (files_writeBufToFile(fname, data, size, O_WRONLY | O_CREAT | O_EXCL | O_TRUNC) == false) { |
| 403 | LOG_W("Couldn't write buffer to file '%s'", fname); |
| 404 | } |
| 405 | } |
| 406 | |
Anestis Bechtsoudis | be0ac7b | 2015-12-26 15:38:47 +0200 | [diff] [blame] | 407 | static void fuzz_perfFeedback(honggfuzz_t * hfuzz, fuzzer_t * fuzzer) |
| 408 | { |
| 409 | LOG_D |
Robert Swiecki | 3bfc33c | 2016-03-14 18:12:41 +0100 | [diff] [blame] | 410 | ("New file size: %zu, Perf feedback new/cur (instr,branch): %" PRIu64 "/%" PRIu64 ",%" |
| 411 | PRIu64 "/%" PRIu64 ", BBcnt new/total: %" PRIu64 "/%" PRIu64, fuzzer->dynamicFileSz, |
| 412 | fuzzer->hwCnts.cpuInstrCnt, hfuzz->hwCnts.cpuInstrCnt, fuzzer->hwCnts.cpuBranchCnt, |
| 413 | hfuzz->hwCnts.cpuBranchCnt, fuzzer->hwCnts.bbCnt, hfuzz->hwCnts.bbCnt); |
Anestis Bechtsoudis | be0ac7b | 2015-12-26 15:38:47 +0200 | [diff] [blame] | 414 | |
Robert Swiecki | 76ecd5e | 2016-03-16 14:57:03 +0100 | [diff] [blame] | 415 | MX_SCOPED_LOCK(&hfuzz->dynfileq_mutex); |
Anestis Bechtsoudis | be0ac7b | 2015-12-26 15:38:47 +0200 | [diff] [blame] | 416 | |
| 417 | int64_t diff0 = hfuzz->hwCnts.cpuInstrCnt - fuzzer->hwCnts.cpuInstrCnt; |
| 418 | int64_t diff1 = hfuzz->hwCnts.cpuBranchCnt - fuzzer->hwCnts.cpuBranchCnt; |
Robert Swiecki | 3bfc33c | 2016-03-14 18:12:41 +0100 | [diff] [blame] | 419 | int64_t diff2 = hfuzz->hwCnts.customCnt - fuzzer->hwCnts.customCnt; |
Anestis Bechtsoudis | be0ac7b | 2015-12-26 15:38:47 +0200 | [diff] [blame] | 420 | |
Robert Swiecki | 3bfc33c | 2016-03-14 18:12:41 +0100 | [diff] [blame] | 421 | if (diff0 < 0 || diff1 < 0 || diff2 < 0 || fuzzer->hwCnts.bbCnt > 0) { |
Robert Swiecki | f3534bb | 2016-03-14 18:55:10 +0100 | [diff] [blame] | 422 | LOG_I |
Robert Swiecki | 3bfc33c | 2016-03-14 18:12:41 +0100 | [diff] [blame] | 423 | ("New file size: %zu, Perf feedback new/cur (instr,branch): %" PRIu64 "/%" PRIu64 ",%" |
| 424 | PRIu64 "/%" PRIu64 ", BBcnt new/total: %" PRIu64 "/%" PRIu64, fuzzer->dynamicFileSz, |
| 425 | fuzzer->hwCnts.cpuInstrCnt, hfuzz->hwCnts.cpuInstrCnt, fuzzer->hwCnts.cpuBranchCnt, |
| 426 | hfuzz->hwCnts.cpuBranchCnt, fuzzer->hwCnts.bbCnt, hfuzz->hwCnts.bbCnt); |
Anestis Bechtsoudis | be0ac7b | 2015-12-26 15:38:47 +0200 | [diff] [blame] | 427 | |
Anestis Bechtsoudis | be0ac7b | 2015-12-26 15:38:47 +0200 | [diff] [blame] | 428 | hfuzz->hwCnts.cpuInstrCnt = fuzzer->hwCnts.cpuInstrCnt; |
| 429 | hfuzz->hwCnts.cpuBranchCnt = fuzzer->hwCnts.cpuBranchCnt; |
Anestis Bechtsoudis | be0ac7b | 2015-12-26 15:38:47 +0200 | [diff] [blame] | 430 | hfuzz->hwCnts.customCnt = fuzzer->hwCnts.customCnt; |
Robert Swiecki | 3bfc33c | 2016-03-14 18:12:41 +0100 | [diff] [blame] | 431 | hfuzz->hwCnts.bbCnt += fuzzer->hwCnts.bbCnt; |
Anestis Bechtsoudis | be0ac7b | 2015-12-26 15:38:47 +0200 | [diff] [blame] | 432 | |
Robert Swiecki | a4a6805 | 2016-03-17 16:51:01 +0100 | [diff] [blame^] | 433 | fuzz_addFileToFileQLocked(hfuzz, fuzzer->dynamicFile, fuzzer->dynamicFileSz, |
| 434 | fuzzer->hwCnts.bbCnt); |
Anestis Bechtsoudis | be0ac7b | 2015-12-26 15:38:47 +0200 | [diff] [blame] | 435 | } |
Anestis Bechtsoudis | be0ac7b | 2015-12-26 15:38:47 +0200 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | static void fuzz_sanCovFeedback(honggfuzz_t * hfuzz, fuzzer_t * fuzzer) |
| 439 | { |
| 440 | LOG_D |
Robert Swiecki | 3bfc33c | 2016-03-14 18:12:41 +0100 | [diff] [blame] | 441 | ("File size (Best/New): %zu, SanCov feedback (bb,dso): Best: [%" PRIu64 |
Anestis Bechtsoudis | 56e360f | 2016-01-11 14:29:17 +0200 | [diff] [blame] | 442 | ",%" PRIu64 "] / New: [%" PRIu64 ",%" PRIu64 "], newBBs:%" PRIu64, |
Robert Swiecki | 3bfc33c | 2016-03-14 18:12:41 +0100 | [diff] [blame] | 443 | fuzzer->dynamicFileSz, hfuzz->sanCovCnts.hitBBCnt, |
Anestis Bechtsoudis | 56e360f | 2016-01-11 14:29:17 +0200 | [diff] [blame] | 444 | hfuzz->sanCovCnts.iDsoCnt, fuzzer->sanCovCnts.hitBBCnt, fuzzer->sanCovCnts.iDsoCnt, |
| 445 | fuzzer->sanCovCnts.newBBCnt); |
Anestis Bechtsoudis | be0ac7b | 2015-12-26 15:38:47 +0200 | [diff] [blame] | 446 | |
Robert Swiecki | 76ecd5e | 2016-03-16 14:57:03 +0100 | [diff] [blame] | 447 | MX_SCOPED_LOCK(&hfuzz->dynfileq_mutex); |
Anestis Bechtsoudis | be0ac7b | 2015-12-26 15:38:47 +0200 | [diff] [blame] | 448 | |
Anestis Bechtsoudis | a16f70f | 2016-01-03 13:03:21 +0200 | [diff] [blame] | 449 | /* |
| 450 | * Keep mutated seed if: |
Robert Swiecki | 142f941 | 2016-03-14 19:22:01 +0100 | [diff] [blame] | 451 | * a) Newly discovered (not met before) BBs |
| 452 | * b) More instrumented DSOs loaded |
Robert Swiecki | 23ec02a | 2016-01-19 18:47:45 +0100 | [diff] [blame] | 453 | * |
Anestis Bechtsoudis | b78cf60 | 2016-01-07 13:10:50 +0200 | [diff] [blame] | 454 | * TODO: (a) method can significantly assist to further improvements in interesting areas |
Anestis Bechtsoudis | a16f70f | 2016-01-03 13:03:21 +0200 | [diff] [blame] | 455 | * discovery if combined with seeds pool/queue support. If a runtime queue is maintained |
| 456 | * more interesting seeds can be saved between runs instead of instantly discarded |
| 457 | * based on current absolute elitism (only one mutated seed is promoted). |
| 458 | */ |
Robert Swiecki | 142f941 | 2016-03-14 19:22:01 +0100 | [diff] [blame] | 459 | if (fuzzer->sanCovCnts.newBBCnt > 0 || hfuzz->sanCovCnts.iDsoCnt < fuzzer->sanCovCnts.iDsoCnt) { |
Robert Swiecki | 3bfc33c | 2016-03-14 18:12:41 +0100 | [diff] [blame] | 460 | LOG_I("SanCov Update: file size (Cur): %zu, newBBs:%" PRIu64 |
Anestis Bechtsoudis | a16f70f | 2016-01-03 13:03:21 +0200 | [diff] [blame] | 461 | ", counters (Cur,New): %" PRIu64 "/%" PRIu64 ",%" PRIu64 "/%" PRIu64, |
Robert Swiecki | 3bfc33c | 2016-03-14 18:12:41 +0100 | [diff] [blame] | 462 | fuzzer->dynamicFileSz, fuzzer->sanCovCnts.newBBCnt, |
Anestis Bechtsoudis | 56e360f | 2016-01-11 14:29:17 +0200 | [diff] [blame] | 463 | hfuzz->sanCovCnts.hitBBCnt, hfuzz->sanCovCnts.iDsoCnt, fuzzer->sanCovCnts.hitBBCnt, |
Anestis Bechtsoudis | a16f70f | 2016-01-03 13:03:21 +0200 | [diff] [blame] | 464 | fuzzer->sanCovCnts.iDsoCnt); |
Anestis Bechtsoudis | be0ac7b | 2015-12-26 15:38:47 +0200 | [diff] [blame] | 465 | |
Robert Swiecki | 142f941 | 2016-03-14 19:22:01 +0100 | [diff] [blame] | 466 | hfuzz->sanCovCnts.hitBBCnt += fuzzer->sanCovCnts.newBBCnt; |
Anestis Bechtsoudis | a16f70f | 2016-01-03 13:03:21 +0200 | [diff] [blame] | 467 | hfuzz->sanCovCnts.dsoCnt = fuzzer->sanCovCnts.dsoCnt; |
| 468 | hfuzz->sanCovCnts.iDsoCnt = fuzzer->sanCovCnts.iDsoCnt; |
| 469 | hfuzz->sanCovCnts.crashesCnt += fuzzer->sanCovCnts.crashesCnt; |
Robert Swiecki | 142f941 | 2016-03-14 19:22:01 +0100 | [diff] [blame] | 470 | hfuzz->sanCovCnts.newBBCnt = fuzzer->sanCovCnts.newBBCnt; |
Anestis Bechtsoudis | b78cf60 | 2016-01-07 13:10:50 +0200 | [diff] [blame] | 471 | |
Anestis Bechtsoudis | 56e360f | 2016-01-11 14:29:17 +0200 | [diff] [blame] | 472 | if (hfuzz->sanCovCnts.totalBBCnt < fuzzer->sanCovCnts.totalBBCnt) { |
Anestis Bechtsoudis | a16f70f | 2016-01-03 13:03:21 +0200 | [diff] [blame] | 473 | /* Keep only the max value (for dlopen cases) to measure total target coverage */ |
Anestis Bechtsoudis | 56e360f | 2016-01-11 14:29:17 +0200 | [diff] [blame] | 474 | hfuzz->sanCovCnts.totalBBCnt = fuzzer->sanCovCnts.totalBBCnt; |
Anestis Bechtsoudis | a16f70f | 2016-01-03 13:03:21 +0200 | [diff] [blame] | 475 | } |
Anestis Bechtsoudis | be0ac7b | 2015-12-26 15:38:47 +0200 | [diff] [blame] | 476 | |
Robert Swiecki | a4a6805 | 2016-03-17 16:51:01 +0100 | [diff] [blame^] | 477 | fuzz_addFileToFileQLocked(hfuzz, fuzzer->dynamicFile, fuzzer->dynamicFileSz, |
| 478 | fuzzer->sanCovCnts.hitBBCnt); |
Anestis Bechtsoudis | be0ac7b | 2015-12-26 15:38:47 +0200 | [diff] [blame] | 479 | } |
Anestis Bechtsoudis | be0ac7b | 2015-12-26 15:38:47 +0200 | [diff] [blame] | 480 | } |
| 481 | |
Robert Swiecki | 6d01e82 | 2016-03-15 20:21:46 +0100 | [diff] [blame] | 482 | static fuzzState_t fuzz_getState(honggfuzz_t * hfuzz) |
| 483 | { |
Jagger | d34417d | 2016-03-16 01:26:54 +0100 | [diff] [blame] | 484 | return ATOMIC_GET(hfuzz->state); |
Robert Swiecki | 6d01e82 | 2016-03-15 20:21:46 +0100 | [diff] [blame] | 485 | } |
| 486 | |
| 487 | static void fuzz_setState(honggfuzz_t * hfuzz, fuzzState_t state) |
| 488 | { |
Jagger | d34417d | 2016-03-16 01:26:54 +0100 | [diff] [blame] | 489 | ATOMIC_SET(hfuzz->state, state); |
Robert Swiecki | 6d01e82 | 2016-03-15 20:21:46 +0100 | [diff] [blame] | 490 | } |
| 491 | |
Jagger | 190f0dc | 2015-09-05 16:41:22 +0200 | [diff] [blame] | 492 | static void fuzz_fuzzLoop(honggfuzz_t * hfuzz) |
| 493 | { |
| 494 | fuzzer_t fuzzer = { |
| 495 | .pid = 0, |
| 496 | .timeStartedMillis = util_timeNowMillis(), |
Anestis Bechtsoudis | ecb0a66 | 2015-09-27 18:19:46 +0300 | [diff] [blame] | 497 | .crashFileName = {0}, |
Jagger | 190f0dc | 2015-09-05 16:41:22 +0200 | [diff] [blame] | 498 | .pc = 0ULL, |
| 499 | .backtrace = 0ULL, |
| 500 | .access = 0ULL, |
| 501 | .exception = 0, |
Robert Swiecki | a96d78d | 2016-03-14 16:50:50 +0100 | [diff] [blame] | 502 | .mainWorker = true, |
| 503 | .flipRate = hfuzz->origFlipRate, |
| 504 | |
Anestis Bechtsoudis | be0ac7b | 2015-12-26 15:38:47 +0200 | [diff] [blame] | 505 | .sanCovCnts = { |
Anestis Bechtsoudis | 56e360f | 2016-01-11 14:29:17 +0200 | [diff] [blame] | 506 | .hitBBCnt = 0ULL, |
| 507 | .totalBBCnt = 0ULL, |
Anestis Bechtsoudis | a16f70f | 2016-01-03 13:03:21 +0200 | [diff] [blame] | 508 | .dsoCnt = 0ULL, |
| 509 | .iDsoCnt = 0ULL, |
Anestis Bechtsoudis | 56e360f | 2016-01-11 14:29:17 +0200 | [diff] [blame] | 510 | .newBBCnt = 0ULL, |
Anestis Bechtsoudis | a16f70f | 2016-01-03 13:03:21 +0200 | [diff] [blame] | 511 | .crashesCnt = 0ULL, |
Anestis Bechtsoudis | be0ac7b | 2015-12-26 15:38:47 +0200 | [diff] [blame] | 512 | }, |
Robert Swiecki | a96d78d | 2016-03-14 16:50:50 +0100 | [diff] [blame] | 513 | .dynamicFileSz = 0, |
Robert Swiecki | 7084e65 | 2016-03-14 19:47:00 +0100 | [diff] [blame] | 514 | .dynamicFile = util_Malloc(hfuzz->maxFileSz), |
Robert Swiecki | a96d78d | 2016-03-14 16:50:50 +0100 | [diff] [blame] | 515 | |
| 516 | .hwCnts = { |
| 517 | .cpuInstrCnt = 0ULL, |
| 518 | .cpuBranchCnt = 0ULL, |
Robert Swiecki | a96d78d | 2016-03-14 16:50:50 +0100 | [diff] [blame] | 519 | .customCnt = 0ULL, |
Robert Swiecki | 3bfc33c | 2016-03-14 18:12:41 +0100 | [diff] [blame] | 520 | .bbCnt = 0ULL, |
Robert Swiecki | a96d78d | 2016-03-14 16:50:50 +0100 | [diff] [blame] | 521 | }, |
Anestis Bechtsoudis | 5c86ebc | 2015-09-27 18:06:43 +0300 | [diff] [blame] | 522 | .report = {'\0'}, |
Jagger | 190f0dc | 2015-09-05 16:41:22 +0200 | [diff] [blame] | 523 | }; |
Jagger | 28aebbd | 2016-03-10 22:58:51 +0100 | [diff] [blame] | 524 | DEFER(free(fuzzer.dynamicFile)); |
Jagger | 190f0dc | 2015-09-05 16:41:22 +0200 | [diff] [blame] | 525 | |
Anestis Bechtsoudis | 2013f25 | 2015-11-07 22:03:31 +0200 | [diff] [blame] | 526 | size_t rnd_index = util_rndGet(0, hfuzz->fileCnt - 1); |
Anestis Bechtsoudis | 46ea10e | 2015-11-07 18:16:25 +0200 | [diff] [blame] | 527 | |
| 528 | /* If dry run mode, pick the next file and not a random one */ |
Robert Swiecki | a96d78d | 2016-03-14 16:50:50 +0100 | [diff] [blame] | 529 | if (fuzzer.flipRate == 0.0L && hfuzz->useVerifier) { |
Jagger | d34417d | 2016-03-16 01:26:54 +0100 | [diff] [blame] | 530 | rnd_index = ATOMIC_POST_INC(hfuzz->lastFileIndex); |
Anestis Bechtsoudis | 46ea10e | 2015-11-07 18:16:25 +0200 | [diff] [blame] | 531 | } |
Robert Swiecki | 129afe8 | 2016-03-15 20:03:20 +0100 | [diff] [blame] | 532 | |
Robert Swiecki | 6d01e82 | 2016-03-15 20:21:46 +0100 | [diff] [blame] | 533 | if (fuzz_getState(hfuzz) == _HF_STATE_DYNAMIC_PRE) { |
Jagger | d34417d | 2016-03-16 01:26:54 +0100 | [diff] [blame] | 534 | rnd_index = ATOMIC_POST_INC(hfuzz->lastFileIndex); |
Robert Swiecki | a96d78d | 2016-03-14 16:50:50 +0100 | [diff] [blame] | 535 | if (rnd_index >= hfuzz->fileCnt) { |
Jagger | 33fd952 | 2016-03-15 22:13:57 +0100 | [diff] [blame] | 536 | /* |
| 537 | * The waiting logic (for the DYNAMIC_PRE phase to finish) should be based on cond-waits |
| 538 | * or mutexes, but it'd complicate code too much |
| 539 | */ |
Robert Swiecki | 6d01e82 | 2016-03-15 20:21:46 +0100 | [diff] [blame] | 540 | while (fuzz_getState(hfuzz) == _HF_STATE_DYNAMIC_PRE) { |
| 541 | sleep(1); |
Robert Swiecki | 129afe8 | 2016-03-15 20:03:20 +0100 | [diff] [blame] | 542 | } |
Robert Swiecki | a96d78d | 2016-03-14 16:50:50 +0100 | [diff] [blame] | 543 | } |
| 544 | } |
Anestis Bechtsoudis | 46ea10e | 2015-11-07 18:16:25 +0200 | [diff] [blame] | 545 | |
Jagger | 33fd952 | 2016-03-15 22:13:57 +0100 | [diff] [blame] | 546 | fuzzState_t state = fuzz_getState(hfuzz); |
| 547 | if (state == _HF_STATE_DYNAMIC_MAIN) { |
Robert Swiecki | a08ab1c | 2016-03-14 18:29:21 +0100 | [diff] [blame] | 548 | strncpy(fuzzer.origFileName, "DYNAMIC", PATH_MAX); |
| 549 | } else { |
| 550 | strncpy(fuzzer.origFileName, files_basename(hfuzz->files[rnd_index]), PATH_MAX); |
| 551 | } |
Robert Swiecki | 6d01e82 | 2016-03-15 20:21:46 +0100 | [diff] [blame] | 552 | |
Jagger | 190f0dc | 2015-09-05 16:41:22 +0200 | [diff] [blame] | 553 | fuzz_getFileName(hfuzz, fuzzer.fileName); |
| 554 | |
Robert Swiecki | 6d01e82 | 2016-03-15 20:21:46 +0100 | [diff] [blame] | 555 | if (state == _HF_STATE_DYNAMIC_MAIN) { |
Robert Swiecki | a96d78d | 2016-03-14 16:50:50 +0100 | [diff] [blame] | 556 | if (!fuzz_prepareFileDynamically(hfuzz, &fuzzer)) { |
| 557 | exit(EXIT_FAILURE); |
| 558 | } |
Robert Swiecki | 6d01e82 | 2016-03-15 20:21:46 +0100 | [diff] [blame] | 559 | } else if (state == _HF_STATE_DYNAMIC_PRE) { |
Robert Swiecki | 129afe8 | 2016-03-15 20:03:20 +0100 | [diff] [blame] | 560 | fuzzer.flipRate = 0.0f; |
Robert Swiecki | a96d78d | 2016-03-14 16:50:50 +0100 | [diff] [blame] | 561 | if (!fuzz_prepareFile(hfuzz, &fuzzer, rnd_index)) { |
Jagger | 190f0dc | 2015-09-05 16:41:22 +0200 | [diff] [blame] | 562 | exit(EXIT_FAILURE); |
| 563 | } |
| 564 | } else if (hfuzz->externalCommand != NULL) { |
| 565 | if (!fuzz_prepareFileExternally(hfuzz, &fuzzer, rnd_index)) { |
| 566 | exit(EXIT_FAILURE); |
| 567 | } |
| 568 | } else { |
| 569 | if (!fuzz_prepareFile(hfuzz, &fuzzer, rnd_index)) { |
| 570 | exit(EXIT_FAILURE); |
| 571 | } |
| 572 | } |
| 573 | |
Robert Swiecki | 1df61a9 | 2015-10-08 17:26:06 +0200 | [diff] [blame] | 574 | fuzzer.pid = arch_fork(hfuzz); |
Jagger | 190f0dc | 2015-09-05 16:41:22 +0200 | [diff] [blame] | 575 | if (fuzzer.pid == -1) { |
Robert Swiecki | c8c32db | 2015-10-09 18:06:22 +0200 | [diff] [blame] | 576 | PLOG_F("Couldn't fork"); |
Jagger | 190f0dc | 2015-09-05 16:41:22 +0200 | [diff] [blame] | 577 | exit(EXIT_FAILURE); |
| 578 | } |
| 579 | |
| 580 | if (!fuzzer.pid) { |
Robert Swiecki | 1e1b353 | 2016-03-10 18:43:28 +0100 | [diff] [blame] | 581 | if (!fuzz_prepareExecve(hfuzz, fuzzer.fileName)) { |
| 582 | LOG_E("fuzz_prepareExecve() failed"); |
Jagger | bb83e7c | 2016-03-10 04:33:40 +0100 | [diff] [blame] | 583 | exit(EXIT_FAILURE); |
| 584 | } |
Jagger | 190f0dc | 2015-09-05 16:41:22 +0200 | [diff] [blame] | 585 | if (!arch_launchChild(hfuzz, fuzzer.fileName)) { |
Jagger | 4e10da3 | 2016-03-10 23:13:50 +0100 | [diff] [blame] | 586 | LOG_E("Error launching child process"); |
Jagger | 190f0dc | 2015-09-05 16:41:22 +0200 | [diff] [blame] | 587 | exit(EXIT_FAILURE); |
| 588 | } |
| 589 | } |
| 590 | |
Robert Swiecki | c8c32db | 2015-10-09 18:06:22 +0200 | [diff] [blame] | 591 | LOG_D("Launched new process, pid: %d, (concurrency: %zd)", fuzzer.pid, hfuzz->threadsMax); |
Jagger | 190f0dc | 2015-09-05 16:41:22 +0200 | [diff] [blame] | 592 | |
| 593 | arch_reapChild(hfuzz, &fuzzer); |
| 594 | unlink(fuzzer.fileName); |
| 595 | |
| 596 | if (hfuzz->dynFileMethod != _HF_DYNFILE_NONE) { |
Anestis Bechtsoudis | be0ac7b | 2015-12-26 15:38:47 +0200 | [diff] [blame] | 597 | fuzz_perfFeedback(hfuzz, &fuzzer); |
| 598 | } else if (hfuzz->useSanCov) { |
| 599 | fuzz_sanCovFeedback(hfuzz, &fuzzer); |
Jagger | 190f0dc | 2015-09-05 16:41:22 +0200 | [diff] [blame] | 600 | } |
| 601 | |
Anestis Bechtsoudis | c45db7f | 2015-11-30 16:44:58 +0200 | [diff] [blame] | 602 | if (hfuzz->useVerifier && (fuzzer.crashFileName[0] != 0) && fuzzer.backtrace) { |
Anestis Bechtsoudis | 3085f22 | 2015-09-27 18:35:26 +0300 | [diff] [blame] | 603 | if (!fuzz_runVerifier(hfuzz, &fuzzer)) { |
Anestis Bechtsoudis | 0cde66f | 2015-10-11 19:37:11 -0700 | [diff] [blame] | 604 | LOG_I("Failed to verify %s", fuzzer.crashFileName); |
Anestis Bechtsoudis | 3085f22 | 2015-09-27 18:35:26 +0300 | [diff] [blame] | 605 | } |
Anestis Bechtsoudis | 5c86ebc | 2015-09-27 18:06:43 +0300 | [diff] [blame] | 606 | } |
| 607 | |
Jagger | 190f0dc | 2015-09-05 16:41:22 +0200 | [diff] [blame] | 608 | report_Report(hfuzz, fuzzer.report); |
Robert Swiecki | 05354ca | 2016-03-15 19:10:23 +0100 | [diff] [blame] | 609 | |
Jagger | d34417d | 2016-03-16 01:26:54 +0100 | [diff] [blame] | 610 | if (state == _HF_STATE_DYNAMIC_PRE && ATOMIC_PRE_INC(hfuzz->doneFileIndex) >= hfuzz->fileCnt) { |
Robert Swiecki | 6d01e82 | 2016-03-15 20:21:46 +0100 | [diff] [blame] | 611 | fuzz_setState(hfuzz, _HF_STATE_DYNAMIC_MAIN); |
Robert Swiecki | 05354ca | 2016-03-15 19:10:23 +0100 | [diff] [blame] | 612 | } |
Jagger | 190f0dc | 2015-09-05 16:41:22 +0200 | [diff] [blame] | 613 | } |
| 614 | |
robert.swiecki@gmail.com | c844314 | 2015-02-13 13:46:40 +0000 | [diff] [blame] | 615 | static void *fuzz_threadNew(void *arg) |
robert.swiecki | 3bb518c | 2010-10-14 00:48:24 +0000 | [diff] [blame] | 616 | { |
robert.swiecki@gmail.com | 882900b | 2015-02-11 13:56:22 +0000 | [diff] [blame] | 617 | honggfuzz_t *hfuzz = (honggfuzz_t *) arg; |
Anestis Bechtsoudis | 02b99be | 2015-12-27 11:53:01 +0200 | [diff] [blame] | 618 | |
Robert Swiecki | a96d78d | 2016-03-14 16:50:50 +0100 | [diff] [blame] | 619 | for (;;) { |
Anestis Bechtsoudis | 46ea10e | 2015-11-07 18:16:25 +0200 | [diff] [blame] | 620 | /* Check if dry run mode with verifier enabled */ |
Robert Swiecki | a96d78d | 2016-03-14 16:50:50 +0100 | [diff] [blame] | 621 | if (hfuzz->origFlipRate == 0.0L && hfuzz->useVerifier) { |
Jagger | d34417d | 2016-03-16 01:26:54 +0100 | [diff] [blame] | 622 | if (ATOMIC_POST_INC(hfuzz->mutationsCnt) >= hfuzz->fileCnt) { |
| 623 | ATOMIC_POST_INC(hfuzz->threadsFinished); |
Anestis Bechtsoudis | 46ea10e | 2015-11-07 18:16:25 +0200 | [diff] [blame] | 624 | // All files checked, weak-up the main process |
| 625 | pthread_kill(fuzz_mainThread, SIGALRM); |
| 626 | return NULL; |
| 627 | } |
| 628 | } |
| 629 | /* Check for max iterations limit if set */ |
Jagger | d34417d | 2016-03-16 01:26:54 +0100 | [diff] [blame] | 630 | else if ((ATOMIC_POST_INC(hfuzz->mutationsCnt) >= hfuzz->mutationsMax) |
Anestis Bechtsoudis | 46ea10e | 2015-11-07 18:16:25 +0200 | [diff] [blame] | 631 | && hfuzz->mutationsMax) { |
Jagger | d34417d | 2016-03-16 01:26:54 +0100 | [diff] [blame] | 632 | ATOMIC_POST_INC(hfuzz->threadsFinished); |
Robert Swiecki | 81c6a0d | 2015-09-08 15:43:20 +0200 | [diff] [blame] | 633 | // Wake-up the main process |
Jagger | 6113c43 | 2015-09-24 05:00:28 +0200 | [diff] [blame] | 634 | pthread_kill(fuzz_mainThread, SIGALRM); |
Jagger | ea39a8f | 2015-09-05 00:57:22 +0200 | [diff] [blame] | 635 | return NULL; |
| 636 | } |
robert.swiecki | 3bb518c | 2010-10-14 00:48:24 +0000 | [diff] [blame] | 637 | |
Jagger | 190f0dc | 2015-09-05 16:41:22 +0200 | [diff] [blame] | 638 | fuzz_fuzzLoop(hfuzz); |
robert.swiecki@gmail.com | d4dd4df | 2015-02-18 00:50:12 +0000 | [diff] [blame] | 639 | } |
robert.swiecki@gmail.com | 882900b | 2015-02-11 13:56:22 +0000 | [diff] [blame] | 640 | } |
| 641 | |
robert.swiecki@gmail.com | c844314 | 2015-02-13 13:46:40 +0000 | [diff] [blame] | 642 | static void fuzz_runThread(honggfuzz_t * hfuzz, void *(*thread) (void *)) |
| 643 | { |
robert.swiecki@gmail.com | c844314 | 2015-02-13 13:46:40 +0000 | [diff] [blame] | 644 | pthread_attr_t attr; |
robert.swiecki@gmail.com | c844314 | 2015-02-13 13:46:40 +0000 | [diff] [blame] | 645 | |
robert.swiecki@gmail.com | 6f5c239 | 2015-02-16 18:13:09 +0000 | [diff] [blame] | 646 | pthread_attr_init(&attr); |
robert.swiecki@gmail.com | c844314 | 2015-02-13 13:46:40 +0000 | [diff] [blame] | 647 | pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); |
robert.swiecki@gmail.com | 441089a | 2015-02-23 13:14:07 +0000 | [diff] [blame] | 648 | pthread_attr_setstacksize(&attr, _HF_PTHREAD_STACKSIZE); |
robert.swiecki@gmail.com | 011981f | 2015-02-17 19:06:44 +0000 | [diff] [blame] | 649 | pthread_attr_setguardsize(&attr, (size_t) sysconf(_SC_PAGESIZE)); |
robert.swiecki@gmail.com | c844314 | 2015-02-13 13:46:40 +0000 | [diff] [blame] | 650 | |
robert.swiecki@gmail.com | 01b6dd4 | 2015-02-16 18:11:28 +0000 | [diff] [blame] | 651 | pthread_t t; |
robert.swiecki@gmail.com | c844314 | 2015-02-13 13:46:40 +0000 | [diff] [blame] | 652 | if (pthread_create(&t, &attr, thread, (void *)hfuzz) < 0) { |
Robert Swiecki | c8c32db | 2015-10-09 18:06:22 +0200 | [diff] [blame] | 653 | PLOG_F("Couldn't create a new thread"); |
robert.swiecki@gmail.com | c844314 | 2015-02-13 13:46:40 +0000 | [diff] [blame] | 654 | } |
| 655 | |
| 656 | return; |
| 657 | } |
| 658 | |
Jagger | 08816fd | 2016-03-11 01:32:38 +0100 | [diff] [blame] | 659 | void fuzz_threads(honggfuzz_t * hfuzz) |
robert.swiecki | 3bb518c | 2010-10-14 00:48:24 +0000 | [diff] [blame] | 660 | { |
Jagger | 6113c43 | 2015-09-24 05:00:28 +0200 | [diff] [blame] | 661 | fuzz_mainThread = pthread_self(); |
| 662 | |
robert.swiecki@gmail.com | 956276a | 2015-04-16 16:51:52 +0000 | [diff] [blame] | 663 | if (!arch_archInit(hfuzz)) { |
Robert Swiecki | c8c32db | 2015-10-09 18:06:22 +0200 | [diff] [blame] | 664 | LOG_F("Couldn't prepare arch for fuzzing"); |
robert.swiecki@gmail.com | ef829fa | 2011-06-22 13:51:57 +0000 | [diff] [blame] | 665 | } |
Jagger | 0026560 | 2016-03-10 02:36:27 +0100 | [diff] [blame] | 666 | if (!sancov_Init(hfuzz)) { |
| 667 | LOG_F("Couldn't prepare sancov options"); |
| 668 | } |
robert.swiecki@gmail.com | ef829fa | 2011-06-22 13:51:57 +0000 | [diff] [blame] | 669 | |
Robert Swiecki | a96d78d | 2016-03-14 16:50:50 +0100 | [diff] [blame] | 670 | if (hfuzz->useSanCov || hfuzz->dynFileMethod != _HF_DYNFILE_NONE) { |
Jagger | ebe1929 | 2016-03-17 00:11:44 +0100 | [diff] [blame] | 671 | fuzz_setState(hfuzz, _HF_STATE_DYNAMIC_PRE); |
Robert Swiecki | a96d78d | 2016-03-14 16:50:50 +0100 | [diff] [blame] | 672 | } else { |
Jagger | ebe1929 | 2016-03-17 00:11:44 +0100 | [diff] [blame] | 673 | fuzz_setState(hfuzz, _HF_STATE_STATIC); |
Robert Swiecki | a96d78d | 2016-03-14 16:50:50 +0100 | [diff] [blame] | 674 | } |
| 675 | |
Jagger | ea39a8f | 2015-09-05 00:57:22 +0200 | [diff] [blame] | 676 | for (size_t i = 0; i < hfuzz->threadsMax; i++) { |
robert.swiecki@gmail.com | c844314 | 2015-02-13 13:46:40 +0000 | [diff] [blame] | 677 | fuzz_runThread(hfuzz, fuzz_threadNew); |
robert.swiecki | 3bb518c | 2010-10-14 00:48:24 +0000 | [diff] [blame] | 678 | } |
robert.swiecki | 3bb518c | 2010-10-14 00:48:24 +0000 | [diff] [blame] | 679 | } |