Skip to contentSkip to conversation

Fuzzing targets for oss-fuzz

RFC PATCH Superseded Wei Liu 2 participants 17 messages Dec 8, 2016 – Dec 9, 2016

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Wei Liu

author
#0 lore raw

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.

The fuzzing targets aren't very sophiscated at the moment. The purpose of this series is to gather feedback at this early stage.

We can always improve the fuzzing code in the future.

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 (5):
libelf: don't always include libxc headers tools/fuzz: introduce libelf target 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                                  |   7 +
 tools/fuzz/libelf/Makefile                         |  31 ++
 tools/fuzz/libelf/libelf-fuzzer.c                  |  32 ++
 tools/fuzz/x86_instruction_emulator/Makefile       |  33 ++
 .../x86-insn-emulator-fuzzer.c                     | 335 +++++++++++++++++++++
 xen/common/libelf/libelf-private.h                 |   2 +
 9 files changed, 453 insertions(+)
 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

RFC PATCH 1/5 libelf: don't always include libxc headers

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]>

---
 xen/common/libelf/libelf-private.h | 2 ++
 1 file changed, 2 insertions(+)
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
#2 lore raw

Re: [PATCH VERY RFC 1/5] libelf: don't always include libxc headers

xen/common/libelf/libelf-private.h line 78

Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 08.12.16 at 14:54, <[email protected]> wrote:
xen/common/libelf/libelf-private.h +2 -0
@@ -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

If put in together with patch 2 (which I think it should really be part of) this can have my ack; I don't think it makes sense to put in on its own.

Jan

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

author
#3 lore raw

RFC PATCH 2/5 tools/fuzz: introduce libelf target

In reply to Wei Liu

A simple program and Makefile to fuzz libelf in Google's oss-fuzz infrastructure.

---
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 ++++++++++++++++++++++++++++++++
 2 files changed, 63 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:
+ */
Signature · 7 lines
2.1.4


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

Re: [PATCH VERY RFC 2/5] tools/fuzz: introduce libelf target

Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 08.12.16 at 14:54, <[email protected]> wrote:

A simple program and Makefile to fuzz libelf in Google's oss-fuzz infrastructure.

Mind adding some description here on how this is expected to work / be used? The new Makefile produce an object file and an archive, but no binary, so it's not clear to me what use this is.

Jan

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

author
#5 lore raw

Re: [PATCH VERY RFC 2/5] tools/fuzz: introduce libelf target

Quoted 8 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 08.12.16 at 14:54, <[email protected]> wrote:

A simple program and Makefile to fuzz libelf in Google's oss-fuzz infrastructure.

Mind adding some description here on how this is expected to work / be used? The new Makefile produce an object file and an archive, but no binary, so it's not clear to me what use this is.

Sure, I can elaborate more on this in the README file.

Wei.

Quoted 2 lines

Jan

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

author
#6 lore raw

RFC PATCH 3/5 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]>

---
 .gitignore                                         |   1 +
 tools/fuzz/x86_instruction_emulator/Makefile       |  33 ++
 .../x86-insn-emulator-fuzzer.c                     | 335 +++++++++++++++++++++
 3 files changed, 369 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 +33 -0
new file mode 100644
index 0000000..374c84a
@@ -0,0 +1,33 @@
+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:
+	[ -L x86_emulate.c ] || ln -sf $(XEN_ROOT)/tools/tests/x86_emulator/x86_emulate.c
+
+x86_emulate.h:
+	[ -L x86_emulate.h ] || ln -sf $(XEN_ROOT)/tools/tests/x86_emulator/x86_emulate.h
+
+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
+
+.PHONY: clean
+clean:
+	rm -f *.a *.o
tools/fuzz/x86_instruction_emulator/x86-insn-emulator-fuzzer.c new file +335 -0

335 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
#7 lore raw

Re: [PATCH VERY RFC 3/5] tools/fuzz: introduce x86 instruction emulator target

Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 08.12.16 at 14:54, <[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.

With this, how much of the new code could be shared between Google's fuzzer and AFL, for which George had put this together originally afaik? Or are we now no longer planning on having an AFL target?

Quoted 6 lines
tools/fuzz/x86_instruction_emulator/Makefile new file +3 -0
@@ -0,0 +1,33 @@
+XEN_ROOT=$(CURDIR)/../../..
+include $(XEN_ROOT)/tools/Rules.mk
+

tools/fuzz/x86_instruction_emulator/Makefile line 13

Quoted 10 lines
tools/fuzz/x86_instruction_emulator/Makefile new file +10 -0
+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:
+	[ -L x86_emulate.c ] || ln -sf $(XEN_ROOT)/tools/tests/x86_emulator/x86_emulate.c
+
+x86_emulate.h:
+	[ -L x86_emulate.h ] || ln -sf $(XEN_ROOT)/tools/tests/x86_emulator/x86_emulate.h

I think these two could easily be a single (pattern) rule, with (slightly unusually) the file extension being the stem.

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

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

Quoted 10 lines
tools/fuzz/x86_instruction_emulator/x86-insn-emulator-fuzzer.c new file +10 -0
+#include <xen/xen.h>
+#include <unistd.h>
+#include <assert.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <sys/mman.h>
+
+#define __packed __attribute__((packed))
+#define ASSERT assert

This should not be needed anymore if you included ...

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

Quoted 1 line
tools/fuzz/x86_instruction_emulator/x86-insn-emulator-fuzzer.c new file +1 -0
+#include "x86_emulate/x86_emulate.h"

"x86_emulate.h" instead. And __packed, if its really needed, should then also be added to that header.

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

Quoted 8 lines
tools/fuzz/x86_instruction_emulator/x86-insn-emulator-fuzzer.c new file +8 -0
+/* EFLAGS bit definitions. */
+#define EFLG_OF (1<<11)
+#define EFLG_DF (1<<10)
+#define EFLG_SF (1<<7)
+#define EFLG_ZF (1<<6)
+#define EFLG_AF (1<<4)
+#define EFLG_PF (1<<2)
+#define EFLG_CF (1<<0)

These appear to be unused.

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

Quoted 6 lines
tools/fuzz/x86_instruction_emulator/x86-insn-emulator-fuzzer.c new file +6 -0
+static unsigned char data[4096];
+static unsigned int data_index = 0;
+static unsigned int data_max;
+
+int data_read(const char *why, void *dst, unsigned int bytes) {
+

static? And the brace put on the otherwise stray blank line.

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

Quoted 1 line
tools/fuzz/x86_instruction_emulator/x86-insn-emulator-fuzzer.c new file +1 -0
+static int emul_read(

May I suggest to prefix all of these fuzz_ instead of emul_?

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

Quoted 5 lines
tools/fuzz/x86_instruction_emulator/x86-insn-emulator-fuzzer.c new file +5 -0
+#define cpu_has_sse2 ({ \
+    unsigned int eax = 1, ecx = 0, edx; \
+    emul_cpuid(&eax, &ecx, &ecx, &edx, NULL); \
+    (edx & (1U << 26)) != 0; \
+})

This appears to be unused again.

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

Quoted 11 lines
tools/fuzz/x86_instruction_emulator/x86-insn-emulator-fuzzer.c new file +11 -0
+#define cpu_has_avx2 ({ \
+    unsigned int eax = 1, ebx, ecx = 0; \
+    emul_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; \
+})

Same here.

Quoted 10 lines
tools/fuzz/x86_instruction_emulator/x86-insn-emulator-fuzzer.c new file +10 -0
+static int emul_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 */

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

Quoted 10 lines
tools/fuzz/x86_instruction_emulator/x86-insn-emulator-fuzzer.c new file +10 -0
+        return X86EMUL_OKAY;
+
+    case 4:
+        /* OSFXSR, OSXMMEXCPT, and maybe OSXSAVE */
+        *val = 0x00000600 | (cpu_has_xsave ? 0x00040000 : 0);
+        return X86EMUL_OKAY;
+    }
+
+    return X86EMUL_UNHANDLEABLE;
+}

Looks suspiciously similar to existing code. We may want to share such stuff, to avoid having to update it in multiple places.

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

Quoted 1 line
tools/fuzz/x86_instruction_emulator/x86-insn-emulator-fuzzer.c new file +1 -0
+int emul_get_fpu(

static?

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

Quoted 1 line
tools/fuzz/x86_instruction_emulator/x86-insn-emulator-fuzzer.c new file +1 -0
+struct x86_emulate_ops emulops = {

again

Quoted 13 lines
tools/fuzz/x86_instruction_emulator/x86-insn-emulator-fuzzer.c new file +13 -0
+bool make_stack_executable(void) {
+    unsigned long sp;
+    bool stack_exec;
+
+    /*
+     * Mark the entire stack executable so that the stub executions
+     * don't fault
+     */
+#define MMAP_SZ 16384
+
+#ifdef __x86_64__
+    asm ("movq %%rsp, %0" : "=g" (sp));
+#else

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

Quoted 10 lines
tools/fuzz/x86_instruction_emulator/x86-insn-emulator-fuzzer.c new file +10 -0
+    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;
+    if ( !stack_exec )
+        printf("Warning: Stack could not be made executable (%d).\n", errno);
+
+    return stack_exec;
+}

This too looks like it would want sharing.

Jan

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

author
#8 lore raw

Re: [PATCH VERY RFC 3/5] tools/fuzz: introduce x86 instruction emulator target

Quoted 8 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 08.12.16 at 14:54, <[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.

With this, how much of the new code could be shared between Google's fuzzer and AFL, for which George had put this together originally afaik? Or are we now no longer planning on having an AFL target?

We could share the majority of the code. I started by stripping unused code in their patch (and as you already saw, not quite complete yet).

When Google oss-fuzz supports AFL, we can easily add that support in. Ultimately it is only the entry function is a bit different. All the stub functions should work the same.

Regarding all comments below, I will fix them all together in the next round.

Wei.

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

author
#9 lore raw

Re: [PATCH VERY RFC 3/5] tools/fuzz: introduce x86 instruction emulator target

In reply to Jan Beulich

On Thu, Dec 08, 2016 at 08:03:04AM -0700, Jan Beulich wrote:
[...]

Quoted 16 lines
Quoted 16 lines
tools/fuzz/x86_instruction_emulator/x86-insn-emulator-fuzzer.c new file +15 -0
+static int emul_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);
Quoted 9 lines

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

Quoted 5 lines
tools/fuzz/x86_instruction_emulator/x86-insn-emulator-fuzzer.c new file +5 -0
+        return X86EMUL_OKAY;
+    }
+
+    return X86EMUL_UNHANDLEABLE;
+}

Looks suspiciously similar to existing code. We may want to share such stuff, to avoid having to update it in multiple places.

Share with what? Do you mean the real emulator code?

Wei.

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

#10 lore raw

Re: [PATCH VERY RFC 3/5] tools/fuzz: introduce x86 instruction emulator target

Quoted 28 lines
Quoted 1 line
Quoted 1 line · On 08.12.16 at 18:25, <[email protected]> wrote:

On Thu, Dec 08, 2016 at 08:03:04AM -0700, Jan Beulich wrote:
[...]

Quoted 16 lines
Quoted 16 lines
tools/fuzz/x86_instruction_emulator/x86-insn-emulator-fuzzer.c new file +15 -0
+static int emul_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);
Quoted 8 lines

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

Quoted 5 lines
tools/fuzz/x86_instruction_emulator/x86-insn-emulator-fuzzer.c new file +5 -0
+        return X86EMUL_OKAY;
+    }
+
+    return X86EMUL_UNHANDLEABLE;
+}

Looks suspiciously similar to existing code. We may want to share such stuff, to avoid having to update it in multiple places.

Quoted 1 line

Share with what? Do you mean the real emulator code?

The real emulator test code, yes.

Jan

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

author
#11 lore raw

Re: [PATCH VERY RFC 3/5] tools/fuzz: introduce x86 instruction emulator target

