Changeset 1641 for zzuf/trunk
- Timestamp:
- Jan 10, 2007, 6:17:26 PM (16 years ago)
- Location:
- zzuf/trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
zzuf/trunk/doc/zzuf.1
r1640 r1641 3 3 zzuf \- multiple purpose fuzzer 4 4 .SH SYNOPSIS 5 \fBzzuf\fR [\fB\-cdiMnqS\fR] [\fB\-r\fR \fIratio\fR] [\fB\-s\fR \fIseed\fR |\fB\-s\fR \fIstart:stop\fR]5 \fBzzuf\fR [\fB\-cdiMnqS\fR] [\fB\-r\fR \fIratio\fR] [\fB\-s\fR \fIseed\fR|\fB\-s\fR \fIstart:stop\fR] 6 6 .br 7 7 [\fB\-F\fR \fIforks\fR] [\fB\-C\fR \fIcrashes\fR] [\fB\-B\fR \fIbytes\fR] [\fB\-T\fR \fIseconds\fR] 8 8 .br 9 [\fB\- P\fR \fIprotect\fR] [\fB\-R\fR \fIrefuse\fR]9 [\fB\-M\fR \fImegabytes\fR] [\fB\-P\fR \fIprotect\fR] [\fB\-R\fR \fIrefuse\fR] 10 10 .br 11 11 [\fB\-I\fR \fIinclude\fR] [\fB\-E\fR \fIexclude\fR] [\fIPROGRAM\fR [\fIARGS\fR]...] … … 99 99 Instead of displaying the program's standard output, just print the MD5 digest 100 100 of that output. The standard error channel is left untouched. 101 .TP 102 \fB\-M\fR, \fB\-\-max-memory\fR=\fImegabytes\fR 103 Specify the maximum amount of memory, in megabytes, that children are allowed 104 to allocate. This is useful to detect infinite loops that eat up a lot of 105 memory. The value should set reasonably high so as not to interfer with normal 106 program operation. 107 108 \fBZzuf\fR uses the \fBsetrlimit\fR() call to set memory usage limitations and 109 relies on the operating system's ability to enforce such limitations. 101 110 .TP 102 111 \fB\-n\fR, \fB\-\-network\fR … … 228 237 .PP 229 238 \fB zzuf \-c \-s 87423 \-r 0.01 vlc movie.avi\fR 230 \fB zzuf \-c \-s 87423 \-r 0.01 cp movie.avifuzzy\-movie.avi\fR239 \fB zzuf \-c \-s 87423 \-r 0.01 <movie.avi >fuzzy\-movie.avi\fR 231 240 \fB vlc fuzzy\-movie.avi\fR 232 241 .PP … … 241 250 .SH RESTRICTIONS 242 251 .PP 243 Due to \fBzzuf\fR using shared object preloading (\fBLD_PRELOAD\fR on most244 Unix systems, \fBDYLD_INSERT_LIBRARIES\fR on Mac OS X) to run its child252 Due to \fBzzuf\fR using shared object preloading (\fBLD_PRELOAD\fR, 253 \fB_RLD_LIST\fB, \fBDYLD_INSERT_LIBRARIES\fR, etc.) to run its child 245 254 processes, it will fail in the presence of any mechanism that disables 246 255 preloading. For instance setuid root binaries will not be fuzzed when run … … 267 276 descriptor operations is undefined. 268 277 .SH NOTES 269 In order to intercept file and network operations and signal handlers,270 \fBzzuf\fR diverts and reimplements the following functions, which can 271 be private libc symbols, too:278 In order to intercept file and network operations, signal handlers and memory 279 allocations, \fBzzuf\fR diverts and reimplements the following functions, 280 which can be private libc symbols, too: 272 281 .TP 273 282 Unix file descriptor handling: 274 283 \fBopen\fR(), \fBlseek\fR(), \fBread\fR(), \fBaccept\fR(), \fBsocket\fR(), 275 \fB mmap\fR(), \fBmunmap\fR(), \fBclose\fR()284 \fBclose\fR() 276 285 .TP 277 286 Standard IO streams: … … 279 288 \fBfread\fR(), \fBgetc\fR(), \fBfgetc\fR(), \fBfgets\fR(), \fBungetc\fR(), 280 289 \fBfclose\fR() 290 .TP 291 Memory management: 292 \fBmmap\fR(), \fBmunmap\fR(), \fBmalloc\fR(), \fBcalloc\fR(), \fBvalloc\fR(), 293 \fBfree\fR(), \fBmemalign\fR(), \fBposix_memalign\fR(), \fBbrk\fR(), 294 \fBsbrk\fR() 281 295 .TP 282 296 Linux-specific: -
zzuf/trunk/src/libzzuf.c
r1639 r1641 45 45 int _zz_hasdebug = 0; 46 46 int _zz_signal = 0; 47 int _zz_memory = 0; 47 48 int _zz_network = 0; 48 49 … … 84 85 _zz_signal = 1; 85 86 87 tmp = getenv("ZZUF_MEMORY"); 88 if(tmp && *tmp == '1') 89 _zz_memory = 1; 90 86 91 tmp = getenv("ZZUF_NETWORK"); 87 92 if(tmp && *tmp == '1') -
zzuf/trunk/src/libzzuf.h
r1614 r1641 40 40 extern int _zz_hasdebug; 41 41 extern int _zz_signal; 42 extern int _zz_memory; 42 43 extern int _zz_network; 43 44 -
zzuf/trunk/src/load-mem.c
r1639 r1641 23 23 /* Use this to get mmap64() on glibc systems */ 24 24 #define _LARGEFILE64_SOURCE 25 /* Use this to get posix_memalign */ 26 #define _XOPEN_SOURCE 600 25 27 26 28 #if defined HAVE_STDINT_H … … 32 34 #include <string.h> 33 35 #include <dlfcn.h> 34 36 #include <errno.h> 37 #include <signal.h> 38 39 #include <malloc.h> 35 40 #include <unistd.h> 36 41 #include <sys/mman.h> … … 46 51 47 52 /* Library functions that we divert */ 48 static void * (*mmap_orig) (void *start, size_t length, int prot, 49 int flags, int fd, off_t offset); 53 static void * (*calloc_orig) (size_t nmemb, size_t size); 54 static void * (*malloc_orig) (size_t size); 55 static void (*free_orig) (void *ptr); 56 static void * (*valloc_orig) (size_t size); 57 static void * (*memalign_orig) (size_t boundary, size_t size); 58 static int (*posix_memalign_orig) (void **memptr, size_t alignment, 59 size_t size); 60 static void * (*realloc_orig) (void *ptr, size_t size); 61 static int (*brk_orig) (void *end_data_segment); 62 static void * (*sbrk_orig) (intptr_t increment); 63 64 static void * (*mmap_orig) (void *start, size_t length, int prot, 65 int flags, int fd, off_t offset); 66 /* TODO */ 67 /* static void * (*mremap_orig) (void *old_address, size_t old_size, 68 size_t new_size, int flags); */ 50 69 #ifdef HAVE_MMAP64 51 static void * (*mmap64_orig) (void *start, size_t length, int prot,52 int flags, int fd, off64_t offset);53 #endif 54 static int (*munmap_orig) (void *start, size_t length);70 static void * (*mmap64_orig) (void *start, size_t length, int prot, 71 int flags, int fd, off64_t offset); 72 #endif 73 static int (*munmap_orig) (void *start, size_t length); 55 74 #ifdef HAVE_MAP_FD 56 75 static kern_return_t (*map_fd_orig) (int fd, vm_offset_t offset, … … 61 80 void _zz_load_mem(void) 62 81 { 82 LOADSYM(calloc); 83 LOADSYM(malloc); 84 LOADSYM(free); 85 LOADSYM(realloc); 86 LOADSYM(valloc); 87 LOADSYM(memalign); 88 LOADSYM(posix_memalign); 89 LOADSYM(brk); 90 LOADSYM(sbrk); 91 63 92 LOADSYM(mmap); 64 93 #ifdef HAVE_MMAP64 … … 69 98 LOADSYM(map_fd); 70 99 #endif 100 } 101 102 /* 32k of ugly static memory for programs that call us *before* we’re 103 * initialised */ 104 uint64_t dummy_buffer[4096]; 105 106 void *calloc(size_t nmemb, size_t size) 107 { 108 void *ret; 109 if(!_zz_ready) 110 { 111 /* Calloc says we must zero the data */ 112 int i = (nmemb * size + 7) / 8; 113 while(i--) 114 dummy_buffer[i] = 0; 115 return dummy_buffer; 116 } 117 ret = calloc_orig(nmemb, size); 118 if(ret == NULL && _zz_memory && errno == ENOMEM) 119 raise(SIGKILL); 120 return ret; 121 } 122 123 void *malloc(size_t size) 124 { 125 void *ret; 126 if(!_zz_ready) 127 return dummy_buffer; 128 ret = malloc_orig(size); 129 if(ret == NULL && _zz_memory && errno == ENOMEM) 130 raise(SIGKILL); 131 return ret; 132 } 133 134 void free(void *ptr) 135 { 136 if(ptr == dummy_buffer) 137 return; 138 if(!_zz_ready) 139 LOADSYM(free); 140 free_orig(ptr); 141 } 142 143 void *realloc(void *ptr, size_t size) 144 { 145 void *ret; 146 if(ptr == dummy_buffer) 147 return ptr; 148 if(!_zz_ready) 149 LOADSYM(realloc); 150 ret = realloc_orig(ptr, size); 151 if(ret == NULL && _zz_memory && errno == ENOMEM) 152 raise(SIGKILL); 153 return ret; 154 } 155 156 void *valloc(size_t size) 157 { 158 void *ret; 159 if(!_zz_ready) 160 LOADSYM(valloc); 161 ret = valloc_orig(size); 162 if(ret == NULL && _zz_memory && errno == ENOMEM) 163 raise(SIGKILL); 164 return ret; 165 } 166 167 void *memalign(size_t boundary, size_t size) 168 { 169 void *ret; 170 if(!_zz_ready) 171 LOADSYM(memalign); 172 ret = memalign_orig(boundary, size); 173 if(ret == NULL && _zz_memory && errno == ENOMEM) 174 raise(SIGKILL); 175 return ret; 176 } 177 178 int posix_memalign(void **memptr, size_t alignment, size_t size) 179 { 180 int ret; 181 if(!_zz_ready) 182 LOADSYM(posix_memalign); 183 ret = posix_memalign_orig(memptr, alignment, size); 184 if(ret == ENOMEM && _zz_memory) 185 raise(SIGKILL); 186 return ret; 187 } 188 189 int brk(void *end_data_segment) 190 { 191 int ret; 192 if(!_zz_ready) 193 LOADSYM(brk); 194 ret = brk_orig(end_data_segment); 195 if(ret == -1 && _zz_memory && errno == ENOMEM) 196 raise(SIGKILL); 197 return ret; 198 } 199 200 void *sbrk(intptr_t increment) 201 { 202 void *ret; 203 if(!_zz_ready) 204 LOADSYM(sbrk); 205 ret = sbrk_orig(increment); 206 if(ret == (void *)-1 && _zz_memory && errno == ENOMEM) 207 raise(SIGKILL); 208 return ret; 71 209 } 72 210 -
zzuf/trunk/src/zzuf.c
r1640 r1641 37 37 #include <time.h> 38 38 #include <sys/wait.h> 39 #include <sys/time.h> 40 #include <sys/resource.h> 39 41 40 42 #include "libzzuf.h" … … 81 83 static int md5 = 0; 82 84 static int checkexit = 0; 85 static int maxmem = -1; 83 86 static double maxtime = -1.0; 84 87 … … 120 123 { "include", 1, NULL, 'I' }, 121 124 { "md5", 0, NULL, 'm' }, 125 { "max-memory", 1, NULL, 'M' }, 122 126 { "network", 0, NULL, 'n' }, 123 127 { "protect", 1, NULL, 'P' }, … … 132 136 { "version", 0, NULL, 'v' }, 133 137 }; 134 int c = getopt_long(argc, argv, "B:cC:dE:F:iI:m nP:qr:R:s:ST:xhv",138 int c = getopt_long(argc, argv, "B:cC:dE:F:iI:mM:nP:qr:R:s:ST:xhv", 135 139 long_options, &option_index); 136 140 # else 137 141 # define MOREINFO "Try `%s -h' for more information.\n" 138 int c = getopt(argc, argv, "B:cC:dE:F:iI:m nP:qr:R:s:ST:xhv");142 int c = getopt(argc, argv, "B:cC:dE:F:iI:mM:nP:qr:R:s:ST:xhv"); 139 143 # endif 140 144 if(c == -1) … … 181 185 case 'm': /* --md5 */ 182 186 md5 = 1; 187 break; 188 case 'M': /* --max-memory */ 189 setenv("ZZUF_MEMORY", "1", 1); 190 maxmem = atoi(optarg); 183 191 break; 184 192 case 'n': /* --network */ … … 425 433 case 0: 426 434 /* We’re the child */ 435 if(maxmem >= 0) 436 { 437 struct rlimit rlim; 438 rlim.rlim_cur = maxmem * 1000000; 439 rlim.rlim_max = maxmem * 1000000; 440 setrlimit(RLIMIT_AS, &rlim); 441 } 442 427 443 for(j = 0; j < 3; j++) 428 444 { … … 529 545 else if(WIFSIGNALED(status)) 530 546 { 531 fprintf(stdout, "zzuf[seed=%i]: signal %i\n", 532 child_list[i].seed, WTERMSIG(status)); 547 fprintf(stdout, "zzuf[seed=%i]: signal %i%s\n", 548 child_list[i].seed, WTERMSIG(status), 549 (WTERMSIG(status) == SIGKILL && maxmem >= 0) ? 550 " (memory exceeded?)" : ""); 533 551 crashes++; 534 552 } … … 667 685 printf("Usage: zzuf [-cdimnqSx] [-r ratio] [-s seed | -s start:stop]\n"); 668 686 printf(" [-F forks] [-C crashes] [-B bytes] [-T seconds]\n"); 669 printf(" [- P protect] [-R refuse]\n");687 printf(" [-M bytes] [-P protect] [-R refuse]\n"); 670 688 printf(" [-I include] [-E exclude] [PROGRAM [ARGS]...]\n"); 671 689 # ifdef HAVE_GETOPT_LONG … … 689 707 printf(" -I, --include <regex> only fuzz files matching <regex>\n"); 690 708 printf(" -m, --md5 compute the output's MD5 hash\n"); 709 printf(" -M, --max-memory <n> maximum child virtual memory size in MB\n"); 691 710 printf(" -n, --network fuzz network input\n"); 692 711 printf(" -P, --protect <list> protect bytes and characters in <list>\n"); … … 711 730 printf(" -I <regex> only fuzz files matching <regex>\n"); 712 731 printf(" -m compute the output's MD5 hash\n"); 732 printf(" -M maximum child virtual memory size in MB\n"); 713 733 printf(" -n fuzz network input\n"); 714 734 printf(" -P <list> protect bytes and characters in <list>\n");
Note: See TracChangeset
for help on using the changeset viewer.