Skip to contentSkip to conversation

fuzz: basic AFL support

PATCH Superseded Wei Liu 7 participants 24 messages Jan 20, 2017 – Jan 25, 2017

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Wei Liu

author
#0 lore raw

cover fuzz: basic AFL support

Provide simple stub programs for AFL fuzzer. For usage, please see README.afl.

This series doesn't aim to improve fuzzing targets. It is just demonstration for how we could use the same fuzzing code for both oss-fuzz and AFL.

The stub programs are identical in libefl and x86 emulator at the moment, but they will likely diverge in the future. The duplication of code is deliberate.

Julien, FYI I think the in-tree libfdt could have something similar, too.

Wei.

Cc Andrew Cooper <[email protected]>
Cc George Dunlap <[email protected]>
Cc Ian Jackson <[email protected]>
Cc Jan Beulich <[email protected]>
Cc Julien Grall <[email protected]>

Wei Liu (4):
tools/fuzz: add missing dependency in x86 insn fuzzer build rule tools/fuzz: add AFL stub program for x86 insn emulator fuzzer tools/fuzz: add AFL stub program for libefl fuzzer tools/fuzz: add README.afl

 .gitignore                                         |  2 ++
 tools/fuzz/README.afl                              | 27 ++++++++++++++
 tools/fuzz/{README => README.oss-fuzz}             |  0
 tools/fuzz/libelf/Makefile                         |  7 +++-
 tools/fuzz/libelf/afl-libelf-fuzzer.c              | 42 ++++++++++++++++++++++
 tools/fuzz/x86_instruction_emulator/Makefile       | 11 ++++--
 .../afl-x86-insn-emulator-fuzzer.c                 | 42 ++++++++++++++++++++++
 7 files changed, 128 insertions(+), 3 deletions(-)
 create mode 100644 tools/fuzz/README.afl
 rename tools/fuzz/{README => README.oss-fuzz} (100%)
 create mode 100644 tools/fuzz/libelf/afl-libelf-fuzzer.c
 create mode 100644 tools/fuzz/x86_instruction_emulator/afl-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 1/4 tools/fuzz: add missing dependency in x86 insn fuzzer build rule

The said file needs the two header files.

---
Cc: Ian Jackson <[email protected]>

---
 tools/fuzz/x86_instruction_emulator/Makefile | 2 ++
 1 file changed, 2 insertions(+)
tools/fuzz/x86_instruction_emulator/Makefile +2 -0
index 1777bf6..6aef3a7 100644
@@ -18,6 +18,8 @@ CFLAGS += $(CFLAGS_xeninclude) -D__XEN_TOOLS__
 
 x86_emulate.o: x86_emulate.c x86_emulate.h x86_emulate/x86_emulate.c x86_emulate/x86_emulate.h
 
+x86-insn-emulator-fuzzer.o: x86_emulate.h x86_emulate/x86_emulate.h
+
 x86-insn-emulator.a: x86_emulate.o
 	$(AR) rc $@ $^
 
Signature · 7 lines
2.1.4


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

PATCH 2/4 tools/fuzz: add AFL stub program for x86 insn emulator fuzzer

In reply to Wei Liu

This is a basic program to call into the unified fuzzing function.

Hook it up into build system so that we can always build test it.

---
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>

---
 .gitignore                                         |  1 +
 tools/fuzz/x86_instruction_emulator/Makefile       |  9 +++--
 .../afl-x86-insn-emulator-fuzzer.c                 | 42 ++++++++++++++++++++++
 3 files changed, 50 insertions(+), 2 deletions(-)
 create mode 100644 tools/fuzz/x86_instruction_emulator/afl-x86-insn-emulator-fuzzer.c
.gitignore +1 -0
index 7689596..881e7cb 100644
@@ -147,6 +147,7 @@ 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/fuzz/x86_instruction_emulator/afl-x86-insn-emulator-fuzzer
 tools/helpers/_paths.h
 tools/helpers/init-xenstore-domain
 tools/helpers/xen-init-dom0