Quoted 28 lines · Jan Beulich
Quoted 28 lines
Quoted 1 line
Quoted 1 line · On 08.12.16 at 18:25, <[email protected]> wrote:

On Thu, Dec 08, 2016 at 08:03:04AM -0700, Jan Beulich wrote:
[...]

Quoted 24 lines
Quoted 11 lines
tools/fuzz/x86_instruction_emulator/x86-insn-emulator-fuzzer.c new file +10 -0
+static int emul_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 */

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

Quoted 10 lines
tools/fuzz/x86_instruction_emulator/x86-insn-emulator-fuzzer.c new file +10 -0
+        return X86EMUL_OKAY;
+
+    case 4:
+        /* OSFXSR, OSXMMEXCPT, and maybe OSXSAVE */
+        *val = 0x00000600 | (cpu_has_xsave ? 0x00040000 : 0);
+        return X86EMUL_OKAY;
+    }
+
+    return X86EMUL_UNHANDLEABLE;
+}

Looks suspiciously similar to existing code. We may want to share such stuff, to avoid having to update it in multiple places.

Quoted 4 lines
Quoted 1 line

Share with what? Do you mean the real emulator code?

The real emulator test code, yes.

OK. I will refactor the code a bit. Let's start with sharing the two places you point out and make further improvements as we go along.

Wei.

Quoted 2 lines

Jan

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

author
#12 lore raw

Re: [PATCH VERY RFC 3/5] tools/fuzz: introduce x86 instruction emulator target

In reply to Jan Beulich
Quoted 20 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 08.12.16 at 14:54, <[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.

With this, how much of the new code could be shared between Google's fuzzer and AFL, for which George had put this together originally afaik? Or are we now no longer planning on having an AFL target?

Quoted 11 lines
tools/fuzz/x86_instruction_emulator/Makefile new file +8 -0
@@ -0,0 +1,33 @@
+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 .
+
Quoted 8 lines

tools/fuzz/x86_instruction_emulator/Makefile line 13

Quoted 5 lines
tools/fuzz/x86_instruction_emulator/Makefile new file +5 -0
+x86_emulate.c:
+	[ -L x86_emulate.c ] || ln -sf $(XEN_ROOT)/tools/tests/x86_emulator/x86_emulate.c
+
+x86_emulate.h:
+	[ -L x86_emulate.h ] || ln -sf $(XEN_ROOT)/tools/tests/x86_emulator/x86_emulate.h

I think these two could easily be a single (pattern) rule, with (slightly unusually) the file extension being the stem.

I think it is better to have them explicitly spelled out, because using something like

x86_emulate.%:

	[ -L x86_emulate.$* ] || ln -sf $(XEN_ROOT)/tools/tests/x86_emulator/x86_emulate.$*

would cause the x86_emulate.o compiled in tools/tests/x86_emulator be linked here, too, due to another rule we have:

x86_emulate.o: x86_emulate.c x86_emulate.h x86_emulate/x86_emulate.c x86_emulate/x86_emulate.h

Please let me know if you have some other ideas to deal with this.

Wei.

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

#13 lore raw

Re: [PATCH VERY RFC 3/5] tools/fuzz: introduce x86 instruction emulator target

Quoted 34 lines
Quoted 1 line
Quoted 1 line · On 08.12.16 at 18:57, <[email protected]> wrote:
Quoted 20 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 08.12.16 at 14:54, <[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.

With this, how much of the new code could be shared between Google's fuzzer and AFL, for which George had put this together originally afaik? Or are we now no longer planning on having an AFL target?

Quoted 11 lines
tools/fuzz/x86_instruction_emulator/Makefile new file +8 -0
@@ -0,0 +1,33 @@
+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 .
+
Quoted 8 lines

tools/fuzz/x86_instruction_emulator/Makefile line 13

Quoted 5 lines
tools/fuzz/x86_instruction_emulator/Makefile new file +5 -0
+x86_emulate.c:
+	[ -L x86_emulate.c ] || ln -sf $(XEN_ROOT)/tools/tests/x86_emulator/x86_emulate.c
+
+x86_emulate.h:
+	[ -L x86_emulate.h ] || ln -sf $(XEN_ROOT)/tools/tests/x86_emulator/x86_emulate.h

I think these two could easily be a single (pattern) rule, with (slightly unusually) the file extension being the stem.

I think it is better to have them explicitly spelled out, because using something like

Quoted 8 lines

x86_emulate.%:

	[ -L x86_emulate.$* ] || ln -sf $(XEN_ROOT)/tools/tests/x86_emulator/x86_emulate.$*

would cause the x86_emulate.o compiled in tools/tests/x86_emulator be linked here, too, due to another rule we have:

x86_emulate.o: x86_emulate.c x86_emulate.h x86_emulate/x86_emulate.c x86_emulate/x86_emulate.h

Good point.

Quoted 1 line

Please let me know if you have some other ideas to deal with this.

A static pattern rule may then still be better than repeating the same thing twice (and later perhaps even more often, i.e. once we gain shared helper routine source/header files):

x86_emulate.c x86_emulate.h: %:

	[ -L $* ] || ln -sf $(XEN_ROOT)/tools/tests/x86_emulator/$*

Jan

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

author
#14 lore raw

Re: [PATCH VERY RFC 3/5] tools/fuzz: introduce x86 instruction emulator target

Quoted 45 lines · Jan Beulich
Quoted 34 lines
Quoted 1 line
Quoted 1 line · On 08.12.16 at 18:57, <[email protected]> wrote:
Quoted 20 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 08.12.16 at 14:54, <[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.

With this, how much of the new code could be shared between Google's fuzzer and AFL, for which George had put this together originally afaik? Or are we now no longer planning on having an AFL target?

Quoted 11 lines
tools/fuzz/x86_instruction_emulator/Makefile new file +8 -0
@@ -0,0 +1,33 @@
+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 .
+
Quoted 8 lines

tools/fuzz/x86_instruction_emulator/Makefile line 13

Quoted 5 lines
tools/fuzz/x86_instruction_emulator/Makefile new file +5 -0
+x86_emulate.c:
+	[ -L x86_emulate.c ] || ln -sf $(XEN_ROOT)/tools/tests/x86_emulator/x86_emulate.c
+
+x86_emulate.h:
+	[ -L x86_emulate.h ] || ln -sf $(XEN_ROOT)/tools/tests/x86_emulator/x86_emulate.h

I think these two could easily be a single (pattern) rule, with (slightly unusually) the file extension being the stem.

I think it is better to have them explicitly spelled out, because using something like

Quoted 8 lines

x86_emulate.%:

	[ -L x86_emulate.$* ] || ln -sf $(XEN_ROOT)/tools/tests/x86_emulator/x86_emulate.$*

would cause the x86_emulate.o compiled in tools/tests/x86_emulator be linked here, too, due to another rule we have:

x86_emulate.o: x86_emulate.c x86_emulate.h x86_emulate/x86_emulate.c x86_emulate/x86_emulate.h

Good point.

Quoted 9 lines
Quoted 1 line

Please let me know if you have some other ideas to deal with this.

A static pattern rule may then still be better than repeating the same thing twice (and later perhaps even more often, i.e. once we gain shared helper routine source/header files):

x86_emulate.c x86_emulate.h: %:

	[ -L $* ] || ln -sf $(XEN_ROOT)/tools/tests/x86_emulator/$*

This is a good idea. I've made the change to my code.

Wei.

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

author
#15 lore raw

RFC PATCH 4/5 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
#16 lore raw

RFC PATCH 5/5 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 | 7 +++++++
 1 file changed, 7 insertions(+)
 create mode 100644 tools/fuzz/README
tools/fuzz/README new file +7 -0
new file mode 100644
index 0000000..6e4d4bb
@@ -0,0 +1,7 @@
+This directory provides fuzzing targets to be run inside Google
+oss-fuzz infrastructure.
+
+See also https://github.com/google/oss-fuzz.
+
+To run each fuzzing target in standalone mode, please refer to
+oss-fuzz documents.
Signature · 7 lines
2.1.4


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