Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EH] Fuzz calls from JS by calling wasm exports, sometimes catching #7067

Merged
merged 62 commits into from
Nov 8, 2024

Conversation

kripken
Copy link
Member

@kripken kripken commented Nov 8, 2024

This adds two new imports to fuzzer modules:

  • call-export, which gets an export index and calls it.
  • call-export-catch, which does the call in a try-catch, swallowing
    any error, and returning 1 if it saw an error.

The former gives us calls back into the wasm, possibly making various
trips between wasm and JS in interesting ways. The latter adds a try-catch
which helps fuzz wasm EH.

We do these calls using a wasm export index, i.e., the index in
the list of exports. This is simple, but it does have the downside that
it makes executing the wasm sensitive to changes in exports (e.g.
wasm-merge adds more), which requires some handling in the fuzzer.

Comment on lines 210 to 212
// check for that first (wasm2js does not define RuntimeError, so use
// that for the check).
var wasm2js = !WebAssembly.RuntimeError;
Copy link
Member

Choose a reason for hiding this comment

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

This seems to assume we only fuzz wasm2js in environments that don't support WebAssembly. Otherwise WebAssembly.RuntimeError would be defined even if we were using wasm2js, right? I don't understand why this does what we want.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, no, when we run wasm2js it does WebAssembly = { .. polyfill .. }, so it tramples any native support. We can't mix native and polyfill stuff, so we have to do that.

Copy link
Member

Choose a reason for hiding this comment

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

Got it, thanks. It would be good to clarify that in the comment.

target = callExportCatchImportName;
// This never traps, so we can be less careful, but we do still want to
// avoid trapping a lot as executing code is more interesting.
maxIndex = (maxIndex + 1) * 2;
Copy link
Member

Choose a reason for hiding this comment

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

Maybe multiply by less than two here? I don't think we need half of the calls to be out of bounds.

Copy link
Member Author

Choose a reason for hiding this comment

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

I was thinking (but I see I didn't document 😄 ) that this is fine because we are doing this as we go, that is, we are still adding functions (we don't know how many in advance). So even larger offsets will have a good chance to be in bounds. What do you think?

Copy link
Member

Choose a reason for hiding this comment

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

aha, that seems reasonable, I suppose.

Comment on lines +21 to +22
;; Note that the exported table appears first here, but in the binary and in
;; the IR it is actually last, as we always add function exports first.
Copy link
Member

Choose a reason for hiding this comment

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

I think we have a TODO in the text parser to fix this and add the exports to the IR in their original order. I guess we'll just have to update this test if we ever fix that.

@kripken kripken merged commit 8c0429a into WebAssembly:main Nov 8, 2024
13 checks passed
@kripken kripken deleted the fuzz.import.calls branch November 8, 2024 18:16
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.

2 participants