tools/fuzz/x86_instruction_emulator/Makefile +7 -2
index 6aef3a7..2d1ff78 100644
@@ -3,7 +3,7 @@ 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
+x86-instruction-emulator-fuzzer-all: x86-insn-emulator.a x86-insn-emulator-fuzzer.o afl
 else
 x86-instruction-emulator-fuzzer-all:
 endif
@@ -23,6 +23,8 @@ x86-insn-emulator-fuzzer.o: x86_emulate.h x86_emulate/x86_emulate.h
 x86-insn-emulator.a: x86_emulate.o
 	$(AR) rc $@ $^
 
+afl-x86-insn-emulator-fuzzer: afl-x86-insn-emulator-fuzzer.o x86-insn-emulator-fuzzer.o x86_emulate.o
+
 # Common targets
 .PHONY: all
 all: x86-instruction-emulator-fuzzer-all
@@ -33,7 +35,10 @@ distclean: clean
 
 .PHONY: clean
 clean:
-	rm -f *.a *.o
+	rm -f *.a *.o afl-x86-insn-emulator-fuzzer
 
 .PHONY: install
 install: all
+
+.PHONY: afl
+afl: afl-x86-insn-emulator-fuzzer
tools/fuzz/x86_instruction_emulator/afl-x86-insn-emulator-fuzzer.c new file +42 -0

42 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 v1 2/4
#3 lore raw

Re: [PATCH 2/4] tools/fuzz: add AFL stub program for x86 insn emulator fuzzer

tools/fuzz/x86_instruction_emulator/Makefile distclean: clean · line 38

Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 20.01.17 at 13:11, <[email protected]> wrote:
tools/fuzz/x86_instruction_emulator/Makefile +1 -1
@@ -33,7 +35,10 @@ distclean: clean
 
 .PHONY: clean
 clean:
-	rm -f *.a *.o
+	rm -f *.a *.o afl-x86-insn-emulator-fuzzer

Perhaps *-x86-insn-emulator-fuzzer right away?

