aboutsummaryrefslogtreecommitdiffstats
path: root/executor
diff options
context:
space:
mode:
authorAndrey Konovalov <andreyknvl@google.com>2017-05-17 20:20:23 +0200
committerAndrey Konovalov <andreyknvl@google.com>2017-06-12 19:48:23 +0200
commit7d7c9c550f5d83c652719be31a350a9f8f306b3c (patch)
treeab581a0ab6f18a9fbab1643e5438a332b73d957c /executor
parent1ab96df8855796901f133c1afab0f7384fc92eea (diff)
csource: add EnableTun option
Diffstat (limited to 'executor')
-rw-r--r--executor/common.h66
-rw-r--r--executor/executor.cc1
2 files changed, 36 insertions, 31 deletions
diff --git a/executor/common.h b/executor/common.h
index 55ed7a73a..d7b403554 100644
--- a/executor/common.h
+++ b/executor/common.h
@@ -189,10 +189,6 @@ static void install_segv_handler()
*(type*)(addr) = new_val; \
}
-#if defined(__NR_syz_emit_ethernet) || defined(__NR_syz_extract_tcp_res)
-#define SYZ_TUN_ENABLE
-#endif
-
#ifdef SYZ_TUN_ENABLE
static void vsnprintf_check(char* str, size_t size, const char* format, va_list args)
{
@@ -307,6 +303,17 @@ static void setup_tun(uint64_t pid, bool enable_tun)
initialize_tun(pid);
}
+int read_tun(char* data, int size)
+{
+ int rv = read(tunfd, data, size);
+ if (rv < 0) {
+ if (errno == EAGAIN)
+ return -1;
+ fail("tun: read failed with %d, errno: %d", rv, errno);
+ }
+ return rv;
+}
+
void debug_dump_data(const char* data, int length)
{
int i;
@@ -320,7 +327,7 @@ void debug_dump_data(const char* data, int length)
}
#endif // SYZ_TUN_ENABLE
-#if defined(__NR_syz_emit_ethernet) || defined(__NR_syz_test)
+#if (defined(__NR_syz_emit_ethernet) && defined(SYZ_TUN_ENABLE)) || defined(__NR_syz_test)
struct csum_inet {
uint32_t acc;
};
@@ -352,7 +359,7 @@ uint16_t csum_inet_digest(struct csum_inet* csum)
}
#endif
-#ifdef __NR_syz_emit_ethernet
+#if defined(__NR_syz_emit_ethernet) && defined(SYZ_TUN_ENABLE)
static uintptr_t syz_emit_ethernet(uintptr_t a0, uintptr_t a1)
{
// syz_emit_ethernet(len len[packet], packet ptr[in, eth_packet])
@@ -367,7 +374,16 @@ static uintptr_t syz_emit_ethernet(uintptr_t a0, uintptr_t a1)
}
#endif
-#ifdef __NR_syz_extract_tcp_res
+#if (defined(SYZ_EXECUTOR) || defined(SYZ_REPEAT)) && defined(SYZ_TUN_ENABLE)
+void flush_tun()
+{
+ char data[SYZ_TUN_MAX_PACKET_SIZE];
+ while (read_tun(&data[0], sizeof(data)) != -1)
+ ;
+}
+#endif
+
+#if defined(__NR_syz_extract_tcp_res) && defined(SYZ_TUN_ENABLE)
// Can't include <linux/ipv6.h>, since it causes
// conflicts due to some structs redefinition.
struct ipv6hdr {
@@ -388,17 +404,6 @@ struct tcp_resources {
int32_t ack;
};
-int read_tun(char* data, int size)
-{
- int rv = read(tunfd, data, size);
- if (rv < 0) {
- if (errno == EAGAIN)
- return -1;
- fail("tun: read failed with %d, errno: %d", rv, errno);
- }
- return rv;
-}
-
static uintptr_t syz_extract_tcp_res(uintptr_t a0, uintptr_t a1, uintptr_t a2)
{
// syz_extract_tcp_res(res ptr[out, tcp_resources], seq_inc int32, ack_inc int32)
@@ -451,15 +456,6 @@ static uintptr_t syz_extract_tcp_res(uintptr_t a0, uintptr_t a1, uintptr_t a2)
}
#endif
-#if defined(SYZ_TUN_ENABLE) && (defined(SYZ_EXECUTOR) || defined(SYZ_REPEAT))
-void flush_tun()
-{
- char data[SYZ_TUN_MAX_PACKET_SIZE];
- while (read_tun(&data[0], sizeof(data)) != -1)
- ;
-}
-#endif
-
#ifdef __NR_syz_open_dev
static uintptr_t syz_open_dev(uintptr_t a0, uintptr_t a1, uintptr_t a2)
{
@@ -597,14 +593,22 @@ static uintptr_t execute_syscall(int nr, uintptr_t a0, uintptr_t a1, uintptr_t a
case __NR_syz_fuseblk_mount:
return syz_fuseblk_mount(a0, a1, a2, a3, a4, a5, a6, a7);
#endif
-#ifdef __NR_syz_emit_ethernet
+#if defined(__NR_syz_emit_ethernet)
case __NR_syz_emit_ethernet:
+#if defined(SYZ_TUN_ENABLE)
return syz_emit_ethernet(a0, a1);
-#endif
-#ifdef __NR_syz_extract_tcp_res
+#else
+ return 0;
+#endif // defined(SYZ_TUN_ENABLE)
+#endif // defined(__NR_syz_emit_ethernet)
+#if defined(__NR_syz_extract_tcp_res)
case __NR_syz_extract_tcp_res:
+#if defined(SYZ_TUN_ENABLE)
return syz_extract_tcp_res(a0, a1, a2);
-#endif
+#else
+ return 0;
+#endif // defined(SYZ_TUN_ENABLE)
+#endif // defined(__NR_syz_extract_tcp_res)
#ifdef __NR_syz_kvm_setup_cpu
case __NR_syz_kvm_setup_cpu:
return syz_kvm_setup_cpu(a0, a1, a2, a3, a4, a5, a6, a7);
diff --git a/executor/executor.cc b/executor/executor.cc
index 044410792..800ac932e 100644
--- a/executor/executor.cc
+++ b/executor/executor.cc
@@ -31,6 +31,7 @@
#include "syscalls.h"
#define SYZ_EXECUTOR
+#define SYZ_TUN_ENABLE
#include "common.h"
#define KCOV_INIT_TRACE _IOR('c', 1, unsigned long long)