diff options
| author | Andrey Konovalov <andreyknvl@google.com> | 2017-05-18 14:54:02 +0200 |
|---|---|---|
| committer | Andrey Konovalov <andreyknvl@google.com> | 2017-06-12 19:48:23 +0200 |
| commit | 10c9064bfc4890e5895057021280a0558131e3eb (patch) | |
| tree | d651d4ecf24acbdad5bfb26e95cd943389d4e091 /executor | |
| parent | acae98dc5463f8aaa13013aab1aa80509d800fb7 (diff) | |
csource: only handle SIGSEGV when necessary
Diffstat (limited to 'executor')
| -rw-r--r-- | executor/common.h | 29 | ||||
| -rw-r--r-- | executor/common_kvm_amd64.h | 9 |
2 files changed, 29 insertions, 9 deletions
diff --git a/executor/common.h b/executor/common.h index 5041aaf7b..032365471 100644 --- a/executor/common.h +++ b/executor/common.h @@ -132,6 +132,7 @@ void debug(const char* msg, ...) fflush(stdout); } +#if defined(SYZ_EXECUTOR) || defined(SYZ_HANDLE_SEGV) __thread int skip_segv; __thread jmp_buf segv_env; @@ -175,6 +176,16 @@ static void install_segv_handler() sigaction(SIGBUS, &sa, NULL); } +#define NONFAILING(...) \ + { \ + __atomic_fetch_add(&skip_segv, 1, __ATOMIC_SEQ_CST); \ + if (_setjmp(segv_env) == 0) { \ + __VA_ARGS__; \ + } \ + __atomic_fetch_sub(&skip_segv, 1, __ATOMIC_SEQ_CST); \ + } +#endif + #if defined(SYZ_EXECUTOR) || defined(SYZ_USE_TMP_DIR) static void use_temporary_dir() { @@ -189,15 +200,6 @@ static void use_temporary_dir() } #endif -#define NONFAILING(...) \ - { \ - __atomic_fetch_add(&skip_segv, 1, __ATOMIC_SEQ_CST); \ - if (_setjmp(segv_env) == 0) { \ - __VA_ARGS__; \ - } \ - __atomic_fetch_sub(&skip_segv, 1, __ATOMIC_SEQ_CST); \ - } - #define BITMASK_LEN(type, bf_len) (type)((1ull << (bf_len)) - 1) #define BITMASK_LEN_OFF(type, bf_off, bf_len) (type)(BITMASK_LEN(type, (bf_len)) << (bf_off)) @@ -469,8 +471,13 @@ static uintptr_t syz_extract_tcp_res(uintptr_t a0, uintptr_t a1, uintptr_t a2) } struct tcp_resources* res = (struct tcp_resources*)a0; +#if defined(SYZ_EXECUTOR) || defined(SYZ_HANDLE_SEGV) NONFAILING(res->seq = htonl((ntohl(tcphdr->seq) + (uint32_t)a1))); NONFAILING(res->ack = htonl((ntohl(tcphdr->ack_seq) + (uint32_t)a2))); +#else + res->seq = htonl((ntohl(tcphdr->seq) + (uint32_t)a1)); + res->ack = htonl((ntohl(tcphdr->ack_seq) + (uint32_t)a2)); +#endif debug("extracted seq: %08x\n", res->seq); debug("extracted ack: %08x\n", res->ack); @@ -492,7 +499,11 @@ static uintptr_t syz_open_dev(uintptr_t a0, uintptr_t a1, uintptr_t a2) // syz_open_dev(dev strconst, id intptr, flags flags[open_flags]) fd char buf[1024]; char* hash; +#if defined(SYZ_EXECUTOR) || defined(SYZ_HANDLE_SEGV) NONFAILING(strncpy(buf, (char*)a0, sizeof(buf))); +#else + strncpy(buf, (char*)a0, sizeof(buf)); +#endif buf[sizeof(buf) - 1] = 0; while ((hash = strchr(buf, '#'))) { *hash = '0' + (char)(a1 % 10); // 10 devices should be enough for everyone. diff --git a/executor/common_kvm_amd64.h b/executor/common_kvm_amd64.h index dd37733ed..e4753223e 100644 --- a/executor/common_kvm_amd64.h +++ b/executor/common_kvm_amd64.h @@ -7,6 +7,15 @@ // See Intel Software Developer’s Manual Volume 3: System Programming Guide // for details on what happens here. +// We could put each NONFAILING use in this file under ifdef, +// but I don't think it's worth it. +#ifndef NONFAILING +#define NONFAILING(x) \ + { \ + x; \ + } +#endif + #include "kvm.S.h" #include "kvm.h" |
