Skip to contentSkip to conversation

Fuzzing targets for oss-fuzz

PATCH In review Wei Liu 4 participants 21 messages Dec 12, 2016 – Dec 16, 2016

lore
Share & tools
lore

Wei Liu

author
#0 lore raw

v3 cover Fuzzing targets for oss-fuzz

Hi all

This series adds two fuzzing targets to run in Google's oss-fuzz infrastructure.

There will be some other patches on the oss-fuzz side. Their recommendation is to have all the fuzzing targets committed in our tree so that they can be kept up to date.

Please see the patch to add README for details on how this works.

Wei.

Cc Andrew Cooper <[email protected]>
Cc George Dunlap <[email protected]>
Cc Ian Jackson <[email protected]>
Cc Jan Beulich <[email protected]>
Cc Konrad Rzeszutek Wilk <[email protected]>
Cc Stefano Stabellini <[email protected]>
Cc Tim Deegan <[email protected]>
Cc Wei Liu <[email protected]>

Wei Liu (7):
tools/fuzz: introduce libelf target x86emul/test: factor out emul_test_make_stack_executable x86emul/test: factor out emul_test_{read_cr,cpuid} x86emul/test: factor out emul_test_get_fpu tools/fuzz: introduce x86 instruction emulator target
tools: hook up fuzz directory
tools/fuzz: add README

 .gitignore                                         |   1 +
 tools/Makefile                                     |   1 +
 tools/fuzz/Makefile                                |  11 ++
 tools/fuzz/README                                  |  39 +++++
 tools/fuzz/libelf/Makefile                         |  31 ++++
 tools/fuzz/libelf/libelf-fuzzer.c                  |  32 ++++
 tools/fuzz/x86_instruction_emulator/Makefile       |  31 ++++
 .../x86-insn-emulator-fuzzer.c                     | 195 +++++++++++++++++++++
 tools/tests/x86_emulator/test_x86_emulator.c       | 142 +--------------
 tools/tests/x86_emulator/x86_emulate.c             |  84 +++++++++
 tools/tests/x86_emulator/x86_emulate.h             |  81 +++++++++
 xen/common/libelf/libelf-private.h                 |   2 +
 12 files changed, 513 insertions(+), 137 deletions(-)
 create mode 100644 tools/fuzz/Makefile
 create mode 100644 tools/fuzz/README
 create mode 100644 tools/fuzz/libelf/Makefile
 create mode 100644 tools/fuzz/libelf/libelf-fuzzer.c
 create mode 100644 tools/fuzz/x86_instruction_emulator/Makefile
 create mode 100644 tools/fuzz/x86_instruction_emulator/x86-insn-emulator-fuzzer.c
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
author
#1 lore raw

PATCH v3 1/7 tools/fuzz: introduce libelf target

Source code and Makefile to fuzz libelf in Google's oss-fuzz infrastructure.

Introduce FUZZ_NO_LIBXC in libelf-private.h. That macro will be set when compiling libelf fuzzer target because libxc is not required in libelf fuzzing.

---
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Tim Deegan <[email protected]>
Cc: Wei Liu <[email protected]>

---
 tools/fuzz/libelf/Makefile         | 31 +++++++++++++++++++++++++++++++
 tools/fuzz/libelf/libelf-fuzzer.c  | 32 ++++++++++++++++++++++++++++++++
 xen/common/libelf/libelf-private.h |  2 ++
 3 files changed, 65 insertions(+)
 create mode 100644 tools/fuzz/libelf/Makefile
 create mode 100644 tools/fuzz/libelf/libelf-fuzzer.c
tools/fuzz/libelf/Makefile new file +31 -0
new file mode 100644
index 0000000..0e9d40a
@@ -0,0 +1,31 @@
+XEN_ROOT = $(CURDIR)/../../..
+include $(XEN_ROOT)/tools/Rules.mk
+
+# libelf fuzz target
+vpath %.c ../../../xen/common/libelf
+CFLAGS += -I../../../xen/common/libelf
+ELF_SRCS-y += libelf-tools.c libelf-loader.c libelf-dominfo.c
+ELF_LIB_OBJS := $(patsubst %.c,%.o,$(ELF_SRCS-y))
+
+$(patsubst %.c,%.o,$(ELF_SRCS-y)): CFLAGS += -Wno-pointer-sign
+
+$(ELF_LIB_OBJS): CFLAGS += -DFUZZ_NO_LIBXC $(CFLAGS_xeninclude)
+
+libelf-fuzzer.o: CFLAGS += $(CFLAGS_xeninclude)
+
+libelf.a: $(ELF_LIB_OBJS)
+	$(AR) rc $@ $^
+
+.PHONY: libelf-fuzzer-all
+libelf-fuzzer-all: libelf.a libelf-fuzzer.o
+
+# Common targets
+.PHONY: all
+all: libelf-fuzzer-all
+
+.PHONY: distclean
+distclean: clean
+
+.PHONY: clean
+clean:
+	rm -f *.o *.a
tools/fuzz/libelf/libelf-fuzzer.c new file +32 -0
new file mode 100644
index 0000000..71561d3
@@ -0,0 +1,32 @@
+#include <inttypes.h>
+#include <stddef.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <xen/libelf/libelf.h>
+
+int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
+{
+    struct elf_binary elf_buf, *elf;
+    struct elf_dom_parms parms;
+
+    elf = &elf_buf;
+
+    memset(elf, 0, sizeof(*elf));
+    elf_init(elf, (const char *)data, size);
+    elf_parse_binary(elf);
+    elf_xen_parse(elf, &parms);
+
+    return 0;
+}
+
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
xen/common/libelf/libelf-private.h +2 -0
index 388c3da..47db679 100644
@@ -72,8 +72,10 @@
 #include <xen/elfnote.h>
 #include <xen/libelf/libelf.h>
 
+#ifndef FUZZ_NO_LIBXC
 #include "xenctrl.h"
 #include "xc_private.h"
+#endif
 
 #define elf_msg(elf, fmt, args ... )                    \
     elf_call_log_callback(elf, 0, fmt , ## args );
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Reviewed-by on v3 1/7
#2 lore raw

Re: [PATCH v3 1/7] tools/fuzz: introduce libelf target

Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 12.12.16 at 10:28, <[email protected]> wrote:

Source code and Makefile to fuzz libelf in Google's oss-fuzz infrastructure.

Introduce FUZZ_NO_LIBXC in libelf-private.h. That macro will be set when compiling libelf fuzzer target because libxc is not required in libelf fuzzing.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

author
#3 lore raw

PATCH v3 2/7 x86emul/test: factor out emul_test_make_stack_executable

In reply to Wei Liu

It will be used by emulator fuzzing target.

---
 tools/tests/x86_emulator/test_x86_emulator.c | 12 ++----------
 tools/tests/x86_emulator/x86_emulate.c       | 20 ++++++++++++++++++++
 tools/tests/x86_emulator/x86_emulate.h       |  3 +++
 3 files changed, 25 insertions(+), 10 deletions(-)
tools/tests/x86_emulator/test_x86_emulator.c +2 -10
index eed8a0d..0d80bff 100644
@@ -23,8 +23,6 @@ static const struct {
 #endif
 };
 
-#define MMAP_SZ 16384
-
 /* EFLAGS bit definitions. */
 #define EFLG_OF (1<<11)
 #define EFLG_DF (1<<10)
@@ -234,7 +232,6 @@ int main(int argc, char **argv)
     struct cpu_user_regs regs;
     char *instr;
     unsigned int *res, i, j;
-    unsigned long sp;
     bool stack_exec;
     int rc;
 #ifndef __x86_64__
@@ -258,13 +255,8 @@ int main(int argc, char **argv)
     }
     instr = (char *)res + 0x100;
 
-#ifdef __x86_64__
-    asm ("movq %%rsp, %0" : "=g" (sp));
-#else
-    asm ("movl %%esp, %0" : "=g" (sp));
-#endif
-    stack_exec = mprotect((void *)(sp & -0x1000L) - (MMAP_SZ - 0x1000),
-                          MMAP_SZ, PROT_READ|PROT_WRITE|PROT_EXEC) == 0;
+    stack_exec = emul_test_make_stack_executable();
+
     if ( !stack_exec )
         printf("Warning: Stack could not be made executable (%d).\n", errno);
 
tools/tests/x86_emulator/x86_emulate.c +20 -0
index 66c2464..963dd71 100644
@@ -1,5 +1,7 @@
 #include "x86_emulate.h"
 
+#include <sys/mman.h>
+
 #define EFER_SCE       (1 << 0)
 #define EFER_LMA       (1 << 10)
 
@@ -18,4 +20,22 @@
 #define get_stub(stb) ((void *)((stb).addr = (uintptr_t)(stb).buf))
 #define put_stub(stb)
 
+bool emul_test_make_stack_executable(void)
+{
+    unsigned long sp;
+
+    /*
+     * Mark the entire stack executable so that the stub executions
+     * don't fault
+     */
+#ifdef __x86_64__
+    asm ("movq %%rsp, %0" : "=g" (sp));
+#else
+    asm ("movl %%esp, %0" : "=g" (sp));
+#endif
+
+    return mprotect((void *)(sp & -0x1000L) - (MMAP_SZ - 0x1000),
+                    MMAP_SZ, PROT_READ|PROT_WRITE|PROT_EXEC) == 0;
+}
+
 #include "x86_emulate/x86_emulate.c"
