[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [RFC PATCH v2 14/17] fuzz: Add forking support to the fuzze
From: |
Oleinik, Alexander |
Subject: |
[Qemu-devel] [RFC PATCH v2 14/17] fuzz: Add forking support to the fuzzer |
Date: |
Mon, 5 Aug 2019 07:11:15 +0000 |
Forking is a simple way of ensuring that state doesn't leak between
runs. This patch depends on a modification to libfuzzer:
https://reviews.llvm.org/D65672
Signed-off-by: Alexander Oleinik <address@hidden>
---
tests/fuzz/fuzzer_hooks.c | 62 +++++++++++++++++++++++++++++++++++++++
tests/fuzz/fuzzer_hooks.h | 21 +++++++++++++
2 files changed, 83 insertions(+)
create mode 100644 tests/fuzz/fuzzer_hooks.c
create mode 100644 tests/fuzz/fuzzer_hooks.h
diff --git a/tests/fuzz/fuzzer_hooks.c b/tests/fuzz/fuzzer_hooks.c
new file mode 100644
index 0000000000..87c94ef65f
--- /dev/null
+++ b/tests/fuzz/fuzzer_hooks.c
@@ -0,0 +1,62 @@
+#include "qemu/osdep.h"
+#include "qemu/units.h"
+#include "qapi/error.h"
+#include "qemu-common.h"
+#include "fuzzer_hooks.h"
+
+#include <dlfcn.h>
+#include <elf.h>
+
+
+
+void *counter_shm;
+size_t feature_shm_len;
+uintptr_t feature_shm;
+size_t offset;
+
+typedef struct CoverageRegion {
+ uint8_t *start;
+ size_t length;
+ bool store; /* Set this if it needs to be copied to the forked process */
+} CoverageRegion;
+
+CoverageRegion regions[10];
+int region_index;
+
+
+void counter_shm_init(void)
+{
+ LLVMFuzzerIterateFeatureRegions(&measure_shm_size);
+ feature_shm = (uintptr_t)mmap(NULL, feature_shm_len,
+ PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0);
+}
+
+void counter_shm_store(void)
+{
+ offset = 0;
+ LLVMFuzzerIterateFeatureRegions(&feature_store);
+}
+
+void counter_shm_load(void)
+{
+ offset = 0;
+ LLVMFuzzerIterateFeatureRegions(&feature_load);
+}
+
+void feature_load(void *start, size_t len)
+{
+ memcpy(start, (void *)(feature_shm + offset), len);
+ offset += len;
+}
+
+void feature_store(void *start, size_t len)
+{
+ memcpy((void *)(feature_shm + offset), start, len);
+ offset += len;
+}
+
+void measure_shm_size(void *start, size_t len)
+{
+ feature_shm_len += len;
+}
+
diff --git a/tests/fuzz/fuzzer_hooks.h b/tests/fuzz/fuzzer_hooks.h
new file mode 100644
index 0000000000..2f411193dd
--- /dev/null
+++ b/tests/fuzz/fuzzer_hooks.h
@@ -0,0 +1,21 @@
+#ifndef FUZZER_HOOKS_H
+#define FUZZER_HOOKS_H
+
+
+/* NOTE: Pending https://reviews.llvm.org/D65672
+ * Alternatively, a similar functionality can be added fairly straightforwardly
+ * with AFL deferred fork mode, albeit requiring a different fuzzer and
compiler
+ * https://github.com/mirrorer/afl/blob/master/llvm_mode/README.llvm#L82
+ */
+extern void LLVMFuzzerIterateFeatureRegions(void (*CB)(void *, size_t));
+
+void measure_shm_size(void *start, size_t len);
+
+void counter_shm_init(void);
+void counter_shm_store(void);
+void counter_shm_load(void);
+void feature_load(void *start, size_t len);
+void feature_store(void *start, size_t len);
+
+#endif
+
--
2.20.1
- Re: [Qemu-devel] [RFC PATCH v2 07/17] fuzz: Add ramfile qemu-file type, (continued)
- [Qemu-devel] [RFC PATCH v2 09/17] fuzz: hardcode needed objects into i386 target, Oleinik, Alexander, 2019/08/05
- [Qemu-devel] [RFC PATCH v2 08/17] fuzz: Export the qemu_savevm_live_state function, Oleinik, Alexander, 2019/08/05
- [Qemu-devel] [RFC PATCH v2 10/17] fuzz: qtest client directly interacts with server, Oleinik, Alexander, 2019/08/05
- [Qemu-devel] [RFC PATCH v2 11/17] fuzz: Move useful qos functions to separate object, Oleinik, Alexander, 2019/08/05
- [Qemu-devel] [RFC PATCH v2 14/17] fuzz: Add forking support to the fuzzer,
Oleinik, Alexander <=
- [Qemu-devel] [RFC PATCH v2 13/17] fuzz: Add libqos support to the fuzzer, Oleinik, Alexander, 2019/08/05
- [Qemu-devel] [RFC PATCH v2 17/17] fuzz: Add fuzz accelerator type, Oleinik, Alexander, 2019/08/05
- [Qemu-devel] [RFC PATCH v2 12/17] fuzz: Add fuzzer skeleton, Oleinik, Alexander, 2019/08/05
- [Qemu-devel] [RFC PATCH v2 15/17] fuzz: Add general qtest fuzz-target, Oleinik, Alexander, 2019/08/05
- [Qemu-devel] [RFC PATCH v2 16/17] fuzz: Add virtio-net fuzz targets, Oleinik, Alexander, 2019/08/05
- Re: [Qemu-devel] [RFC PATCH v2 00/17] Add virtual device fuzzing support, no-reply, 2019/08/05