xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: George Dunlap <george.dunlap@citrix.com>
To: Wei Liu <wei.liu2@citrix.com>, Paul Semel <semelpaul@gmail.com>
Cc: george.dunlap@eu.citrix.com, xen-devel@lists.xenproject.org,
	JBeulich@suse.com, andrew.cooper3@citrix.com
Subject: Re: [PATCH] fuzz/x86_emulate: fix bounds for input size
Date: Fri, 23 Feb 2018 16:33:18 +0000	[thread overview]
Message-ID: <2128b78a-a8f8-7005-3277-afca291d165c@citrix.com> (raw)
In-Reply-To: <20180223163009.b42xfl3euanth3b7@citrix.com>

On 02/23/2018 04:30 PM, Wei Liu wrote:
> On Fri, Feb 23, 2018 at 12:57:26AM +0100, Paul Semel wrote:
>> The minimum size for the input size was set to DATA_OFFSET + 1 which was meaning
>> that we were requesting at least one character of the data array to be filled.
>> This is not needed for the fuzzer to get working correctly.
> 
> Sorry, I don't follow -- what do you expect the emulator to do if there
> is no instruction to emulate?
> 
>>
>> The maximum size for the input size was set to INPUT_SIZE, which is actually
>> the size of the data array inside the fuzz_corpus structure and so was not
>> abling user (or AFL) to fill in the whole structure. Changing to
>> sizeof(struct fuzz_corpus) correct this problem.
>>
>> Signed-off-by: Paul Semel <semelpaul@gmail.com>
>> ---
>>  tools/fuzz/x86_instruction_emulator/fuzz-emul.c | 9 +++++----
>>  1 file changed, 5 insertions(+), 4 deletions(-)
>>
>> diff --git a/tools/fuzz/x86_instruction_emulator/fuzz-emul.c b/tools/fuzz/x86_instruction_emulator/fuzz-emul.c
>> index 964682aa1a..f3ce2e7e27 100644
>> --- a/tools/fuzz/x86_instruction_emulator/fuzz-emul.c
>> +++ b/tools/fuzz/x86_instruction_emulator/fuzz-emul.c
>> @@ -33,6 +33,7 @@ struct fuzz_corpus
>>      unsigned char data[INPUT_SIZE];
>>  } input;
>>  #define DATA_OFFSET offsetof(struct fuzz_corpus, data)
>> +#define FUZZ_CORPUS_SIZE (sizeof(struct fuzz_corpus))
>>  
>>  /*
>>   * Internal state of the fuzzing harness.  Calculated initially from the input
>> @@ -822,13 +823,13 @@ int LLVMFuzzerTestOneInput(const uint8_t *data_p, size_t size)
>>      /* Reset all global state variables */
>>      memset(&input, 0, sizeof(input));
>>  
>> -    if ( size <= DATA_OFFSET )
>> +    if ( size < DATA_OFFSET )
>>      {
>>          printf("Input too small\n");
>>          return 1;
>>      }
>>  
>> -    if ( size > INPUT_SIZE )
>> +    if ( size > FUZZ_CORPUS_SIZE )
>>      {
>>          printf("Input too large\n");
>>          return 1;
>> @@ -859,9 +860,9 @@ int LLVMFuzzerTestOneInput(const uint8_t *data_p, size_t size)
>>  
>>  unsigned int fuzz_minimal_input_size(void)
>>  {
>> -    BUILD_BUG_ON(DATA_OFFSET > INPUT_SIZE);
>> +    BUILD_BUG_ON(DATA_OFFSET > FUZZ_CORPUS_SIZE);
> 
> Thinking more about it, this BUILD_BUG_ON is probably irrelevant
> nowadays because we've opted to use struct fuzz_corpus instead of a
> bunch of data structures (when the fuzzer was first implemented). I
> don't think we will go back to the old model in the future so deleting
> this BUILD_BUG_ON should be fine.

We statically allocate an array of data of size INPUT_SIZE in
afl-harness.c; I think that's the purpose of the BUILD_BUG_ON(), to make
sure that that buffer is always big enough for our minimum file size.

 -George

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

  reply	other threads:[~2018-02-23 16:33 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-22 12:39 [xen-devel] [fuzz] [x86 emulator] Input size Paul Semel
2018-02-22 18:00 ` Wei Liu
2018-02-22 23:57   ` [PATCH] fuzz/x86_emulate: fix bounds for input size Paul Semel
2018-02-23  8:20     ` Paul Semel
2018-02-23 10:44     ` George Dunlap
2018-02-23 12:07       ` Paul Semel
2018-02-23 16:30     ` Wei Liu
2018-02-23 16:33       ` George Dunlap [this message]
2018-02-23 16:37         ` Wei Liu
2018-02-23 22:41       ` Paul Semel
2018-02-23 22:48       ` [PATCH v2] " Paul Semel
2018-02-26 10:33         ` Wei Liu
2018-03-02 12:30           ` Wei Liu
2018-02-27 10:39         ` George Dunlap
2018-02-28 17:30           ` Paul Semel

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=2128b78a-a8f8-7005-3277-afca291d165c@citrix.com \
    --to=george.dunlap@citrix.com \
    --cc=JBeulich@suse.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=george.dunlap@eu.citrix.com \
    --cc=semelpaul@gmail.com \
    --cc=wei.liu2@citrix.com \
    --cc=xen-devel@lists.xenproject.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).