tools/tests/x86_emulator/x86_emulate.h +3 -0
index 1981326..a9b874c 100644
@@ -33,4 +33,7 @@
 
 #define is_canonical_address(x) (((int64_t)(x) >> 47) == ((int64_t)(x) >> 63))
 
+#define MMAP_SZ 16384
+bool emul_test_make_stack_executable(void);
+
 #include "x86_emulate/x86_emulate.h"
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
author
#4 lore raw

PATCH v3 3/7 x86emul/test: factor out emul_test_{read_cr, cpuid}

In reply to Wei Liu

While at it, move xgetbv, all cpu_has_* and cache_line_size macros to x86_emulate.h.

---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Wei Liu <[email protected]>

---
 tools/tests/x86_emulator/test_x86_emulator.c | 103 +--------------------------
 tools/tests/x86_emulator/x86_emulate.c       |  39 ++++++++++
 tools/tests/x86_emulator/x86_emulate.h       |  72 +++++++++++++++++++
 3 files changed, 113 insertions(+), 101 deletions(-)
tools/tests/x86_emulator/test_x86_emulator.c +2 -101
index 0d80bff..e40f0ea 100644
@@ -92,105 +92,6 @@ static int cmpxchg(
     return X86EMUL_OKAY;
 }
 
-static int cpuid(
-    unsigned int *eax,
-    unsigned int *ebx,
-    unsigned int *ecx,
-    unsigned int *edx,
-    struct x86_emulate_ctxt *ctxt)
-{
-    unsigned int leaf = *eax;
-
-    asm ("cpuid" : "+a" (*eax), "+c" (*ecx), "=d" (*edx), "=b" (*ebx));
-
-    /* The emulator doesn't itself use MOVBE, so we can always run the test. */
-    if ( leaf == 1 )
-        *ecx |= 1U << 22;
-
-    return X86EMUL_OKAY;
-}
-
-#define cache_line_size() ({ \
-    unsigned int eax = 1, ebx, ecx = 0, edx; \
-    cpuid(&eax, &ebx, &ecx, &edx, NULL); \
-    edx & (1U << 19) ? (ebx >> 5) & 0x7f8 : 0; \
-})
-
-#define cpu_has_mmx ({ \
-    unsigned int eax = 1, ecx = 0, edx; \
-    cpuid(&eax, &ecx, &ecx, &edx, NULL); \
-    (edx & (1U << 23)) != 0; \
-})
-
-#define cpu_has_sse ({ \
-    unsigned int eax = 1, ecx = 0, edx; \
-    cpuid(&eax, &ecx, &ecx, &edx, NULL); \
-    (edx & (1U << 25)) != 0; \
-})
-
-#define cpu_has_sse2 ({ \
-    unsigned int eax = 1, ecx = 0, edx; \
-    cpuid(&eax, &ecx, &ecx, &edx, NULL); \
-    (edx & (1U << 26)) != 0; \
-})
-
-#define cpu_has_xsave ({ \
-    unsigned int eax = 1, ecx = 0; \
-    cpuid(&eax, &eax, &ecx, &eax, NULL); \
-    /* Intentionally checking OSXSAVE here. */ \
-    (ecx & (1U << 27)) != 0; \
-})
-
-static inline uint64_t xgetbv(uint32_t xcr)
-{
-    uint32_t lo, hi;
-
-    asm ( ".byte 0x0f, 0x01, 0xd0" : "=a" (lo), "=d" (hi) : "c" (xcr) );
-
-    return ((uint64_t)hi << 32) | lo;
-}
-
-#define cpu_has_avx ({ \
-    unsigned int eax = 1, ecx = 0; \
-    cpuid(&eax, &eax, &ecx, &eax, NULL); \
-    if ( !(ecx & (1U << 27)) || ((xgetbv(0) & 6) != 6) ) \
-        ecx = 0; \
-    (ecx & (1U << 28)) != 0; \
-})
-
-#define cpu_has_avx2 ({ \
-    unsigned int eax = 1, ebx, ecx = 0; \
-    cpuid(&eax, &ebx, &ecx, &eax, NULL); \
-    if ( !(ecx & (1U << 27)) || ((xgetbv(0) & 6) != 6) ) \
-        ebx = 0; \
-    else { \
-        eax = 7, ecx = 0; \
-        cpuid(&eax, &ebx, &ecx, &eax, NULL); \
-    } \
-    (ebx & (1U << 5)) != 0; \
-})
-
-static int read_cr(
-    unsigned int reg,
-    unsigned long *val,
-    struct x86_emulate_ctxt *ctxt)
-{
-    /* Fake just enough state for the emulator's _get_fpu() to be happy. */
-    switch ( reg )
-    {
-    case 0:
-        *val = 0x00000001; /* PE */
-        return X86EMUL_OKAY;
-
-    case 4:
-        /* OSFXSR, OSXMMEXCPT, and maybe OSXSAVE */
-        *val = 0x00000600 | (cpu_has_xsave ? 0x00040000 : 0);
-        return X86EMUL_OKAY;
-    }
-
-    return X86EMUL_UNHANDLEABLE;
-}
-
 int get_fpu(
     void (*exception_callback)(void *, struct cpu_user_regs *),
     void *exception_callback_arg,
@@ -221,8 +122,8 @@ static struct x86_emulate_ops emulops = {
     .insn_fetch = fetch,
     .write      = write,
     .cmpxchg    = cmpxchg,
-    .cpuid      = cpuid,
-    .read_cr    = read_cr,
+    .cpuid      = emul_test_cpuid,
+    .read_cr    = emul_test_read_cr,
     .get_fpu    = get_fpu,
 };
 
tools/tests/x86_emulator/x86_emulate.c +39 -0
index 963dd71..8b70580 100644
@@ -38,4 +38,43 @@ bool emul_test_make_stack_executable(void)
                     MMAP_SZ, PROT_READ|PROT_WRITE|PROT_EXEC) == 0;
 }
 
+int emul_test_cpuid(
+    unsigned int *eax,
+    unsigned int *ebx,
+    unsigned int *ecx,
+    unsigned int *edx,
+    struct x86_emulate_ctxt *ctxt)
+{
+    unsigned int leaf = *eax;
+
+    asm ("cpuid" : "+a" (*eax), "+c" (*ecx), "=d" (*edx), "=b" (*ebx));
+
+    /* The emulator doesn't itself use MOVBE, so we can always run the test. */
+    if ( leaf == 1 )
+        *ecx |= 1U << 22;
+
+    return X86EMUL_OKAY;
+}
+
+int emul_test_read_cr(
+    unsigned int reg,
+    unsigned long *val,
+    struct x86_emulate_ctxt *ctxt)
+{
+    /* Fake just enough state for the emulator's _get_fpu() to be happy. */
+    switch ( reg )
+    {
+    case 0:
+        *val = 0x00000001; /* PE */
+        return X86EMUL_OKAY;
+
+    case 4:
+        /* OSFXSR, OSXMMEXCPT, and maybe OSXSAVE */
+        *val = 0x00000600 | (cpu_has_xsave ? 0x00040000 : 0);
+        return X86EMUL_OKAY;
+    }
+
+    return X86EMUL_UNHANDLEABLE;
+}
+
 #include "x86_emulate/x86_emulate.c"
tools/tests/x86_emulator/x86_emulate.h +72 -0

75 lines not on this page · raw message

Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Reviewed-by on v3 3/7
#5 lore raw

Re: [PATCH v3 3/7] x86emul/test: factor out emul_test_{read_cr, cpuid}

Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 12.12.16 at 10:28, <[email protected]> wrote:

While at it, move xgetbv, all cpu_has_* and cache_line_size macros to x86_emulate.h.

with one further cosmetic request:

Quoted 10 lines
tools/tests/x86_emulator/x86_emulate.c +4 -0
@@ -38,4 +38,43 @@ bool emul_test_make_stack_executable(void)
                     MMAP_SZ, PROT_READ|PROT_WRITE|PROT_EXEC) == 0;
 }
 
+int emul_test_cpuid(
+    unsigned int *eax,
+    unsigned int *ebx,
+    unsigned int *ecx,

tools/tests/x86_emulator/x86_emulate.c bool emul_test_make_stack_executable(void) · line 54

Quoted 10 lines
tools/tests/x86_emulator/x86_emulate.c +10 -0
+    unsigned int *edx,
+    struct x86_emulate_ctxt *ctxt)
+{
+    unsigned int leaf = *eax;
+
+    asm ("cpuid" : "+a" (*eax), "+c" (*ecx), "=d" (*edx), "=b" (*ebx));
+
+    /* The emulator doesn't itself use MOVBE, so we can always run the test. */
+    if ( leaf == 1 )
+        *ecx |= 1U << 22;

The comment here wants some adjustment: "the test" is no longer applicable. Perhaps "respective tests"?

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

author
#6 lore raw

Re: [PATCH v3 3/7] x86emul/test: factor out emul_test_{read_cr, cpuid}

Quoted 24 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 12.12.16 at 10:28, <[email protected]> wrote:

While at it, move xgetbv, all cpu_has_* and cache_line_size macros to x86_emulate.h.

with one further cosmetic request:

Quoted 15 lines
tools/tests/x86_emulator/x86_emulate.c +9 -0
@@ -38,4 +38,43 @@ bool emul_test_make_stack_executable(void)
                     MMAP_SZ, PROT_READ|PROT_WRITE|PROT_EXEC) == 0;
 }
 
