Repository navigation
Improve fuzzing effectiveness - #34
Conversation
`parse_ir`, `roundtrip_roundtrip`, `differential` and `opt_diff` unwrapped the result of `Module::from_wasm_bytes`, and `roundtrip`, `differential` and `opt_diff` unwrapped the result of `expand_all_funcs`. A wasm-smith module that uses a feature the frontend does not support, such as a GC type in the type section, made these targets panic with `FrontendError::UnsupportedFeature`. `roundtrip` skipped `UnsupportedFeature` and `TooLarge` when parsing, but that rule existed only there. Add `fuzzing::skip_unsupported`, which returns `None` for `UnsupportedFeature` and `TooLarge` errors and panics on every other error, and `fuzzing::parse`, which applies it to `Module::from_wasm_bytes`. Every target that parses wasm-smith output now uses them for parsing and for `expand_all_funcs`.
`parse_ir`, `roundtrip` and `roundtrip_roundtrip` took `wasm_smith::Module` through its `Arbitrary` implementation, which uses wasm-smith's default configuration. That configuration enables GC, exceptions, threads, tail calls, memory64, relaxed SIMD and extended constant expressions. The frontend rejects GC types, the instructions of the other proposals, and constant expressions with more than one instruction, and it has no representation for memory64 or shared memories. Most inputs therefore ended in a rejected feature. Add `fuzzing::SupportedModule`, which generates a module from an arbitrary `wasm_smith::Config` with these proposals turned off. Limits and the remaining proposals, including bulk memory, reference types, SIMD, multi-value and multi-memory, stay random. The three targets now take `SupportedModule`. `skip_unsupported` still skips inputs that reach an unsupported construct, such as `global.get` in a constant expression or a bulk memory instruction the frontend does not translate. `differential` and `opt_diff` keep `ArbitraryModule`.
`roundtrip` and `roundtrip_roundtrip` checked only that the backend returned bytes, and `roundtrip` discarded the result of `to_wasm_bytes`. `roundtrip_roundtrip` reparses its output with waffle, which does not validate. A valid input that became an invalid output therefore went unnoticed, for example a function body that refers to a data segment the backend did not emit. Add `fuzzing::validate_output`, which validates bytes with `wasmparser::Validator` and panics with the validator's message on failure. The feature set is the one wasm-smith reports for the configuration the input was generated with (`Config::features`), so the output may use any feature the input could have used and no other. Both targets now unwrap `to_wasm_bytes` and validate every module they serialize. The `fuzzing` feature now enables wasm-smith's `wasmparser` feature, which provides `Config::features`.
The `check_fuzz` job ran `cargo fuzz check`, which compiles the fuzz targets and never runs them. Run `parse_ir` for 30 seconds after the check. The step uses cargo-fuzz's default release build with debug assertions, and `-s none` as the check does. `roundtrip` and `roundtrip_roundtrip` fail on existing bugs (dropped passive element and data segments, and functions declared only by an overwritten table entry). `differential` and `opt_diff` generate modules that almost never pass `fuzzing::reject`, so a 30-second run compares almost nothing. `irreducible` generates a CFG instead of a wasm module.
`supported_config` turned off threads because the frontend accepted shared memories and dropped `shared`. The frontend now returns `FrontendError::UnsupportedFeature` for shared memories, and for atomic instructions when it expands a function body. `skip_unsupported` discards those inputs. Turn threads on again. The targets now also cover atomic instructions on unshared memories in unexpanded function bodies, and the rejection of shared memories. memory64 stays off. The frontend rejects every 64-bit memory and table, so those inputs reach no code past that check.
|
I'm developing a better opt pass to replace |
|
After about 10min, I've had it fail at this unwrap while fizzing Line 1489 in 716afb3 Base64: |
|
Is that one of the issues my other PRs fix, or in addition? With those applied, I didn't find anything after an overnight run |
|
I just pulled the changes from this PR, so could be that this is fixed by your other PRs. |
The backend declares a local that holds the result of `ref.func` with the type `(ref null $sig)`, which requires the function references proposal. `validate_output` validated under the features wasm-smith reports for the input's configuration. Those include function references only when GC is enabled, and `supported_config` turns GC off. `roundtrip` therefore failed on valid inputs whose expanded bodies hold a `ref.func` result in a local. `validate_output` now also enables function references. `differential` enables them in its Wasmtime configuration, because Wasmtime 44 leaves them off by default and rejects such a module.
|
This should be ready to land once #31 is in: I just pushed a small additional commit to accommodate the changes in that PR. |
This set of commits fixes a number of issues with the fuzzing targets that prevented them from generating good coverage / finding some important issues.
The two most import changes are to
With the changes here, the fuzzers were effective enough to find the issues I just opened PRs for in a matter of minutes. I'll let a campaign run over night in case more things turn out with a longer run, too.
Note that this also enables 30-second test runs of three fuzz targets in CI, which are quite likely to fail until the other PRs have been merged.