Quoted 23 lines
tools/fuzz/x86_instruction_emulator/afl-x86-insn-emulator-fuzzer.c new file +20 -0
@@ -0,0 +1,42 @@
+#include <assert.h>
+#include <fcntl.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+extern int LLVMFuzzerTestOneInput(const uint8_t *data_p, size_t size);
+
+static uint8_t input[4096];
+
+int main(int argc, char **argv)
+{
+    size_t size;
+    int fd;
+
+    if ( argc != 2 )
+    {

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

Quoted 10 lines
tools/fuzz/x86_instruction_emulator/afl-x86-insn-emulator-fuzzer.c new file +10 -0
+        printf("Expecting only one argument\n");
+        exit(1);
+    }
+
+    fd = open(argv[1], O_RDONLY, 0);
+    assert(fd != -1);
+    size = read(fd, input, sizeof(input));
+    close(fd);
+
+    LLVMFuzzerTestOneInput(input, size);

Please handle the case of read() failing (at least in the same way as you do for open()). With that

Jan

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

author
#4 lore raw

Re: [PATCH 2/4] tools/fuzz: add AFL stub program for x86 insn emulator fuzzer

Quoted 10 lines · Jan Beulich

tools/fuzz/x86_instruction_emulator/Makefile distclean: clean · line 38

Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 20.01.17 at 13:11, <[email protected]> wrote:
tools/fuzz/x86_instruction_emulator/Makefile +1 -1
@@ -33,7 +35,10 @@ distclean: clean
 
 .PHONY: clean
 clean:
-	rm -f *.a *.o
+	rm -f *.a *.o afl-x86-insn-emulator-fuzzer

Perhaps *-x86-insn-emulator-fuzzer right away?

OK.

Quoted 28 lines
Quoted 28 lines
tools/fuzz/x86_instruction_emulator/afl-x86-insn-emulator-fuzzer.c new file +25 -0
@@ -0,0 +1,42 @@
+#include <assert.h>
+#include <fcntl.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+extern int LLVMFuzzerTestOneInput(const uint8_t *data_p, size_t size);
+
+static uint8_t input[4096];
+
+int main(int argc, char **argv)
+{
+    size_t size;
+    int fd;
+
+    if ( argc != 2 )
+    {
+        printf("Expecting only one argument\n");
+        exit(1);
+    }
+
+    fd = open(argv[1], O_RDONLY, 0);
Quoted 8 lines

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

Quoted 5 lines
tools/fuzz/x86_instruction_emulator/afl-x86-insn-emulator-fuzzer.c new file +5 -0
+    assert(fd != -1);
+    size = read(fd, input, sizeof(input));
+    close(fd);
+
+    LLVMFuzzerTestOneInput(input, size);

Please handle the case of read() failing (at least in the same way as you do for open()). With that

OK. I change size to be ssize_t and then assert(size != -1) after read().

Quoted 2 lines

Thanks for reviewing.

Quoted 2 lines

Jan

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

#5 lore raw

Re: [PATCH 2/4] tools/fuzz: add AFL stub program for x86 insn emulator fuzzer

In reply to Wei Liu

Wei Liu writes ("[PATCH 2/4] tools/fuzz: add AFL stub program for x86 insn emulator fuzzer"):

Quoted 1 line

This is a basic program to call into the unified fuzzing function.

...

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

Quoted 3 lines
tools/fuzz/x86_instruction_emulator/afl-x86-insn-emulator-fuzzer.c new file +3 -0
+    fd = open(argv[1], O_RDONLY, 0);
+    assert(fd != -1);
+    size = read(fd, input, sizeof(input));

Why do you use open and read here rather than fopen and fread ?

If you use read you ought to put it in a loop to cope with potential partial reads.

Ian.

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

author
#6 lore raw

Re: [PATCH 2/4] tools/fuzz: add AFL stub program for x86 insn emulator fuzzer

Quoted 9 lines · Ian Jackson

Wei Liu writes ("[PATCH 2/4] tools/fuzz: add AFL stub program for x86 insn emulator fuzzer"):

Quoted 1 line

This is a basic program to call into the unified fuzzing function.

...

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

Quoted 3 lines
tools/fuzz/x86_instruction_emulator/afl-x86-insn-emulator-fuzzer.c new file +3 -0
+    fd = open(argv[1], O_RDONLY, 0);
+    assert(fd != -1);
+    size = read(fd, input, sizeof(input));

Why do you use open and read here rather than fopen and fread ?

No particular reason.

Quoted 3 lines

If you use read you ought to put it in a loop to cope with potential partial reads.

Does fread have better properties than read? I think to deal with short read we would need to stat the file to get actual size for both fread and read, right? If so I will just stick with read and put that in a loop.

Wei.

Quoted 1 line

Ian.

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

#7 lore raw

Re: [PATCH 2/4] tools/fuzz: add AFL stub program for x86 insn emulator fuzzer

Wei Liu writes ("Re: [PATCH 2/4] tools/fuzz: add AFL stub program for x86 insn emulator fuzzer"):

Quoted 5 lines · Ian Jackson
Quoted 2 lines

If you use read you ought to put it in a loop to cope with potential partial reads.

Does fread have better properties than read?

Yes. fread is not allowed to give a short read for no particular reason, nor to return with EINTR.

Quoted 2 lines

I think to deal with short read we would need to stat the file to get actual size for both fread and read, right?

No. In both cases, it is possible to detect whether a short read is due to EOF. With read, that would have to be in a loop. With fread you can test feof.

You don't need to test with stat unless you want to support files bigger than your static buffer.

I recommend you:
* use fopen and fread
* complain if fread filled the whole buffer, on the grounds that that means you may be ignoring a longer file than is supported
* check with feof or ferror that the short read was due to eof

Ian.

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

#8 lore raw

Re: [PATCH 2/4] tools/fuzz: add AFL stub program for x86 insn emulator fuzzer

Quoted 8 lines · Ian Jackson

Wei Liu writes ("Re: [PATCH 2/4] tools/fuzz: add AFL stub program for x86 insn emulator fuzzer"):

Quoted 4 lines · Ian Jackson
Quoted 2 lines

If you use read you ought to put it in a loop to cope with potential partial reads.

Does fread have better properties than read?

Yes. fread is not allowed to give a short read for no particular reason, nor to return with EINTR.

Quoted 8 lines
Quoted 2 lines

I think to deal with short read we would need to stat the file to get actual size for both fread and read, right?

No. In both cases, it is possible to detect whether a short read is due to EOF. With read, that would have to be in a loop. With fread you can test feof.

You don't need to test with stat unless you want to support files bigger than your static buffer.

It is expected that AFL data will eventually become longer than the fuzzer wishes. You should ignore extraneous data.

Also, remember that AFL prefers to pass data by pipe.

~Andrew

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

author
#9 lore raw

Re: [PATCH 2/4] tools/fuzz: add AFL stub program for x86 insn emulator fuzzer

Quoted 15 lines · Andrew Cooper
Quoted 14 lines · Ian Jackson

Wei Liu writes ("Re: [PATCH 2/4] tools/fuzz: add AFL stub program for x86 insn emulator fuzzer"):

Quoted 4 lines · Ian Jackson
Quoted 2 lines

If you use read you ought to put it in a loop to cope with potential partial reads.

Does fread have better properties than read?

Yes. fread is not allowed to give a short read for no particular reason, nor to return with EINTR.

Quoted 2 lines

I think to deal with short read we would need to stat the file to get actual size for both fread and read, right?

No. In both cases, it is possible to detect whether a short read is due to EOF. With read, that would have to be in a loop. With fread you can test feof.

Quoted 6 lines
Quoted 2 lines

You don't need to test with stat unless you want to support files bigger than your static buffer.

It is expected that AFL data will eventually become longer than the fuzzer wishes. You should ignore extraneous data.

That's not necessarily true. It depends on how you run the fuzzer.

But yes, ignoring extraneous data is sensible.

Quoted 1 line

Also, remember that AFL prefers to pass data by pipe.

It supports both using file or STDIN.

Using file would be easier for manual retest.

Wei.

Quoted 2 lines

~Andrew

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

#10 lore raw

Re: [PATCH 2/4] tools/fuzz: add AFL stub program for x86 insn emulator fuzzer

In reply to Andrew Cooper

Andrew Cooper writes ("Re: [PATCH 2/4] tools/fuzz: add AFL stub program for x86 insn emulator fuzzer"):

Quoted 6 lines · Ian Jackson
Quoted 2 lines

You don't need to test with stat unless you want to support files bigger than your static buffer.

It is expected that AFL data will eventually become longer than the fuzzer wishes. You should ignore extraneous data.

No, you should exit nonzero.

That will signal to fuzzers that this is not a "valid" input and so not interesting. It will signal to other kinds of test code that something is wrong.

Ian.

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

author
#11 lore raw

Re: [PATCH 2/4] tools/fuzz: add AFL stub program for x86 insn emulator fuzzer

Quoted 5 lines · Ian Jackson

Andrew Cooper writes ("Re: [PATCH 2/4] tools/fuzz: add AFL stub program for x86 insn emulator fuzzer"):

Quoted 4 lines · Ian Jackson
Quoted 2 lines

You don't need to test with stat unless you want to support files bigger than your static buffer.

Quoted 9 lines
Quoted 2 lines

It is expected that AFL data will eventually become longer than the fuzzer wishes. You should ignore extraneous data.

No, you should exit nonzero.

That will signal to fuzzers that this is not a "valid" input and so not interesting. It will signal to other kinds of test code that something is wrong.

Hmm... I originally thought exit(1) would cause AFL to think the program has crashed, but I was wrong.

So using exit(1) is more sensible in this case.

Wei.

Quoted 1 line

Ian.

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

#12 lore raw

Re: [PATCH 2/4] tools/fuzz: add AFL stub program for x86 insn emulator fuzzer

Wei Liu writes ("Re: [PATCH 2/4] tools/fuzz: add AFL stub program for x86 insn emulator fuzzer"):

Quoted 2 lines

Hmm... I originally thought exit(1) would cause AFL to think the program has crashed, but I was wrong.

Ah. Yes, indeed. Sorry for not explaining that.

Quoted 1 line

So using exit(1) is more sensible in this case.

Right.

Thanks,
Ian.

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

author
#13 lore raw

Re: [PATCH 2/4] tools/fuzz: add AFL stub program for x86 insn emulator fuzzer

In reply to Ian Jackson
Quoted 17 lines · Ian Jackson

Wei Liu writes ("Re: [PATCH 2/4] tools/fuzz: add AFL stub program for x86 insn emulator fuzzer"):

Quoted 5 lines · Ian Jackson
Quoted 2 lines

If you use read you ought to put it in a loop to cope with potential partial reads.

Does fread have better properties than read?

Yes. fread is not allowed to give a short read for no particular reason, nor to return with EINTR.

Quoted 2 lines

I think to deal with short read we would need to stat the file to get actual size for both fread and read, right?

No. In both cases, it is possible to detect whether a short read is due to EOF. With read, that would have to be in a loop. With fread you can test feof.

Quoted 9 lines

You don't need to test with stat unless you want to support files bigger than your static buffer.

I recommend you:
* use fopen and fread
* complain if fread filled the whole buffer, on the grounds that that means you may be ignoring a longer file than is supported
* check with feof or ferror that the short read was due to eof

NP. This sounds sensible.

Wei.

Quoted 1 line

Ian.

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

author
#14 lore raw

PATCH 3/4 tools/fuzz: add AFL stub program for libefl fuzzer

In reply to Wei Liu

And hook it up into build system.

---
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>

---
 .gitignore                            |  1 +
 tools/fuzz/libelf/Makefile            |  7 +++++-
 tools/fuzz/libelf/afl-libelf-fuzzer.c | 42 +++++++++++++++++++++++++++++++++++
 3 files changed, 49 insertions(+), 1 deletion(-)
 create mode 100644 tools/fuzz/libelf/afl-libelf-fuzzer.c
.gitignore +1 -0
index 881e7cb..15344b0 100644
@@ -146,6 +146,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/libelf/afl-libelf-fuzzer
 tools/fuzz/x86_instruction_emulator/x86_emulate*
 tools/fuzz/x86_instruction_emulator/afl-x86-insn-emulator-fuzzer
 tools/helpers/_paths.h
tools/fuzz/libelf/Makefile +6 -1
index c73ce44..3118f3d 100644
@@ -19,6 +19,8 @@ libelf.a: $(ELF_LIB_OBJS)
 .PHONY: libelf-fuzzer-all
 libelf-fuzzer-all: libelf.a libelf-fuzzer.o
 
+afl-libelf-fuzzer: afl-libelf-fuzzer.o libelf-fuzzer.o $(ELF_LIB_OBJS)
+
 # Common targets
 .PHONY: all
 all: libelf-fuzzer-all
@@ -28,7 +30,10 @@ distclean: clean
 
 .PHONY: clean
 clean:
-	rm -f *.o *.a
+	rm -f *.o *.a afl-libelf-fuzzer
 
 .PHONY: install
 install: all
+
+.PHONY: afl
+afl: afl-libelf-fuzzer
tools/fuzz/libelf/afl-libelf-fuzzer.c new file +42 -0

42 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
author
#16 lore raw

PATCH 4/4 tools/fuzz: add README.afl

In reply to Wei Liu

And rename README to README.oss-fuzz.

---
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>

---
 tools/fuzz/README.afl                  | 27 +++++++++++++++++++++++++++
 tools/fuzz/{README => README.oss-fuzz} |  0
 2 files changed, 27 insertions(+)
 create mode 100644 tools/fuzz/README.afl
 rename tools/fuzz/{README => README.oss-fuzz} (100%)
tools/fuzz/README.afl new file +27 -0
new file mode 100644
index 0000000..7214b61
@@ -0,0 +1,27 @@
+# OVERVIEW
+
+Some fuzzing targets have American Fuzzy Lop (AFL) support.
+
+See also http://lcamtuf.coredump.cx/afl/
+
+# HOW IT WORKS
+
+AFL provides a customised toolchain to build an executable, which in
+turn is launched by the fuzzer.
+
+# HOW TO USE IT
+
+Use the x86 instruction emulator fuzzer as an example.
+
+1. download and compile AFL in $AFLPATH.
+
+2. run the following commands to build:
+   $ cd tools/fuzz/x86_instruction_emulator
+   $ make distclean
+   $ make CC=$AFLPATH/afl-gcc afl # produces afl-x86-insn-emulator-fuzzer
+
+3. run the fuzzer with AFL:
+   $ $AFLPATH/afl-fuzz -m none -t 1000 -i testcase_dir -o findings_dir -- \
+     ./afl-x86-insn-emulator-fuzzer @@
+
+Please see AFL documentation for more information.
tools/fuzz/README.oss-fuzz renamed from tools/fuzz/README +0 -0
similarity index 100%
rename from tools/fuzz/README
rename to tools/fuzz/README.oss-fuzz
Signature · 7 lines
2.1.4


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

Re: [PATCH 4/4] tools/fuzz: add README.afl

Quoted 38 lines · Wei Liu

And rename README to README.oss-fuzz.

---
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>

---
 tools/fuzz/README.afl                  | 27 +++++++++++++++++++++++++++
 tools/fuzz/{README => README.oss-fuzz} |  0
 2 files changed, 27 insertions(+)
 create mode 100644 tools/fuzz/README.afl
 rename tools/fuzz/{README => README.oss-fuzz} (100%)
tools/fuzz/README.afl new file +17 -0
new file mode 100644
index 0000000..7214b61
@@ -0,0 +1,27 @@
+# OVERVIEW
+
+Some fuzzing targets have American Fuzzy Lop (AFL) support.
+
+See also http://lcamtuf.coredump.cx/afl/
+
+# HOW IT WORKS
+
+AFL provides a customised toolchain to build an executable, which in
+turn is launched by the fuzzer.
+
+# HOW TO USE IT
+
+Use the x86 instruction emulator fuzzer as an example.
+
+1. download and compile AFL in $AFLPATH.
+

tools/fuzz/README.afl line 27

Quoted 10 lines
tools/fuzz/README.afl new file +10 -0
+2. run the following commands to build:
+   $ cd tools/fuzz/x86_instruction_emulator
+   $ make distclean
+   $ make CC=$AFLPATH/afl-gcc afl # produces afl-x86-insn-emulator-fuzzer
+
+3. run the fuzzer with AFL:
+   $ $AFLPATH/afl-fuzz -m none -t 1000 -i testcase_dir -o findings_dir -- \
+     ./afl-x86-insn-emulator-fuzzer @@
+
+Please see AFL documentation for more information.

Having just debugged this README (I totally haven't forgotten how to use AFL, despite all the recent work on it ;p), it is missing the initial test case.

I previously used a ret instruction as the seed testcase.

$ mkdir testcase_dir
$ echo -n -e '\xc3' > testcase_dir/ret.bin

after which ALF is happy to start running.

~Andrew

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

author
#18 lore raw

Re: [PATCH 4/4] tools/fuzz: add README.afl

Quoted 54 lines · Andrew Cooper
Quoted 38 lines · Wei Liu

And rename README to README.oss-fuzz.

---
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>

---
 tools/fuzz/README.afl                  | 27 +++++++++++++++++++++++++++
 tools/fuzz/{README => README.oss-fuzz} |  0
 2 files changed, 27 insertions(+)
 create mode 100644 tools/fuzz/README.afl
 rename tools/fuzz/{README => README.oss-fuzz} (100%)
tools/fuzz/README.afl new file +17 -0
new file mode 100644
index 0000000..7214b61
@@ -0,0 +1,27 @@
+# OVERVIEW
+
+Some fuzzing targets have American Fuzzy Lop (AFL) support.
+
+See also http://lcamtuf.coredump.cx/afl/
+
+# HOW IT WORKS
+
+AFL provides a customised toolchain to build an executable, which in
+turn is launched by the fuzzer.
+
+# HOW TO USE IT
+
+Use the x86 instruction emulator fuzzer as an example.
+
+1. download and compile AFL in $AFLPATH.
+

tools/fuzz/README.afl line 27

Quoted 10 lines
tools/fuzz/README.afl new file +10 -0
+2. run the following commands to build:
+   $ cd tools/fuzz/x86_instruction_emulator
+   $ make distclean
+   $ make CC=$AFLPATH/afl-gcc afl # produces afl-x86-insn-emulator-fuzzer
+
+3. run the fuzzer with AFL:
+   $ $AFLPATH/afl-fuzz -m none -t 1000 -i testcase_dir -o findings_dir -- \
+     ./afl-x86-insn-emulator-fuzzer @@
+
+Please see AFL documentation for more information.

Having just debugged this README (I totally haven't forgotten how to use AFL, despite all the recent work on it ;p), it is missing the initial test case.

Quoted 6 lines

I previously used a ret instruction as the seed testcase.

$ mkdir testcase_dir
$ echo -n -e '\xc3' > testcase_dir/ret.bin

after which ALF is happy to start running.

Right, I will add this to README.afl.

Wei.

Quoted 2 lines

~Andrew

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

#19 lore raw

Re: [PATCH 4/4] tools/fuzz: add README.afl

In reply to Andrew Cooper
Quoted 54 lines · Andrew Cooper
Quoted 38 lines · Wei Liu

And rename README to README.oss-fuzz.

---
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>

---
 tools/fuzz/README.afl                  | 27 +++++++++++++++++++++++++++
 tools/fuzz/{README => README.oss-fuzz} |  0
 2 files changed, 27 insertions(+)
 create mode 100644 tools/fuzz/README.afl
 rename tools/fuzz/{README => README.oss-fuzz} (100%)
tools/fuzz/README.afl new file +17 -0
new file mode 100644
index 0000000..7214b61
@@ -0,0 +1,27 @@
+# OVERVIEW
+
+Some fuzzing targets have American Fuzzy Lop (AFL) support.
+
+See also http://lcamtuf.coredump.cx/afl/
+
+# HOW IT WORKS
+
+AFL provides a customised toolchain to build an executable, which in
+turn is launched by the fuzzer.
+
+# HOW TO USE IT
+
+Use the x86 instruction emulator fuzzer as an example.
+
+1. download and compile AFL in $AFLPATH.
+

tools/fuzz/README.afl line 27

Quoted 10 lines
tools/fuzz/README.afl new file +10 -0
+2. run the following commands to build:
+   $ cd tools/fuzz/x86_instruction_emulator
+   $ make distclean
+   $ make CC=$AFLPATH/afl-gcc afl # produces afl-x86-insn-emulator-fuzzer
+
+3. run the fuzzer with AFL:
+   $ $AFLPATH/afl-fuzz -m none -t 1000 -i testcase_dir -o findings_dir -- \
+     ./afl-x86-insn-emulator-fuzzer @@
+
+Please see AFL documentation for more information.

Having just debugged this README (I totally haven't forgotten how to use AFL, despite all the recent work on it ;p), it is missing the initial test case.

Quoted 6 lines

I previously used a ret instruction as the seed testcase.

$ mkdir testcase_dir
$ echo -n -e '\xc3' > testcase_dir/ret.bin

after which ALF is happy to start running.

In my own version I had a special option to pass to the binary to generate a set of test cases. Wei, do you have any opinions on this?

One of the things I found was that there were certain "corners" of the code that for some reason AFL had trouble reaching (i.e., after two days of running there were lines that still didn't have any coverage). One of the advantages of generating test cases is that if some of these are identified, we may be able to get a more even coverage more quickly.

-George

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

author
#20 lore raw

Re: [PATCH 4/4] tools/fuzz: add README.afl

Quoted 66 lines · George Dunlap
Quoted 54 lines · Andrew Cooper
Quoted 38 lines · Wei Liu

And rename README to README.oss-fuzz.

---
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>

---
 tools/fuzz/README.afl                  | 27 +++++++++++++++++++++++++++
 tools/fuzz/{README => README.oss-fuzz} |  0
 2 files changed, 27 insertions(+)
 create mode 100644 tools/fuzz/README.afl
 rename tools/fuzz/{README => README.oss-fuzz} (100%)
tools/fuzz/README.afl new file +17 -0
new file mode 100644
index 0000000..7214b61
@@ -0,0 +1,27 @@
+# OVERVIEW
+
+Some fuzzing targets have American Fuzzy Lop (AFL) support.
+
+See also http://lcamtuf.coredump.cx/afl/
+
+# HOW IT WORKS
+
+AFL provides a customised toolchain to build an executable, which in
+turn is launched by the fuzzer.
+
+# HOW TO USE IT
+
+Use the x86 instruction emulator fuzzer as an example.
+
+1. download and compile AFL in $AFLPATH.
+

tools/fuzz/README.afl line 27

Quoted 10 lines
tools/fuzz/README.afl new file +10 -0
+2. run the following commands to build:
+   $ cd tools/fuzz/x86_instruction_emulator
+   $ make distclean
+   $ make CC=$AFLPATH/afl-gcc afl # produces afl-x86-insn-emulator-fuzzer
+
+3. run the fuzzer with AFL:
+   $ $AFLPATH/afl-fuzz -m none -t 1000 -i testcase_dir -o findings_dir -- \
+     ./afl-x86-insn-emulator-fuzzer @@
+
+Please see AFL documentation for more information.

Having just debugged this README (I totally haven't forgotten how to use AFL, despite all the recent work on it ;p), it is missing the initial test case.

Quoted 6 lines

I previously used a ret instruction as the seed testcase.

$ mkdir testcase_dir
$ echo -n -e '\xc3' > testcase_dir/ret.bin

after which ALF is happy to start running.

In my own version I had a special option to pass to the binary to generate a set of test cases. Wei, do you have any opinions on this?

Quoted 7 lines

One of the things I found was that there were certain "corners" of the code that for some reason AFL had trouble reaching (i.e., after two days of running there were lines that still didn't have any coverage). One of the advantages of generating test cases is that if some of these are identified, we may be able to get a more even coverage more quickly.

I haven't read that version in detailed, but I agree with you that having ability to generate tailored test case is a good idea.

Wei.

Quoted 1 line

-George

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

#21 lore raw
In reply to Wei Liu

Hi Wei,

Quoted 9 lines · Wei Liu

Provide simple stub programs for AFL fuzzer. For usage, please see README.afl.

This series doesn't aim to improve fuzzing targets. It is just demonstration for how we could use the same fuzzing code for both oss-fuzz and AFL.

The stub programs are identical in libefl and x86 emulator at the moment, but they will likely diverge in the future. The duplication of code is deliberate.

Julien, FYI I think the in-tree libfdt could have something similar, too.

I am not sure if it would be useful. We know that libfdt is not protected against rogue device-tree and therefore fuzzing will likely break it. Any device-tree used are expected to be trusted (this is documented in the tools).

Anyway, it would be nice to get libfdt fixed and provide patch the upstream version [1].

Cheers,

[1] https://git.kernel.org/cgit/utils/dtc/dtc.git

Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
author
#22 lore raw
Quoted 11 lines · Julien Grall

Hi Wei,

Quoted 8 lines · Wei Liu

Provide simple stub programs for AFL fuzzer. For usage, please see README.afl.

This series doesn't aim to improve fuzzing targets. It is just demonstration for how we could use the same fuzzing code for both oss-fuzz and AFL.

The stub programs are identical in libefl and x86 emulator at the moment, but they will likely diverge in the future. The duplication of code is deliberate.

Quoted 7 lines
Quoted 1 line

Julien, FYI I think the in-tree libfdt could have something similar, too.

I am not sure if it would be useful. We know that libfdt is not protected against rogue device-tree and therefore fuzzing will likely break it. Any device-tree used are expected to be trusted (this is documented in the tools).

OK. In that case we don't need to run AFL against libfdt.

Wei.

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

#23 lore raw
Quoted 14 lines · Wei Liu
Quoted 13 lines · Julien Grall

Hi Wei,

Quoted 9 lines · Wei Liu

Provide simple stub programs for AFL fuzzer. For usage, please see README.afl.

This series doesn't aim to improve fuzzing targets. It is just demonstration for how we could use the same fuzzing code for both oss-fuzz and AFL.

The stub programs are identical in libefl and x86 emulator at the moment, but they will likely diverge in the future. The duplication of code is deliberate.

Julien, FYI I think the in-tree libfdt could have something similar, too.

Quoted 7 lines
Quoted 5 lines

I am not sure if it would be useful. We know that libfdt is not protected against rogue device-tree and therefore fuzzing will likely break it. Any device-tree used are expected to be trusted (this is documented in the tools).

OK. In that case we don't need to run AFL against libfdt.

I agree.

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