|
35 | 35 | #include "exec/tb-lookup.h"
|
36 | 36 | #include "exec/log.h"
|
37 | 37 | #include "qemu/main-loop.h"
|
| 38 | +#include "qemu/selfmap.h" |
38 | 39 | #if defined(TARGET_I386) && !defined(CONFIG_USER_ONLY)
|
39 | 40 | #include "hw/i386/apic.h"
|
40 | 41 | #endif
|
@@ -408,57 +409,40 @@ void afl_setup(void) {
|
408 | 409 | }
|
409 | 410 |
|
410 | 411 | if (have_names) {
|
411 |
| - |
412 |
| - FILE *fp; |
413 |
| - char *line = NULL; |
414 |
| - size_t len = 0; |
415 |
| - ssize_t read; |
416 |
| - |
417 |
| - fp = fopen("/proc/self/maps", "r"); |
418 |
| - if (fp == NULL) { |
419 |
| - fprintf(stderr, "[AFL] ERROR: cannot open /proc/self/maps\n"); |
420 |
| - exit(1); |
421 |
| - } |
422 |
| - |
423 |
| - while ((read = getline(&line, &len, fp)) != -1) { |
424 |
| - |
425 |
| - int fields, dev_maj, dev_min, inode; |
426 |
| - uint64_t min, max, offset; |
427 |
| - char flag_r, flag_w, flag_x, flag_p; |
428 |
| - char path[512] = ""; |
| 412 | + GSList *map_info = read_self_maps(); |
| 413 | + for (GSList *s = map_info; s; s = g_slist_next(s)) { |
| 414 | + MapInfo *e = (MapInfo *) s->data; |
429 | 415 |
|
430 |
| - fields = sscanf(line, "%"PRIx64"-%"PRIx64" %c%c%c%c %"PRIx64" %x:%x %d" |
431 |
| - " %512s", &min, &max, &flag_r, &flag_w, &flag_x, |
432 |
| - &flag_p, &offset, &dev_maj, &dev_min, &inode, path); |
| 416 | + if (h2g_valid(e->start)) { |
| 417 | + unsigned long min = e->start; |
| 418 | + unsigned long max = e->end; |
| 419 | + int flags = page_get_flags(h2g(min)); |
433 | 420 |
|
434 |
| - if ((fields < 10) || (fields > 11) || !flag_x || !h2g_valid(min)) |
435 |
| - continue; |
436 |
| - |
437 |
| - int flags = page_get_flags(h2g(min)); |
438 |
| - |
439 |
| - max = h2g_valid(max - 1) ? max : (uintptr_t)AFL_G2H(GUEST_ADDR_MAX) + 1; |
440 |
| - if (page_check_range(h2g(min), max - min, flags) == -1) |
| 421 | + max = h2g_valid(max - 1) ? max : (uintptr_t) AFL_G2H(GUEST_ADDR_MAX) + 1; |
| 422 | + |
| 423 | + if (page_check_range(h2g(min), max - min, flags) == -1) { |
441 | 424 | continue;
|
442 |
| - |
443 |
| - target_ulong gmin = h2g(min); |
444 |
| - target_ulong gmax = h2g(max); |
445 |
| - |
446 |
| - struct vmrange* n = afl_instr_code; |
447 |
| - while (n) { |
448 |
| - if (n->name && strstr(path, n->name)) { |
449 |
| - if (gmin < n->start) n->start = gmin; |
450 |
| - if (gmax > n->end) n->end = gmax; |
451 |
| - break; |
452 | 425 | }
|
453 |
| - n = n->next; |
| 426 | + |
| 427 | + // Now that we have a valid guest address region, compare its |
| 428 | + // name against the names we care about: |
| 429 | + target_ulong gmin = h2g(min); |
| 430 | + target_ulong gmax = h2g(max); |
| 431 | + |
| 432 | + struct vmrange* n = afl_instr_code; |
| 433 | + while (n) { |
| 434 | + if (n->name && strstr(e->path, n->name)) { |
| 435 | + if (gmin < n->start) n->start = gmin; |
| 436 | + if (gmax > n->end) n->end = gmax; |
| 437 | + break; |
| 438 | + } |
| 439 | + n = n->next; |
| 440 | + } |
454 | 441 | }
|
455 |
| - |
456 | 442 | }
|
457 |
| - |
458 |
| - fclose(fp); |
459 |
| - |
| 443 | + free_self_maps(map_info); |
460 | 444 | }
|
461 |
| - |
| 445 | + |
462 | 446 | if (getenv("AFL_DEBUG") && afl_instr_code) {
|
463 | 447 | struct vmrange* n = afl_instr_code;
|
464 | 448 | while (n) {
|
|
0 commit comments