From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Xen-devel <xen-devel@lists.xen.org>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>,
Ian Jackson <Ian.Jackson@eu.citrix.com>,
Wei Liu <wei.liu2@citrix.com>, Jan Beulich <JBeulich@suse.com>
Subject: [PATCH 6/8] tools/insn-fuzz: Accept fuzzing input on stdin
Date: Mon, 20 Mar 2017 11:19:43 +0000 [thread overview]
Message-ID: <1490008785-6058-7-git-send-email-andrew.cooper3@citrix.com> (raw)
In-Reply-To: <1490008785-6058-1-git-send-email-andrew.cooper3@citrix.com>
This is rather faster for afl-fuzz to arrange than using an explicit file
parameter. Also update the README to recommend using a tmpfs for findings_dir
which reduces disk load and is more performant.
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
CC: Jan Beulich <JBeulich@suse.com>
CC: Ian Jackson <Ian.Jackson@eu.citrix.com>
CC: Wei Liu <wei.liu2@citrix.com>
---
tools/fuzz/README.afl | 7 ++++--
tools/fuzz/x86_instruction_emulator/afl-harness.c | 29 ++++++++++++++---------
2 files changed, 23 insertions(+), 13 deletions(-)
diff --git a/tools/fuzz/README.afl b/tools/fuzz/README.afl
index 357c3c8..c5f749a 100644
--- a/tools/fuzz/README.afl
+++ b/tools/fuzz/README.afl
@@ -25,8 +25,11 @@ Use the x86 instruction emulator fuzzer as an example.
$ dd if=/dev/urandom of=testcase_dir/rand.bin \
bs=`./afl-harness --min-input-size` count=1
+3a. use a tmpfs for findings_dir (Perf improvement and reduced disk load)
+ $ mkdir findings_dir
+ $ mount -t tmpfs -o size=512M tmpfs findings_dir
+
4. run the fuzzer with AFL:
- $ $AFLPATH/afl-fuzz -m none -t 1000 -i testcase_dir -o findings_dir -- \
- ./afl-harness @@
+ $ $AFLPATH/afl-fuzz -t 1000 -i testcase_dir -o findings_dir -- ./afl-harness
Please see AFL documentation for more information.
diff --git a/tools/fuzz/x86_instruction_emulator/afl-harness.c b/tools/fuzz/x86_instruction_emulator/afl-harness.c
index 102566c..89d8605 100644
--- a/tools/fuzz/x86_instruction_emulator/afl-harness.c
+++ b/tools/fuzz/x86_instruction_emulator/afl-harness.c
@@ -14,7 +14,7 @@ static uint8_t input[INPUT_SIZE];
int main(int argc, char **argv)
{
size_t size;
- FILE *fp;
+ FILE *fp = NULL;
setbuf(stdout, NULL);
@@ -40,6 +40,7 @@ int main(int argc, char **argv)
break;
case '?':
+ usage:
printf("Usage: %s $FILE | [--min-input-size]\n", argv[0]);
exit(-1);
break;
@@ -51,17 +52,19 @@ int main(int argc, char **argv)
}
}
- if ( optind != (argc - 1) )
- {
- printf("Expecting only one argument\n");
- exit(-1);
- }
+ if ( optind == argc ) /* No positional parameters. Use stdin. */
+ fp = stdin;
+ else if ( optind != (argc - 1) )
+ goto usage;
- fp = fopen(argv[1], "rb");
- if ( fp == NULL )
+ if ( fp != stdin ) /* If not using stdin, open the provided file. */
{
- perror("fopen");
- exit(-1);
+ fp = fopen(argv[optind], "rb");
+ if ( fp == NULL )
+ {
+ perror("fopen");
+ exit(-1);
+ }
}
size = fread(input, 1, INPUT_SIZE, fp);
@@ -78,7 +81,11 @@ int main(int argc, char **argv)
exit(-1);
}
- fclose(fp);
+ if ( fp != stdin )
+ {
+ fclose(fp);
+ fp = NULL;
+ }
LLVMFuzzerTestOneInput(input, size);
--
2.1.4
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
next prev parent reply other threads:[~2017-03-20 11:19 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-20 11:19 [PATCH 0/8] Fuzzing misc bugfix and performance improvements Andrew Cooper
2017-03-20 11:19 ` [PATCH 1/8] tools/fuzz: Remove .d files in clean Andrew Cooper
2017-03-20 11:19 ` [PATCH 2/8] tools/fuzz: Use $(CC) for linking the harnesses Andrew Cooper
2017-03-20 11:19 ` [PATCH 3/8] tools/fuzz: Include LLVMFuzzerTestOneInput() in the generated .a Andrew Cooper
2017-03-20 11:19 ` [PATCH 4/8] tools/insn-fuzz: Use shorter filenames Andrew Cooper
2017-03-20 11:19 ` [PATCH 5/8] tools/insn-fuzz: Use getopt() for parsing the command line Andrew Cooper
2017-03-20 11:19 ` Andrew Cooper [this message]
2017-03-20 11:19 ` [PATCH 7/8] tools/insn-fuzz: Make use of LLVMFuzzerInitialize() Andrew Cooper
2017-03-20 11:19 ` [PATCH 8/8] tools/insn-fuzz: Support AFL's afl-clang-fast mode Andrew Cooper
2017-03-20 15:55 ` [PATCH 0/8] Fuzzing misc bugfix and performance improvements Wei Liu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1490008785-6058-7-git-send-email-andrew.cooper3@citrix.com \
--to=andrew.cooper3@citrix.com \
--cc=Ian.Jackson@eu.citrix.com \
--cc=JBeulich@suse.com \
--cc=wei.liu2@citrix.com \
--cc=xen-devel@lists.xen.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).