+int emul_test_cpuid(
+    unsigned int *eax,
+    unsigned int *ebx,
+    unsigned int *ecx,
+    unsigned int *edx,
+    struct x86_emulate_ctxt *ctxt)
+{
+    unsigned int leaf = *eax;
+
Quoted 9 lines

tools/tests/x86_emulator/x86_emulate.c bool emul_test_make_stack_executable(void) · line 54

Quoted 5 lines
tools/tests/x86_emulator/x86_emulate.c +5 -0
+    asm ("cpuid" : "+a" (*eax), "+c" (*ecx), "=d" (*edx), "=b" (*ebx));
+
+    /* The emulator doesn't itself use MOVBE, so we can always run the test. */
+    if ( leaf == 1 )
+        *ecx |= 1U << 22;

The comment here wants some adjustment: "the test" is no longer applicable. Perhaps "respective tests"?

Sure. I will make the change in my branch.

Wei.

Quoted 2 lines

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

author
#7 lore raw

PATCH v3 4/7 x86emul/test: factor out emul_test_get_fpu

In reply to Wei Liu

---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Wei Liu <[email protected]>

---
 tools/tests/x86_emulator/test_x86_emulator.c | 27 +--------------------------
 tools/tests/x86_emulator/x86_emulate.c       | 25 +++++++++++++++++++++++++
 tools/tests/x86_emulator/x86_emulate.h       |  6 ++++++
 3 files changed, 32 insertions(+), 26 deletions(-)
tools/tests/x86_emulator/test_x86_emulator.c +1 -26
index e40f0ea..04b8ca6 100644
@@ -92,31 +92,6 @@ static int cmpxchg(
     return X86EMUL_OKAY;
 }
 
-int get_fpu(
-    void (*exception_callback)(void *, struct cpu_user_regs *),
-    void *exception_callback_arg,
-    enum x86_emulate_fpu_type type,
-    struct x86_emulate_ctxt *ctxt)
-{
-    switch ( type )
-    {
-    case X86EMUL_FPU_fpu:
-        break;
-    case X86EMUL_FPU_mmx:
-        if ( cpu_has_mmx )
-            break;
-    case X86EMUL_FPU_xmm:
-        if ( cpu_has_sse )
-            break;
-    case X86EMUL_FPU_ymm:
-        if ( cpu_has_avx )
-            break;
-    default:
-        return X86EMUL_UNHANDLEABLE;
-    }
-    return X86EMUL_OKAY;
-}
-
 static struct x86_emulate_ops emulops = {
     .read       = read,
     .insn_fetch = fetch,
@@ -124,7 +99,7 @@ static struct x86_emulate_ops emulops = {
     .cmpxchg    = cmpxchg,
     .cpuid      = emul_test_cpuid,
     .read_cr    = emul_test_read_cr,
-    .get_fpu    = get_fpu,
+    .get_fpu    = emul_test_get_fpu,
 };
 
 int main(int argc, char **argv)
tools/tests/x86_emulator/x86_emulate.c +25 -0
index 8b70580..a666a32 100644
@@ -77,4 +77,29 @@ int emul_test_read_cr(
     return X86EMUL_UNHANDLEABLE;
 }
 
+int emul_test_get_fpu(
+    void (*exception_callback)(void *, struct cpu_user_regs *),
+    void *exception_callback_arg,
+    enum x86_emulate_fpu_type type,
+    struct x86_emulate_ctxt *ctxt)
+{
+    switch ( type )
+    {
+    case X86EMUL_FPU_fpu:
+        break;
+    case X86EMUL_FPU_mmx:
+        if ( cpu_has_mmx )
+            break;
+    case X86EMUL_FPU_xmm:
+        if ( cpu_has_sse )
+            break;
+    case X86EMUL_FPU_ymm:
+        if ( cpu_has_avx )
+            break;
+    default:
+        return X86EMUL_UNHANDLEABLE;
+    }
+    return X86EMUL_OKAY;
+}
+
 #include "x86_emulate/x86_emulate.c"
tools/tests/x86_emulator/x86_emulate.h +6 -0
index 4cc3f72..b4d1555 100644
@@ -109,3 +109,9 @@ int emul_test_read_cr(
     unsigned int reg,
     unsigned long *val,
     struct x86_emulate_ctxt *ctxt);
+
+int emul_test_get_fpu(
+    void (*exception_callback)(void *, struct cpu_user_regs *),
+    void *exception_callback_arg,
+    enum x86_emulate_fpu_type type,
+    struct x86_emulate_ctxt *ctxt);
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
author
#9 lore raw

PATCH v3 5/7 tools/fuzz: introduce x86 instruction emulator target

In reply to Wei Liu

Instruction emulator fuzzing code is from code previous written by Andrew and George. Adapted to llvm fuzzer and hook up the build system.

---
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Tim Deegan <[email protected]>
Cc: Wei Liu <[email protected]>

v3:
1. coding style fix
2. share more code
3. exit when stack can't be made executable

---
 .gitignore                                         |   1 +
 tools/fuzz/x86_instruction_emulator/Makefile       |  31 ++++
 .../x86-insn-emulator-fuzzer.c                     | 195 +++++++++++++++++++++
 3 files changed, 227 insertions(+)
 create mode 100644 tools/fuzz/x86_instruction_emulator/Makefile
 create mode 100644 tools/fuzz/x86_instruction_emulator/x86-insn-emulator-fuzzer.c
.gitignore +1 -0
index a2f34a1..d507243 100644
@@ -145,6 +145,7 @@ tools/flask/utils/flask-loadpolicy
 tools/flask/utils/flask-setenforce
 tools/flask/utils/flask-set-bool
 tools/flask/utils/flask-label-pci
+tools/fuzz/x86_instruction_emulator/x86_emulate*
 tools/helpers/_paths.h
 tools/helpers/init-xenstore-domain
 tools/helpers/xen-init-dom0
tools/fuzz/x86_instruction_emulator/Makefile new file +31 -0
new file mode 100644
index 0000000..2b147ac
@@ -0,0 +1,31 @@
+XEN_ROOT=$(CURDIR)/../../..
+include $(XEN_ROOT)/tools/Rules.mk
+
+x86-instruction-emulator-fuzzer-all: x86-insn-emulator.a x86-insn-emulator-fuzzer.o
+
+x86_emulate/x86_emulate.c x86_emulate/x86_emulate.h:
+	[ -L x86_emulate ] || ln -sf $(XEN_ROOT)/xen/arch/x86/x86_emulate .
+
+x86_emulate.c x86_emulate.h: %:
+	[ -L $* ] || ln -sf $(XEN_ROOT)/tools/tests/x86_emulator/$*
+
+CFLAGS += $(CFLAGS_xeninclude)
+
+x86_emulate.o: x86_emulate.c x86_emulate.h x86_emulate/x86_emulate.c x86_emulate/x86_emulate.h
+
+x86-insn-emulator.a: x86_emulate.o
+	$(AR) rc $@ $^
+
+x86-insn-emulator-fuzzer.o: x86-insn-emulator-fuzzer.c
+
+# Common targets
+.PHONY: all
+all: x86-instruction-emulator-fuzzer-all
+
+.PHONY: distclean
+distclean: clean
+	rm -f x86_emulate x86_emulate.c x86_emulate.h
+
+.PHONY: clean
+clean:
+	rm -f *.a *.o
tools/fuzz/x86_instruction_emulator/x86-insn-emulator-fuzzer.c new file +195 -0

195 lines not on this page · raw message

Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#10 lore raw

Re: [PATCH v3 5/7] tools/fuzz: introduce x86 instruction emulator target

Quoted 53 lines
Quoted 1 line
Quoted 1 line · On 12.12.16 at 10:28, <[email protected]> wrote:

Instruction emulator fuzzing code is from code previous written by Andrew and George. Adapted to llvm fuzzer and hook up the build system.

---
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Tim Deegan <[email protected]>
Cc: Wei Liu <[email protected]>

v3:
1. coding style fix
2. share more code
3. exit when stack can't be made executable

---
 .gitignore                                         |   1 +
 tools/fuzz/x86_instruction_emulator/Makefile       |  31 ++++
 .../x86-insn-emulator-fuzzer.c                     | 195 +++++++++++++++++++++
 3 files changed, 227 insertions(+)
 create mode 100644 tools/fuzz/x86_instruction_emulator/Makefile
 create mode 100644 

tools/fuzz/x86_instruction_emulator/x86-insn-emulator-fuzzer.c

.gitignore +1 -0
index a2f34a1..d507243 100644
@@ -145,6 +145,7 @@ tools/flask/utils/flask-loadpolicy
 tools/flask/utils/flask-setenforce
 tools/flask/utils/flask-set-bool
 tools/flask/utils/flask-label-pci
+tools/fuzz/x86_instruction_emulator/x86_emulate*
 tools/helpers/_paths.h
 tools/helpers/init-xenstore-domain
 tools/helpers/xen-init-dom0
tools/fuzz/x86_instruction_emulator/Makefile new file +4 -0
new file mode 100644
index 0000000..2b147ac
@@ -0,0 +1,31 @@
+XEN_ROOT=$(CURDIR)/../../..
+include $(XEN_ROOT)/tools/Rules.mk
+
+x86-instruction-emulator-fuzzer-all: x86-insn-emulator.a x86-insn-emulator-fuzzer.o

tools/fuzz/x86_instruction_emulator/Makefile line 14

Quoted 10 lines
tools/fuzz/x86_instruction_emulator/Makefile new file +10 -0
+
+x86_emulate/x86_emulate.c x86_emulate/x86_emulate.h:
+	[ -L x86_emulate ] || ln -sf $(XEN_ROOT)/xen/arch/x86/x86_emulate .
+
+x86_emulate.c x86_emulate.h: %:
+	[ -L $* ] || ln -sf $(XEN_ROOT)/tools/tests/x86_emulator/$*
+
+CFLAGS += $(CFLAGS_xeninclude)
+
+x86_emulate.o: x86_emulate.c x86_emulate.h x86_emulate/x86_emulate.c x86_emulate/x86_emulate.h

Perhaps worthwhile shortening this to

x86_emulate.o: x86_emulate.[ch] x86_emulate/x86_emulate.[ch]

?

Quoted 13 lines
tools/fuzz/x86_instruction_emulator/x86-insn-emulator-fuzzer.c new file +10 -0
@@ -0,0 +1,195 @@
+#include <assert.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <inttypes.h>
+#include <limits.h>
+#include <stdbool.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>

tools/fuzz/x86_instruction_emulator/x86-insn-emulator-fuzzer.c line 20

Quoted 10 lines
tools/fuzz/x86_instruction_emulator/x86-insn-emulator-fuzzer.c new file +10 -0
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/mman.h>
+#include <unistd.h>
+#include <xen/xen.h>
+
+#include "x86_emulate.h"
+
+static unsigned char data[4096];
+static unsigned int data_index = 0;

Pointless initializer.

tools/fuzz/x86_instruction_emulator/x86-insn-emulator-fuzzer.c line 25

Quoted 5 lines
tools/fuzz/x86_instruction_emulator/x86-insn-emulator-fuzzer.c new file +5 -0
+static unsigned int data_max;
+
+static int data_read(const char *why, void *dst, unsigned int bytes)
+{
+    unsigned i;

Please don't omit the "int" here (and in a few more places below) when basically everywhere else it is present.

tools/fuzz/x86_instruction_emulator/x86-insn-emulator-fuzzer.c line 30

Quoted 4 lines
tools/fuzz/x86_instruction_emulator/x86-insn-emulator-fuzzer.c new file +4 -0
+    if ( data_index + bytes > data_max )
+        return X86EMUL_EXCEPTION;
+
+    memcpy(dst,  data+data_index, bytes);

Blanks around binary operators please (more further down).

tools/fuzz/x86_instruction_emulator/x86-insn-emulator-fuzzer.c line 35

Quoted 5 lines
tools/fuzz/x86_instruction_emulator/x86-insn-emulator-fuzzer.c new file +5 -0
+    data_index += bytes;
+
+    printf("%s: ", why);
+    for ( i = 0; i < bytes; i++ )
+        printf(" %02x", (unsigned int)*(unsigned char *)(dst+i));

Is the left most cast really needed here?

tools/fuzz/x86_instruction_emulator/x86-insn-emulator-fuzzer.c line 118

Quoted 11 lines
tools/fuzz/x86_instruction_emulator/x86-insn-emulator-fuzzer.c new file +11 -0
+int LLVMFuzzerTestOneInput(const uint8_t *data_p, size_t size)
+{
+    bool stack_exec;
+    struct cpu_user_regs regs = {};
+    struct x86_emulate_ctxt ctxt =
+        {
+            .regs = &regs,
+            .addr_size = 8 * sizeof(void *),
+            .sp_size = 8 * sizeof(void *),
+        };
+

Stray blank line. The indentation of the initializer above also looks a little unusual.

tools/fuzz/x86_instruction_emulator/x86-insn-emulator-fuzzer.c line 131

Quoted 13 lines
tools/fuzz/x86_instruction_emulator/x86-insn-emulator-fuzzer.c new file +13 -0
+    unsigned nr = 0;
+    int rc;
+    unsigned x;
+    const uint8_t *p = data_p;
+
+    stack_exec = emul_test_make_stack_executable();
+    if ( !stack_exec )
+    {
+        printf("Warning: Stack could not be made executable (%d).\n", errno);
+        exit(1);
+    }
+
+    /* Reset all global states */

DYM "state"?

tools/fuzz/x86_instruction_emulator/x86-insn-emulator-fuzzer.c line 140

Quoted 9 lines
tools/fuzz/x86_instruction_emulator/x86-insn-emulator-fuzzer.c new file +9 -0
+    memset(data, 0, sizeof(data));
+    data_index = 0;
+    data_max = 0;
+
+    nr = size < sizeof(regs) ? size : sizeof(regs);
+
+    memcpy(&regs, p, nr);
+    p += sizeof(regs);
+    nr += sizeof(regs);

I think this second += wants to be dropped, considering how nr gets set above and used below.

tools/fuzz/x86_instruction_emulator/x86-insn-emulator-fuzzer.c line 142

Quoted 1 line
tools/fuzz/x86_instruction_emulator/x86-insn-emulator-fuzzer.c new file +1 -0
+    if ( nr <= size )

< would seem more natural here.

tools/fuzz/x86_instruction_emulator/x86-insn-emulator-fuzzer.c line 148

Quoted 6 lines
tools/fuzz/x86_instruction_emulator/x86-insn-emulator-fuzzer.c new file +6 -0
+    {
+        memcpy(data, p, size - nr);
+        data_max = size - nr;
+    }
+
+    ctxt.force_writeback = 0;

false

tools/fuzz/x86_instruction_emulator/x86-insn-emulator-fuzzer.c line 150

Quoted 1 line
tools/fuzz/x86_instruction_emulator/x86-insn-emulator-fuzzer.c new file +1 -0
+    /* Zero 'private' entries */

s/entries/fields/ ?

tools/fuzz/x86_instruction_emulator/x86-insn-emulator-fuzzer.c line 155

Quoted 5 lines
tools/fuzz/x86_instruction_emulator/x86-insn-emulator-fuzzer.c new file +5 -0
+    regs.error_code = 0;
+    regs.entry_vector = 0;
+
+    /* Use the upper bits of regs.eip to determine addr_size */
+    x = (regs.rip >> ADDR_SIZE_SHIFT) & 0x3;

This won't build as 32-bit code. If that's intentional, then I think this would better be enforced in the Makefile (rather than surfacing a compile error here).

tools/fuzz/x86_instruction_emulator/x86-insn-emulator-fuzzer.c line 165

Quoted 10 lines
tools/fuzz/x86_instruction_emulator/x86-insn-emulator-fuzzer.c new file +10 -0
+    if (x == 3)
+        x = 2;
+    ctxt.addr_size = 16 << x;
+    printf("addr_size: %d\n", ctxt.addr_size);
+
+    /* Use the upper bit of regs.rsp to determine sp_size (if appropriate) */
+    if ( ctxt.addr_size == 64 )
+    {
+        ctxt.sp_size = 64;
+    }

Pointless braces.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

author
#11 lore raw

Re: [PATCH v3 5/7] tools/fuzz: introduce x86 instruction emulator target

Quoted 66 lines · Jan Beulich
Quoted 53 lines
Quoted 1 line
Quoted 1 line · On 12.12.16 at 10:28, <[email protected]> wrote:

Instruction emulator fuzzing code is from code previous written by Andrew and George. Adapted to llvm fuzzer and hook up the build system.

---
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Tim Deegan <[email protected]>
Cc: Wei Liu <[email protected]>

v3:
1. coding style fix
2. share more code
3. exit when stack can't be made executable

---
 .gitignore                                         |   1 +
 tools/fuzz/x86_instruction_emulator/Makefile       |  31 ++++
 .../x86-insn-emulator-fuzzer.c                     | 195 +++++++++++++++++++++
 3 files changed, 227 insertions(+)
 create mode 100644 tools/fuzz/x86_instruction_emulator/Makefile
 create mode 100644 

tools/fuzz/x86_instruction_emulator/x86-insn-emulator-fuzzer.c

.gitignore +1 -0
index a2f34a1..d507243 100644
@@ -145,6 +145,7 @@ tools/flask/utils/flask-loadpolicy
 tools/flask/utils/flask-setenforce
 tools/flask/utils/flask-set-bool
 tools/flask/utils/flask-label-pci
+tools/fuzz/x86_instruction_emulator/x86_emulate*
 tools/helpers/_paths.h
 tools/helpers/init-xenstore-domain
 tools/helpers/xen-init-dom0
tools/fuzz/x86_instruction_emulator/Makefile new file +4 -0
new file mode 100644
index 0000000..2b147ac
@@ -0,0 +1,31 @@
+XEN_ROOT=$(CURDIR)/../../..
+include $(XEN_ROOT)/tools/Rules.mk
+
+x86-instruction-emulator-fuzzer-all: x86-insn-emulator.a x86-insn-emulator-fuzzer.o

tools/fuzz/x86_instruction_emulator/Makefile line 14

Quoted 10 lines
tools/fuzz/x86_instruction_emulator/Makefile new file +10 -0
+
+x86_emulate/x86_emulate.c x86_emulate/x86_emulate.h:
+	[ -L x86_emulate ] || ln -sf $(XEN_ROOT)/xen/arch/x86/x86_emulate .
+
+x86_emulate.c x86_emulate.h: %:
+	[ -L $* ] || ln -sf $(XEN_ROOT)/tools/tests/x86_emulator/$*
+
+CFLAGS += $(CFLAGS_xeninclude)
+
+x86_emulate.o: x86_emulate.c x86_emulate.h x86_emulate/x86_emulate.c x86_emulate/x86_emulate.h

Perhaps worthwhile shortening this to

Quoted 3 lines

x86_emulate.o: x86_emulate.[ch] x86_emulate/x86_emulate.[ch]

?

Done.

Quoted 18 lines
Quoted 18 lines
tools/fuzz/x86_instruction_emulator/x86-insn-emulator-fuzzer.c new file +14 -0
@@ -0,0 +1,195 @@
+#include <assert.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <inttypes.h>
+#include <limits.h>
+#include <stdbool.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/mman.h>
+#include <unistd.h>
Quoted 9 lines

tools/fuzz/x86_instruction_emulator/x86-insn-emulator-fuzzer.c line 20

Quoted 6 lines
tools/fuzz/x86_instruction_emulator/x86-insn-emulator-fuzzer.c new file +6 -0
+#include <xen/xen.h>
+
+#include "x86_emulate.h"
+
+static unsigned char data[4096];
+static unsigned int data_index = 0;

Pointless initializer.

Done.

Quoted 9 lines

tools/fuzz/x86_instruction_emulator/x86-insn-emulator-fuzzer.c line 25

Quoted 5 lines
tools/fuzz/x86_instruction_emulator/x86-insn-emulator-fuzzer.c new file +5 -0
+static unsigned int data_max;
+
+static int data_read(const char *why, void *dst, unsigned int bytes)
+{
+    unsigned i;

Please don't omit the "int" here (and in a few more places below) when basically everywhere else it is present.

Done.

Quoted 7 lines

tools/fuzz/x86_instruction_emulator/x86-insn-emulator-fuzzer.c line 29

Quoted 4 lines
tools/fuzz/x86_instruction_emulator/x86-insn-emulator-fuzzer.c new file +4 -0
+    if ( data_index + bytes > data_max )
+        return X86EMUL_EXCEPTION;
+
+    memcpy(dst,  data+data_index, bytes);

Blanks around binary operators please (more further down).

Done.

Quoted 8 lines

tools/fuzz/x86_instruction_emulator/x86-insn-emulator-fuzzer.c line 34

Quoted 5 lines
tools/fuzz/x86_instruction_emulator/x86-insn-emulator-fuzzer.c new file +5 -0
+    data_index += bytes;
+
+    printf("%s: ", why);
+    for ( i = 0; i < bytes; i++ )
+        printf(" %02x", (unsigned int)*(unsigned char *)(dst+i));

Is the left most cast really needed here?

No. I've deleted that.

Quoted 6 lines
Quoted 6 lines
tools/fuzz/x86_instruction_emulator/x86-insn-emulator-fuzzer.c new file +6 -0
+int LLVMFuzzerTestOneInput(const uint8_t *data_p, size_t size)
+{
+    bool stack_exec;
+    struct cpu_user_regs regs = {};
+    struct x86_emulate_ctxt ctxt =
+        {
Quoted 9 lines

tools/fuzz/x86_instruction_emulator/x86-insn-emulator-fuzzer.c line 45

Quoted 5 lines
tools/fuzz/x86_instruction_emulator/x86-insn-emulator-fuzzer.c new file +5 -0
+            .regs = &regs,
+            .addr_size = 8 * sizeof(void *),
+            .sp_size = 8 * sizeof(void *),
+        };
+

Stray blank line. The indentation of the initializer above also looks a little unusual.

Fixed.

Quoted 7 lines
Quoted 7 lines
tools/fuzz/x86_instruction_emulator/x86-insn-emulator-fuzzer.c new file +7 -0
+    unsigned nr = 0;
+    int rc;
+    unsigned x;
+    const uint8_t *p = data_p;
+
+    stack_exec = emul_test_make_stack_executable();
+    if ( !stack_exec )
Quoted 9 lines

tools/fuzz/x86_instruction_emulator/x86-insn-emulator-fuzzer.c line 58

Quoted 6 lines
tools/fuzz/x86_instruction_emulator/x86-insn-emulator-fuzzer.c new file +6 -0
+    {
+        printf("Warning: Stack could not be made executable (%d).\n", errno);
+        exit(1);
+    }
+
+    /* Reset all global states */

DYM "state"?

I mean "states". There are three states we need to reset.

Quoted 13 lines

tools/fuzz/x86_instruction_emulator/x86-insn-emulator-fuzzer.c line 67

Quoted 9 lines
tools/fuzz/x86_instruction_emulator/x86-insn-emulator-fuzzer.c new file +9 -0
+    memset(data, 0, sizeof(data));
+    data_index = 0;
+    data_max = 0;
+
+    nr = size < sizeof(regs) ? size : sizeof(regs);
+
+    memcpy(&regs, p, nr);
+    p += sizeof(regs);
+    nr += sizeof(regs);

I think this second += wants to be dropped, considering how nr gets set above and used below.

Quoted 3 lines

tools/fuzz/x86_instruction_emulator/x86-insn-emulator-fuzzer.c line 68

Quoted 1 line
tools/fuzz/x86_instruction_emulator/x86-insn-emulator-fuzzer.c new file +1 -0
+    if ( nr <= size )

< would seem more natural here.

Yes, you're right in both places.

Quoted 9 lines

tools/fuzz/x86_instruction_emulator/x86-insn-emulator-fuzzer.c line 74

Quoted 7 lines
tools/fuzz/x86_instruction_emulator/x86-insn-emulator-fuzzer.c new file +6 -0
+    {
+        memcpy(data, p, size - nr);
+        data_max = size - nr;
+    }
+
+    ctxt.force_writeback = 0;

false

Done.

Quoted 5 lines

tools/fuzz/x86_instruction_emulator/x86-insn-emulator-fuzzer.c line 75

Quoted 2 lines
tools/fuzz/x86_instruction_emulator/x86-insn-emulator-fuzzer.c new file +1 -0
+    /* Zero 'private' entries */

s/entries/fields/ ?

Done.

Quoted 10 lines

tools/fuzz/x86_instruction_emulator/x86-insn-emulator-fuzzer.c line 80

Quoted 5 lines
tools/fuzz/x86_instruction_emulator/x86-insn-emulator-fuzzer.c new file +5 -0
+    regs.error_code = 0;
+    regs.entry_vector = 0;
+
+    /* Use the upper bits of regs.eip to determine addr_size */
+    x = (regs.rip >> ADDR_SIZE_SHIFT) & 0x3;

This won't build as 32-bit code. If that's intentional, then I think this would better be enforced in the Makefile (rather than surfacing a compile error here).

Good catch. I think this test case is still preliminary. TBH I haven't paid much attention to the working of this test target, other than pulling everything together to work.

I think long term we do need to determine what to do with 32 bit build, but I would wait until George to come back because he wrote this snippet.

For now I will disable 32bit build in Makefile.

Quoted 1 line

tools/fuzz/x86_instruction_emulator/x86-insn-emulator-fuzzer.c line 81

Quoted 1 line
tools/fuzz/x86_instruction_emulator/x86-insn-emulator-fuzzer.c new file +1 -0
+    if (x == 3)

I also fix this instance to add spaces in ().

---8<---
From 83b7381080aafc3f2fb35ba589715694f847f73a Mon Sep 17 00:00:00 2001
From: Wei Liu <[email protected]>
Date: Thu, 8 Dec 2016 12:09:54 +0000
Subject: [PATCH] tools/fuzz: introduce x86 instruction emulator target

Instruction emulator fuzzing code is from code previous written by Andrew and George. Adapt it to llvm fuzzer and hook up the build system.

---
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Tim Deegan <[email protected]>
Cc: Wei Liu <[email protected]>

v4:
1. more coding style fixes and bug fixes
2. only do 64 bit build

v3:
1. coding style fix
2. share more code
3. exit when stack can't be made executable

---
 .gitignore                                         |   1 +
 tools/fuzz/x86_instruction_emulator/Makefile       |  36 ++++
 .../x86-insn-emulator-fuzzer.c                     | 190 +++++++++++++++++++++
 3 files changed, 227 insertions(+)
 create mode 100644 tools/fuzz/x86_instruction_emulator/Makefile
 create mode 100644 tools/fuzz/x86_instruction_emulator/x86-insn-emulator-fuzzer.c
.gitignore +1 -0
index a2f34a1..d507243 100644
@@ -145,6 +145,7 @@ tools/flask/utils/flask-loadpolicy
 tools/flask/utils/flask-setenforce
 tools/flask/utils/flask-set-bool
 tools/flask/utils/flask-label-pci
+tools/fuzz/x86_instruction_emulator/x86_emulate*
 tools/helpers/_paths.h
 tools/helpers/init-xenstore-domain
 tools/helpers/xen-init-dom0
tools/fuzz/x86_instruction_emulator/Makefile new file +36 -0
new file mode 100644
index 0000000..6e68df7
@@ -0,0 +1,36 @@
+XEN_ROOT=$(CURDIR)/../../..
+include $(XEN_ROOT)/tools/Rules.mk
+
+.PHONY: x86-instruction-emulator-fuzzer-all
+ifeq ($(CONFIG_X86_64),y)
+x86-instruction-emulator-fuzzer-all: x86-insn-emulator.a x86-insn-emulator-fuzzer.o
+else
+x86-instruction-emulator-fuzzer-all:
+endif
+
+x86_emulate/x86_emulate.c x86_emulate/x86_emulate.h:
+	[ -L x86_emulate ] || ln -sf $(XEN_ROOT)/xen/arch/x86/x86_emulate .
+
+x86_emulate.c x86_emulate.h: %:
+	[ -L $* ] || ln -sf $(XEN_ROOT)/tools/tests/x86_emulator/$*
+
+CFLAGS += $(CFLAGS_xeninclude)
+
+x86_emulate.o: x86_emulate.[ch] x86_emulate/x86_emulate.[ch]
+
+x86-insn-emulator.a: x86_emulate.o
+	$(AR) rc $@ $^
+
+x86-insn-emulator-fuzzer.o: x86-insn-emulator-fuzzer.c
+
+# Common targets
+.PHONY: all
+all: x86-instruction-emulator-fuzzer-all
+
+.PHONY: distclean
+distclean: clean
+	rm -f x86_emulate x86_emulate.c x86_emulate.h
+
+.PHONY: clean
+clean:
+	rm -f *.a *.o
tools/fuzz/x86_instruction_emulator/x86-insn-emulator-fuzzer.c new file +190 -0

190 lines not on this page · raw message

Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Reviewed-by
#12 lore raw

Re: [PATCH v3 5/7] tools/fuzz: introduce x86 instruction emulator target

Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 12.12.16 at 12:19, <[email protected]> wrote:
Quoted 4 lines · Jan Beulich
Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 12.12.16 at 10:28, <[email protected]> wrote:

+ /* Reset all global states */

DYM "state"?

I mean "states". There are three states we need to reset.

Hmm, to me as a non-native speaker it feels wrong to use plural here (just like for e.g. milk), but maybe I'm wrong.

Quoted 20 lines

From: Wei Liu <[email protected]>
Date: Thu, 8 Dec 2016 12:09:54 +0000
Subject: [PATCH] tools/fuzz: introduce x86 instruction emulator target

Instruction emulator fuzzing code is from code previous written by Andrew and George. Adapt it to llvm fuzzer and hook up the build system.

---
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Tim Deegan <[email protected]>
Cc: Wei Liu <[email protected]>

Quoted 3 lines

v4:
1. more coding style fixes and bug fixes
2. only do 64 bit build

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

author
#13 lore raw

Re: [PATCH v3 5/7] tools/fuzz: introduce x86 instruction emulator target

Quoted 12 lines · Jan Beulich
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 12.12.16 at 12:19, <[email protected]> wrote:
Quoted 4 lines · Jan Beulich
Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 12.12.16 at 10:28, <[email protected]> wrote:

+ /* Reset all global states */

DYM "state"?

I mean "states". There are three states we need to reset.

Hmm, to me as a non-native speaker it feels wrong to use plural here (just like for e.g. milk), but maybe I'm wrong.

"State" is countable when used to represent the condition of somebody/something. Various other meanings of "state" don't apply here.

Sources:

https://www.oxfordlearnersdictionaries.com/definition/english/state_1
http://www.ldoceonline.com/dictionary/state

Quoted 20 lines
Quoted 20 lines

From: Wei Liu <[email protected]>
Date: Thu, 8 Dec 2016 12:09:54 +0000
Subject: [PATCH] tools/fuzz: introduce x86 instruction emulator target

Instruction emulator fuzzing code is from code previous written by Andrew and George. Adapt it to llvm fuzzer and hook up the build system.

---
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Tim Deegan <[email protected]>
Cc: Wei Liu <[email protected]>

Quoted 6 lines
Quoted 3 lines

v4:
1. more coding style fixes and bug fixes
2. only do 64 bit build

Thanks.

Wei.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#14 lore raw

Re: [PATCH v3 5/7] tools/fuzz: introduce x86 instruction emulator target

Wei Liu writes ("Re: [PATCH v3 5/7] tools/fuzz: introduce x86 instruction emulator target"):

Quoted 9 lines · Jan Beulich
Quoted 5 lines
Quoted 2 lines · On 12.12.16 at 12:19, <[email protected]> wrote:

I mean "states". There are three states we need to reset.

Hmm, to me as a non-native speaker it feels wrong to use plural here (just like for e.g. milk), but maybe I'm wrong.

"State" is countable when used to represent the condition of somebody/something. Various other meanings of "state" don't apply here.

I think "three states" can only be used to mean three alternative possible values of the same variable. It cannot be used to mean three separate variables.

So "a state" is one of the possible values. You can also say something like "the system is in a broken state", but again, this refers to a specific state amongst all the possible different states.

"Reset all states" is really odd and could almost never be right.

Ian.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

author
#15 lore raw

Re: [PATCH v3 5/7] tools/fuzz: introduce x86 instruction emulator target

Quoted 15 lines · Ian Jackson

Wei Liu writes ("Re: [PATCH v3 5/7] tools/fuzz: introduce x86 instruction emulator target"):

Quoted 9 lines · Jan Beulich
Quoted 5 lines
Quoted 2 lines · On 12.12.16 at 12:19, <[email protected]> wrote:

I mean "states". There are three states we need to reset.

Hmm, to me as a non-native speaker it feels wrong to use plural here (just like for e.g. milk), but maybe I'm wrong.

"State" is countable when used to represent the condition of somebody/something. Various other meanings of "state" don't apply here.

I think "three states" can only be used to mean three alternative possible values of the same variable. It cannot be used to mean three separate variables.

Quoted 6 lines

So "a state" is one of the possible values. You can also say something like "the system is in a broken state", but again, this refers to a specific state amongst all the possible different states.

"Reset all states" is really odd and could almost never be right.

David suggested "reset all state variables". That's what I have now.

Wei.

Quoted 1 line

Ian.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

author
#16 lore raw

Re: [PATCH v3 5/7] tools/fuzz: introduce x86 instruction emulator target

In reply to Jan Beulich
Quoted 66 lines · Jan Beulich
Quoted 53 lines
Quoted 1 line
Quoted 1 line · On 12.12.16 at 10:28, <[email protected]> wrote:

Instruction emulator fuzzing code is from code previous written by Andrew and George. Adapted to llvm fuzzer and hook up the build system.

---
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Tim Deegan <[email protected]>
Cc: Wei Liu <[email protected]>

v3:
1. coding style fix
2. share more code
3. exit when stack can't be made executable

---
 .gitignore                                         |   1 +
 tools/fuzz/x86_instruction_emulator/Makefile       |  31 ++++
 .../x86-insn-emulator-fuzzer.c                     | 195 +++++++++++++++++++++
 3 files changed, 227 insertions(+)
 create mode 100644 tools/fuzz/x86_instruction_emulator/Makefile
 create mode 100644 

tools/fuzz/x86_instruction_emulator/x86-insn-emulator-fuzzer.c

.gitignore +1 -0
index a2f34a1..d507243 100644
@@ -145,6 +145,7 @@ tools/flask/utils/flask-loadpolicy
 tools/flask/utils/flask-setenforce
 tools/flask/utils/flask-set-bool
 tools/flask/utils/flask-label-pci
+tools/fuzz/x86_instruction_emulator/x86_emulate*
 tools/helpers/_paths.h
 tools/helpers/init-xenstore-domain
 tools/helpers/xen-init-dom0
tools/fuzz/x86_instruction_emulator/Makefile new file +4 -0
new file mode 100644
index 0000000..2b147ac
@@ -0,0 +1,31 @@
+XEN_ROOT=$(CURDIR)/../../..
+include $(XEN_ROOT)/tools/Rules.mk
+
+x86-instruction-emulator-fuzzer-all: x86-insn-emulator.a x86-insn-emulator-fuzzer.o

tools/fuzz/x86_instruction_emulator/Makefile line 14

Quoted 10 lines
tools/fuzz/x86_instruction_emulator/Makefile new file +10 -0
+
+x86_emulate/x86_emulate.c x86_emulate/x86_emulate.h:
+	[ -L x86_emulate ] || ln -sf $(XEN_ROOT)/xen/arch/x86/x86_emulate .
+
+x86_emulate.c x86_emulate.h: %:
+	[ -L $* ] || ln -sf $(XEN_ROOT)/tools/tests/x86_emulator/$*
+
+CFLAGS += $(CFLAGS_xeninclude)
+
+x86_emulate.o: x86_emulate.c x86_emulate.h x86_emulate/x86_emulate.c x86_emulate/x86_emulate.h

Perhaps worthwhile shortening this to

Quoted 4 lines

x86_emulate.o: x86_emulate.[ch] x86_emulate/x86_emulate.[ch]

?

Ah, I thought this would work, but it doesn't. And I forgot to remove the old links when testing this.

Now in a clean build:

make[2]: *** No rule to make target 'x86_emulate.[ch]', needed by 'x86_emulate.o'. Stop.

So I guess I will stick with what I had before.

Wei.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#17 lore raw

Re: [PATCH v3 5/7] tools/fuzz: introduce x86 instruction emulator target

Quoted 77 lines
Quoted 1 line
Quoted 1 line · On 12.12.16 at 18:51, <[email protected]> wrote:
Quoted 17 lines · Jan Beulich
Quoted 17 lines
Quoted 1 line
Quoted 1 line · On 12.12.16 at 10:28, <[email protected]> wrote:

Instruction emulator fuzzing code is from code previous written by Andrew and George. Adapted to llvm fuzzer and hook up the build system.

---
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Tim Deegan <[email protected]>
Cc: Wei Liu <[email protected]>

Quoted 8 lines
Quoted 8 lines

v3:
1. coding style fix
2. share more code
3. exit when stack can't be made executable

---
 .gitignore                                         |   1 +
 tools/fuzz/x86_instruction_emulator/Makefile       |  31 ++++
 .../x86-insn-emulator-fuzzer.c                     | 195 

+++++++++++++++++++++

Quoted 41 lines
Quoted 28 lines
 3 files changed, 227 insertions(+)
 create mode 100644 tools/fuzz/x86_instruction_emulator/Makefile
 create mode 100644 

tools/fuzz/x86_instruction_emulator/x86-insn-emulator-fuzzer.c

.gitignore +1 -0
index a2f34a1..d507243 100644
@@ -145,6 +145,7 @@ tools/flask/utils/flask-loadpolicy
 tools/flask/utils/flask-setenforce
 tools/flask/utils/flask-set-bool
 tools/flask/utils/flask-label-pci
+tools/fuzz/x86_instruction_emulator/x86_emulate*
 tools/helpers/_paths.h
 tools/helpers/init-xenstore-domain
 tools/helpers/xen-init-dom0
tools/fuzz/x86_instruction_emulator/Makefile new file +4 -0
new file mode 100644
index 0000000..2b147ac
@@ -0,0 +1,31 @@
+XEN_ROOT=$(CURDIR)/../../..
+include $(XEN_ROOT)/tools/Rules.mk
+
+x86-instruction-emulator-fuzzer-all: x86-insn-emulator.a x86-insn-emulator-fuzzer.o

tools/fuzz/x86_instruction_emulator/Makefile line 14

Quoted 10 lines
tools/fuzz/x86_instruction_emulator/Makefile new file +10 -0
+
+x86_emulate/x86_emulate.c x86_emulate/x86_emulate.h:
+	[ -L x86_emulate ] || ln -sf $(XEN_ROOT)/xen/arch/x86/x86_emulate .
+
+x86_emulate.c x86_emulate.h: %:
+	[ -L $* ] || ln -sf $(XEN_ROOT)/tools/tests/x86_emulator/$*
+
+CFLAGS += $(CFLAGS_xeninclude)
+
+x86_emulate.o: x86_emulate.c x86_emulate.h x86_emulate/x86_emulate.c x86_emulate/x86_emulate.h

Perhaps worthwhile shortening this to

Quoted 4 lines

x86_emulate.o: x86_emulate.[ch] x86_emulate/x86_emulate.[ch]

?

Ah, I thought this would work, but it doesn't. And I forgot to remove the old links when testing this.

Quoted 6 lines

Now in a clean build:

make[2]: *** No rule to make target 'x86_emulate.[ch]', needed by 'x86_emulate.o'. Stop.

So I guess I will stick with what I had before.

Oh, right - I'm sorry for misleading you. Wildcards here would work only if the files existed, but there are rules to put them in place. No need to drop my R-b, btw.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#18 lore raw

Re: [PATCH v3 5/7] tools/fuzz: introduce x86 instruction emulator target

In reply to Wei Liu
Quoted 2 lines · Wei Liu

Instruction emulator fuzzing code is from code previous written by Andrew and George. Adapted to llvm fuzzer and hook up the build system.

Thanks for doing this, Wei.

The version you have is quite an early iteration -- attached is a patch containing the most recent version if you feel like updating it.

Long-term, it seems like being able to make the same code compile for AFL and for the oss-fuzz would be a good idea.

I'll probably take a look at it when I get back in January if you haven't done it by then.

Peace,
-George

From ea981c2a0970b1228f5c61b841f30381fa60b718 Mon Sep 17 00:00:00 2001
From: George Dunlap <[email protected]>
Date: Fri, 16 Dec 2016 08:59:56 +0000
Subject: [PATCH] AFL wrapper for the x86 emulator test harness.

Status:
* Fuzzes all gprs
* Inputs an arbitrary number of instructions and "memory reads"
* Fuzzes {addr,sp}_size
* Fuzzes segments
* Fuzzes key MSRs (making sure EFER.LMA acts 'magically')
* Fuzzes CR registers
* Fuzzes emulation hook presence / absence
* Fuzzes emulation hook failure

Limitations:
* FPU exceptions manually disabled every cycle

We also compile a version of the same binary with gcov so that we can get coverage testing for the AFL instances.

TODO:

- Make artificial tests for 1071, 1887, 2321 (based on previous coverage)
- Make artificial test for 5334
- Implement vmfunc
- Implement {read,write}_dr
- Implement SIGFPE handling

---
 tools/tests/x86_emulator/Makefile           |   50 +-
 tools/tests/x86_emulator/afl-crashreport.sh |    7 +
 tools/tests/x86_emulator/afl-fuzz-multi.sh  |   20 +
 tools/tests/x86_emulator/afl-gcov-find.sh   |   32 +
 tools/tests/x86_emulator/afl-gcov.sh        |   13 +
 tools/tests/x86_emulator/afl_x86_emulator.c | 1330 +++++++++++++++++++++++++++
 6 files changed, 1451 insertions(+), 1 deletion(-)
 create mode 100755 tools/tests/x86_emulator/afl-crashreport.sh
 create mode 100755 tools/tests/x86_emulator/afl-fuzz-multi.sh
 create mode 100755 tools/tests/x86_emulator/afl-gcov-find.sh
 create mode 100755 tools/tests/x86_emulator/afl-gcov.sh
 create mode 100644 tools/tests/x86_emulator/afl_x86_emulator.c
tools/tests/x86_emulator/Makefile +49 -1
index 13ace9a..8a66849 100644
@@ -32,7 +32,7 @@ $(TARGET): x86_emulate.o test_x86_emulator.o
 
 .PHONY: clean
 clean:
-	rm -rf $(TARGET) *.o *~ core blowfish.h blowfish.bin x86_emulate
+	rm -rf $(TARGET) *.o *.gcno *~ core blowfish.h blowfish.bin x86_emulate
 
 .PHONY: distclean
 distclean: clean
@@ -40,13 +40,61 @@ distclean: clean
 .PHONY: install
 install:
 
+.PHONY: afl-build
+afl-build: afl_x86_emulator afl_x86_emulator_gcov
+
+.PHONY: afl-fuzz
+afl-fuzz: afl-build
+	afl-fuzz -m none -t 1000 -i testcase_dir/ -o findings_dir/ -- ./afl_x86_emulator @@
+
+afl-fuzz-multi: afl-build
+	rm -rf sync_dir
+	xterm -geometry 80x25 -e "afl-fuzz -m none -t 1000 -i testcase_dir/ -o sync_dir/ -M f0:1/4 -- ./afl_x86_emulator @@" &
+	xterm -geometry 80x25 -e "afl-fuzz -m none -t 1000 -i testcase_dir/ -o sync_dir/ -M f1:2/4 -- ./afl_x86_emulator @@" &
+	xterm -geometry 80x25 -e "afl-fuzz -m none -t 1000 -i testcase_dir/ -o sync_dir/ -M f2:3/4 -- ./afl_x86_emulator @@" &
+	xterm -geometry 80x25 -e "afl-fuzz -m none -t 1000 -i testcase_dir/ -o sync_dir/ -M f3:4/4 -- ./afl_x86_emulator @@" &
+
+afl-gcov: afl_x86_emulator_gcov
+	rm -f *.gcda
+	for i in $(shell sync_dir -name "id*") ; do \
+		echo \$i ;\
+		./afl_x86_emulator_gcov $i > /dev/null ; \
+	done
+	gcov x86_emulator_gcov
+
 x86_emulate/x86_emulate.c x86_emulate/x86_emulate.h:
 	[ -L x86_emulate ] || ln -sf $(XEN_ROOT)/xen/arch/x86/x86_emulate .
 
 HOSTCFLAGS += $(CFLAGS_xeninclude)
 
+AFLCC=$(shell which afl-gcc)
+
+GCOVFLAGS=--coverage
+
+afl_x86_emulator: x86_emulate_afl.o afl_x86_emulator_afl.o
+	[ -n "$(AFLCC)" ] || (echo "Couldn't find afl-gcc" && false)
+	AFL_HARDEN=1 $(AFLCC) -o $@ $^
+
+afl_x86_emulator_gcov: x86_emulate_gcov.o afl_x86_emulator_gcov.o
+	$(HOSTCC) $(GCOVFLAGS) -o $@ $^
+
 x86_emulate.o: x86_emulate.c x86_emulate/x86_emulate.c x86_emulate/x86_emulate.h
 	$(HOSTCC) $(HOSTCFLAGS) -c -g -o $@ $<
 
+x86_emulate_afl.o: x86_emulate.c x86_emulate/x86_emulate.c x86_emulate/x86_emulate.h
+	[ -n "$(AFLCC)" ] || (echo "Couldn't find afl-gcc" && false)
+	AFL_HARDEN=1 $(AFLCC) $(HOSTCFLAGS) -c -g -o $@ $<
+
+x86_emulate_gcov.o: x86_emulate.c x86_emulate/x86_emulate.c x86_emulate/x86_emulate.h
+	$(HOSTCC) $(HOSTCFLAGS) -c -g $(GCOVFLAGS) -o $@ $<
+
 test_x86_emulator.o: test_x86_emulator.c blowfish.h x86_emulate/x86_emulate.h
 	$(HOSTCC) $(HOSTCFLAGS) -c -g -o $@ $<
+
+afl_x86_emulator_afl.o: afl_x86_emulator.c x86_emulate/x86_emulate.h
+	[ -n "$(AFLCC)" ] || (echo "Couldn't find afl-gcc" && false)
+	AFL_HARDEN=1 $(AFLCC) $(HOSTCFLAGS) -c -g -o $@ $<
+
+afl_x86_emulator_gcov.o: afl_x86_emulator.c x86_emulate/x86_emulate.h
+	$(HOSTCC) $(HOSTCFLAGS) -c -g $(GCOVFLAGS) -o $@ $<
+
tools/tests/x86_emulator/afl-crashreport.sh new file +7 -0
new file mode 100755
index 0000000..b8dca63
@@ -0,0 +1,7 @@
+#!/bin/bash
+
+(for i in sync_dir/*/crashes/id:* findings_dir/crashes/id:* ; do 
+     echo $i  ;
+     gdb --batch --eval-command run --eval-command where --args ./afl_x86_emulator $i ;
+     echo ; echo ;
+done) >& crash-report.txt
tools/tests/x86_emulator/afl-fuzz-multi.sh new file +20 -0
new file mode 100755
index 0000000..beccc69
@@ -0,0 +1,20 @@
+#!/bin/bash
+cpus=$(ls -l /sys/devices/system/cpu | grep "cpu[0-9]\+" | wc -l)
+afl_params="-m none -t 1000"
+syncdir=/tmp/sync
+if [[ -z "$cpus" ]] ; then
+    echo "Couldn't get cpu count"
+    exit 1
+fi
+echo "Counted $cpus cpus"
+rm -rf $syncdir
+mkdir -p $syncdir
+i=2
+while [[ "$i" -le "$cpus" ]] ; do
+    echo "afl-fuzz $afl_params -i testcase_dir/ -o $syncdir -M f${i}:${i}/${cpus} -- ./afl_x86_emulator >& $syncdir/f${i}.out"
+    afl-fuzz $afl_params -i testcase_dir/ -o $syncdir -M f${i}:${i}/${cpus} -- ./afl_x86_emulator >& $syncdir/f${i}.out &
+    i=$(($i+1))
+done
+afl-fuzz $afl_params -i testcase_dir/ -o $syncdir -M f1:1/${cpus} -- ./afl_x86_emulator
+echo "Killing all afl workers..."
+killall afl-fuzz
tools/tests/x86_emulator/afl-gcov-find.sh new file +32 -0
new file mode 100755
index 0000000..ca48329
@@ -0,0 +1,32 @@
+#!/bin/bash
+line=$1
+verbose=false
+rm -f *.gcda
+for i in sync_dir/*/queue/id:* findings_dir/queue/id:* ; do 
+    $verbose && echo -n "Checking $i... "
+    rm -f *.gcda
+    ./afl_x86_emulator_gcov $i > /tmp/afl-gcov-find-out.txt
+    gcov x86_emulate_gcov >& /dev/null
+    count=$(perl -ne "if(/ *([0-9-#]*): *$1:/) { print \$1; exit 0; }" x86_emulate.c.gcov)
+    case $count in
+	"-")
+	    echo "Line $line is not an executable line!"
+	    exit 1
+	    ;;
+	"#####")
+	    $verbose && echo "No"
+	    ;;
+	[0-9]*)
+	    if $verbose ; then
+		echo "Yes"
+	    else
+		echo "$i"
+		cat /tmp/afl-gcov-find-out.txt
+	    fi
+	    ;;
+	*)
+	    echo "Unexpected result: $count"
+	    exit 1
+	    ;;
+    esac
+done
tools/tests/x86_emulator/afl-gcov.sh new file +13 -0
new file mode 100755
index 0000000..c571e1f
@@ -0,0 +1,13 @@
+#!/bin/bash
+rm -f *.gcda
+if [[ -e /tmp/sync ]] ; then
+    dir=/tmp/sync/$(ls /tmp/sync | head -1)
+else
+    dir=findings_dir
+fi
+
+for i in $dir/queue/id:* ; do 
+    echo $i ;
+    ./afl_x86_emulator_gcov $i >& /dev/null ; 
+done
+gcov -a x86_emulate_gcov
tools/tests/x86_emulator/afl_x86_emulator.c new file +1330 -0

1,330 lines not on this page · raw message

Signature · 1 line
2.1.4

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

author
#19 lore raw

PATCH v3 6/7 tools: hook up fuzz directory

In reply to Wei Liu

This will make all fuzzing targets get build every time tools directory is built. This serves as basic regression test.

---
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Tim Deegan <[email protected]>
Cc: Wei Liu <[email protected]>

---
 tools/Makefile      |  1 +
 tools/fuzz/Makefile | 11 +++++++++++
 2 files changed, 12 insertions(+)
 create mode 100644 tools/fuzz/Makefile
tools/Makefile +1 -0
index 71515b4..77e0723 100644
@@ -6,6 +6,7 @@ SUBDIRS-y += include
 SUBDIRS-y += libs
 SUBDIRS-y += libxc
 SUBDIRS-y += flask
+SUBDIRS-y += fuzz
 SUBDIRS-y += xenstore
 SUBDIRS-y += misc
 SUBDIRS-y += examples
tools/fuzz/Makefile new file +11 -0
new file mode 100644
index 0000000..ce00b82
@@ -0,0 +1,11 @@
+XEN_ROOT = $(CURDIR)/../..
+include $(XEN_ROOT)/tools/Rules.mk
+
+SUBDIRS-y :=
+SUBDIRS-y += libelf
+SUBDIRS-y += x86_instruction_emulator
+
+.PHONY: all clean distclean
+all clean distclean: %: subdirs-%
+
+install:
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
author
#20 lore raw

PATCH v3 7/7 tools/fuzz: add README

In reply to Wei Liu

---
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Tim Deegan <[email protected]>
Cc: Wei Liu <[email protected]>

---
 tools/fuzz/README | 39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)
 create mode 100644 tools/fuzz/README
tools/fuzz/README new file +39 -0
new file mode 100644
index 0000000..cf47bf6
@@ -0,0 +1,39 @@
+# OVERVIEW
+
+This directory provides fuzzing targets to be run inside Google
+oss-fuzz infrastructure.
+
+See also https://github.com/google/oss-fuzz.
+
+# HOW IT WORKS
+
+We need to provide the source code and the rune to produce objects or
+archives (artefacts) from source code. These items ideally should live
+inside xen.git so that they can be kept up to date.
+
+The artefacts contain all the code we wish to fuzz and a function
+called LLVMFuzzerTestOneInput. LLVMFuzzerTestOneInput is the entry
+point to the code we wish to fuzz. Note that we don't produce
+executable programs because we don't have libFuzzEngine
+locally. libFuzzEngine is maintained by oss-fuzz.
+
+We also provide build script to oss-fuzz. The build script will
+inherit the correct compiler settings and be run in a pre-setup
+environment, which has libFuzzEngine installed. The build script is
+responsible for calling the correct Xen build rune to produce the
+artefacts, then link them against libFuzzEngine to produce
+executables, which will run in oss-fuzz infrastructure.
+
+Please refer to official oss-fuzz documents for the most up-to-date
+descriptions for all moving parts.
+
+# HOW TO IMPROVE THE FUZZING TARGETS
+
+Feel free to modify each fuzzing targets at will. Make sure they build
+by invoking make as you would build tools.
+
+To actually test the new code, you would need to run the target in
+standalone mode, please refer to oss-fuzz documents on how to do that.
+
+It is highly recommended that you run the new target for a while to
+weed out error in plumbing code to avoid false positives.
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel