Commit 3e1db847 authored by eholk's avatar eholk Committed by Commit bot

[wasm] Syntax- and Type-aware Fuzzer

This is the beginning of a new fuzzer that generates
correct-by-construction Wasm modules. This should allow us to better
exercise the compiler and correctness aspects of fuzzing. It is based off
of ahaas' original Wasm fuzzer.

At the moment, it can generate expressions made up of most binops, and
also nested blocks with unconditional breaks. Future CLs will add
additional constructs, such as br_if, loops, memory access, etc.

The way the fuzzer works is that it starts with an array of arbitrary
data provided by libfuzzer. It uses the data to generate an expression.
Care is taken to make use of the entire string. Basically, the
generator has a bunch of grammar-like rules for how to construct an
expression of a given type. For example, an i32 can be made by adding
two other i32s, or by wrapping an i64. The process then continues
recursively until all the data is consumed.

We generate an expression from a slice of data as follows:
* If the slice is less than or equal to the size of the type (e.g. 4
  bytes for i32), then it will emit the entire slice as a constant.
* Otherwise, it will consume the first 4 bytes of the slice and use
  this to select which rule to apply. Each rule then consumes the
  remainder of the slice in an appropriate way. For example:
  * Unary ops use the remainder of the slice to generate the argument.
  * Binary ops consume another four bytes and mod this with the length
    of the remaining slice to split the slice into two parts. Each of
    these subslices are then used to generate one of the arguments to
    the binop.
  * Blocks are basically like a unary op, but a stack of block types is
    maintained to facilitate branches. For blocks that end in a break,
    the first four bytes of a slice are used to select the break depth
    and the stack determines what type of expression to generate.
The goal is that once this generator is complete, it will provide a one
to one mapping between binary strings and valid Wasm modules.

Review-Url: https://codereview.chromium.org/2658723006
Cr-Commit-Position: refs/heads/master@{#43289}
parent 76c65af8
...@@ -3101,3 +3101,23 @@ v8_source_set("wasm_data_section_fuzzer") { ...@@ -3101,3 +3101,23 @@ v8_source_set("wasm_data_section_fuzzer") {
v8_fuzzer("wasm_data_section_fuzzer") { v8_fuzzer("wasm_data_section_fuzzer") {
} }
v8_source_set("wasm_compile_fuzzer") {
sources = [
"test/fuzzer/wasm-compile.cc",
]
deps = [
":fuzzer_support",
":wasm_module_runner",
":wasm_test_signatures",
]
configs = [
":external_config",
":internal_config_base",
]
}
v8_fuzzer("wasm_compile_fuzzer") {
}
...@@ -200,6 +200,35 @@ ...@@ -200,6 +200,35 @@
'../common/wasm/wasm-module-runner.h', '../common/wasm/wasm-module-runner.h',
], ],
}, },
{
'target_name': 'v8_simple_wasm_compile_fuzzer',
'type': 'executable',
'dependencies': [
'wasm_compile_fuzzer_lib',
],
'include_dirs': [
'../..',
],
'sources': [
'fuzzer.cc',
],
},
{
'target_name': 'wasm_compile_fuzzer_lib',
'type': 'static_library',
'dependencies': [
'fuzzer_support',
],
'include_dirs': [
'../..',
],
'sources': [ ### gcmole(all) ###
'wasm-compile.cc',
'../common/wasm/test-signatures.h',
'../common/wasm/wasm-module-runner.cc',
'../common/wasm/wasm-module-runner.h',
],
},
{ {
'target_name': 'v8_simple_wasm_data_section_fuzzer', 'target_name': 'v8_simple_wasm_data_section_fuzzer',
'type': 'executable', 'type': 'executable',
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
'<(PRODUCT_DIR)/v8_simple_wasm_asmjs_fuzzer<(EXECUTABLE_SUFFIX)', '<(PRODUCT_DIR)/v8_simple_wasm_asmjs_fuzzer<(EXECUTABLE_SUFFIX)',
'<(PRODUCT_DIR)/v8_simple_wasm_call_fuzzer<(EXECUTABLE_SUFFIX)', '<(PRODUCT_DIR)/v8_simple_wasm_call_fuzzer<(EXECUTABLE_SUFFIX)',
'<(PRODUCT_DIR)/v8_simple_wasm_code_fuzzer<(EXECUTABLE_SUFFIX)', '<(PRODUCT_DIR)/v8_simple_wasm_code_fuzzer<(EXECUTABLE_SUFFIX)',
'<(PRODUCT_DIR)/v8_simple_wasm_compile_fuzzer<(EXECUTABLE_SUFFIX)',
'<(PRODUCT_DIR)/v8_simple_wasm_data_section_fuzzer<(EXECUTABLE_SUFFIX)', '<(PRODUCT_DIR)/v8_simple_wasm_data_section_fuzzer<(EXECUTABLE_SUFFIX)',
'<(PRODUCT_DIR)/v8_simple_wasm_function_sigs_section_fuzzer<(EXECUTABLE_SUFFIX)', '<(PRODUCT_DIR)/v8_simple_wasm_function_sigs_section_fuzzer<(EXECUTABLE_SUFFIX)',
'<(PRODUCT_DIR)/v8_simple_wasm_globals_section_fuzzer<(EXECUTABLE_SUFFIX)', '<(PRODUCT_DIR)/v8_simple_wasm_globals_section_fuzzer<(EXECUTABLE_SUFFIX)',
...@@ -28,6 +29,7 @@ ...@@ -28,6 +29,7 @@
'./wasm_asmjs/', './wasm_asmjs/',
'./wasm_call/', './wasm_call/',
'./wasm_code/', './wasm_code/',
'./wasm_compile/',
'./wasm_data_section/', './wasm_data_section/',
'./wasm_function_sigs_section/', './wasm_function_sigs_section/',
'./wasm_globals_section/', './wasm_globals_section/',
......
...@@ -19,9 +19,10 @@ class FuzzerVariantGenerator(testsuite.VariantGenerator): ...@@ -19,9 +19,10 @@ class FuzzerVariantGenerator(testsuite.VariantGenerator):
class FuzzerTestSuite(testsuite.TestSuite): class FuzzerTestSuite(testsuite.TestSuite):
SUB_TESTS = ( 'json', 'parser', 'regexp', 'wasm', 'wasm_asmjs', 'wasm_call', SUB_TESTS = ( 'json', 'parser', 'regexp', 'wasm', 'wasm_asmjs', 'wasm_call',
'wasm_code', 'wasm_data_section', 'wasm_function_sigs_section', 'wasm_code', 'wasm_compile', 'wasm_data_section',
'wasm_globals_section', 'wasm_imports_section', 'wasm_memory_section', 'wasm_function_sigs_section', 'wasm_globals_section',
'wasm_names_section', 'wasm_types_section' ) 'wasm_imports_section', 'wasm_memory_section', 'wasm_names_section',
'wasm_types_section' )
def __init__(self, name, root): def __init__(self, name, root):
super(FuzzerTestSuite, self).__init__(name, root) super(FuzzerTestSuite, self).__init__(name, root)
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment