Skip to content

Create the initial skeleton for a wasm-mutate tool - #329

Closed
fitzgen wants to merge 1 commit into
bytecodealliance:mainfrom
fitzgen:skeleton-for-wasm-mutate
Closed

fitzgen wants to merge 1 commit into
bytecodealliance:mainfrom
fitzgen:skeleton-for-wasm-mutate

Conversation

@fitzgen

@fitzgen fitzgen commented Sep 2, 2021

Copy link
Copy Markdown
Member

wasm-mutate will be a new tool for fuzzing Wasm compilers, runtimes,
validators, and other Wasm-consuming programs. wasm-mutate will take in an
existing Wasm module and then apply a pseudo-random transformation to it,
producing a new, mutated Wasm module. This new Wasm module will be fed into the
system under test, potentially triggering a bug that users can then diagnose and
fix.

wasm-mutate should additionally support the following features:

  • wasm-mutate should have the ability to restrict mutations to only those that
    shrink the size of the Wasm module, e.g. removing a function from the Wasm
    module. When used in this mode, wasm-mutate essentially becomes a Wasm
    test-case reducer.

  • wasm-mutate should have the ability to only apply semantics-preserving
    changes to the input Wasm module. When used in this mode, the mutated Wasm
    should compute identical results when given the same inputs as the original
    Wasm module.

  • wasm-mutate should be deterministic. When given the same input Wasm module
    and the same seed, it should always produce the same mutated output Wasm
    module.

  • wasm-mutate should play nice with mutation-based fuzzers like libFuzzer. It
    should reuse the fuzzer's raw input strings when it makes sense (e.g. when
    adding an export, use the raw fuzzer input when choosing an export name) so
    that fuzzer features like dictionary files can be leveraged. wasm-mutate
    should integrate with the LLVMFuzzerCustomMutator hook and the
    libfuzzer_sys::fuzz_mutator! macro.


cc @Jacarte:

You can run the CLI via cargo run --bin wasm-mutate in the root of this repo

You can run its (pretty much non-existant) tests via cargo test -p wasm-mutate in the root of the repo.

The library is at crates/wasm-mutate/src/lib.rs and the executable CLI that wraps it is at src/bin/wasm-mutate.rs.

@fitzgen
fitzgen requested a review from alexcrichton September 2, 2021 18:35
@alexcrichton

Copy link
Copy Markdown
Member

Seems reasonable to me! Should the tool perhaps be developed on a separate branch until it's more fleshed out?

Also in terms of the skeleton, there's a seed argument right now but shouldn't that presumably be some sort of list-of-bytes from the fuzz input? It looks like it's the seed to an RNG but I thought that for libfuzzer-based things we tend to prefer "DNAs" to something like that?

@fitzgen

fitzgen commented Sep 2, 2021

Copy link
Copy Markdown
Member Author

Should the tool perhaps be developed on a separate branch until it's more fleshed out?

I'd like to avoid waiting on one gigantic PR for the whole tool so that we can review incremental PRs. But I guess we could make a series of incremental PRs to a longer-lived wasm-mutate feature branch. Happy to go either way.

Also in terms of the skeleton, there's a seed argument right now but shouldn't that presumably be some sort of list-of-bytes from the fuzz input? It looks like it's the seed to an RNG but I thought that for libfuzzer-based things we tend to prefer "DNAs" to something like that?

That is how we generate a structure from the fuzzer's raw input. This design is based on the custom mutator hooks that libFuzzer exposes. The custom fuzz mutator is given only a u64 seed from libFuzzer, but then when you are mutating some byte slice, you can call LLVMFuzzerMutate on a given slice to have libFuzzer grow or shrink it (including growing a zero-sized slice, effectively giving you a bunch of new random data). This latter hook is what the raw_mutate_func hook in this PR is for integrating with.

@fitzgen
fitzgen force-pushed the skeleton-for-wasm-mutate branch from d97e81d to 8839a9b Compare September 2, 2021 20:32
`wasm-mutate` will be a new tool for fuzzing Wasm compilers, runtimes,
validators, and other Wasm-consuming programs. `wasm-mutate` will take in an
existing Wasm module and then apply a pseudo-random transformation to it,
producing a new, mutated Wasm module. This new Wasm module will be fed into the
system under test, potentially triggering a bug that users can then diagnose and
fix.

`wasm-mutate` should additionally support the following features:

* `wasm-mutate` should have the ability to restrict mutations to only those that
  shrink the size of the Wasm module, e.g. removing a function from the Wasm
  module. When used in this mode, `wasm-mutate` essentially becomes a Wasm
  test-case reducer.

* `wasm-mutate` should have the ability to only apply semantics-preserving
  changes to the input Wasm module. When used in this mode, the mutated Wasm
  should compute identical results when given the same inputs as the original
  Wasm module.

* `wasm-mutate` should be deterministic. When given the same input Wasm module
  and the same seed, it should always produce the same mutated output Wasm
  module.

* `wasm-mutate` should play nice with mutation-based fuzzers like libFuzzer. It
  should reuse the fuzzer's raw input strings when it makes sense (e.g. when
  adding an export, use the raw fuzzer input when choosing an export name) so
  that fuzzer features like dictionary files can be leveraged. `wasm-mutate`
  should integrate with the `LLVMFuzzerCustomMutator` hook and the
  `libfuzzer_sys::fuzz_mutator!` macro.
@fitzgen
fitzgen force-pushed the skeleton-for-wasm-mutate branch from 8839a9b to 83c669f Compare September 2, 2021 20:34
@alexcrichton

Copy link
Copy Markdown
Member

Nah yeah I also agree it'd be good for incremental reviews, but if you're ok I'd prefer to develop on a separate branch and we can merge to main when it's ready to go.

For seed, it appears I need to go off and learn more about how this is integrating into libfuzzer!

@alexcrichton alexcrichton left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh and this looks good to go to me, so feel free to make a branch and such.

@fitzgen

fitzgen commented Sep 3, 2021

Copy link
Copy Markdown
Member Author

Okay, I'll push this to the wasm-mutate branch. @Jacarte: you can send incremental PRs to that branch, rather than main.

@fitzgen fitzgen closed this Sep 3, 2021
@fitzgen
fitzgen deleted the skeleton-for-wasm-mutate branch September 3, 2021 17:49
@Jacarte

Jacarte commented Sep 3, 2021

Copy link
Copy Markdown
Contributor

Okay, I'll push this to the wasm-mutate branch. @Jacarte: you can send incremental PRs to that branch, rather than main.

Gotcha !

@fitzgen

fitzgen commented Sep 3, 2021

Copy link
Copy Markdown
Member Author

alexcrichton pushed a commit to alexcrichton/wasm-tools that referenced this pull request Nov 16, 2022
…codealliance#322)" (bytecodealliance#329)

This reverts commit 126f8e8.

We chose not to use this approach to smuggling component type information
in core modules. See
WebAssembly/component-model#106 (comment)
for more details.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants