Skip to content

[Merged by Bors] - VM Fuzzer - #2401

Closed
addisoncrump wants to merge 8 commits into
boa-dev:mainfrom
addisoncrump:fuzz-vm
Closed

addisoncrump wants to merge 8 commits into
boa-dev:mainfrom
addisoncrump:fuzz-vm

Conversation

@addisoncrump

@addisoncrump addisoncrump commented Nov 2, 2022 •

Copy link
Copy Markdown
Contributor

This Pull Request offers a basic VM fuzzer which relies on implied oracles (namely, "does it crash or timeout?").

It changes the following:

  • Adds an insns_remaining field to Context, denoting the number of instructions remaining to execute (only available when fuzzing)
  • Adds a JsNativeError variant, denoting when the number of instructions has been exceeded (only available when fuzzing)
  • Adds a VM fuzzer which looks for cases where Boa may crash on an input

This offers no guarantees about correctness, only assertion violations. Depends on #2400.

Any issues I raise in association with this fuzzer will link back to this fuzzer.

You may run the fuzzer using the following commands:

$ cd boa_engine
$ cargo +nightly fuzz run -s none vm-implied

@jasonwilliams

Copy link
Copy Markdown
Member

It would be useful to have a README.md in the boa_engine/fuzz directory explaining what it is and why we have it there if you can.

@addisoncrump

Copy link
Copy Markdown
Contributor Author

It would be useful to have a README.md in the boa_engine/fuzz directory explaining what it is and why we have it there if you can.

Done -- provided some explanation for both fuzzers.

@codecov

codecov Bot commented Nov 2, 2022 •

Copy link
Copy Markdown

Codecov Report

Merging #2401 (3c718d0) into main (98e6dd3) will increase coverage by 0.10%.
The diff coverage is 14.28%.

@@            Coverage Diff             @@
##             main    #2401      +/-   ##
==========================================
+ Coverage   52.41%   52.51%   +0.10%     
==========================================
  Files         329      327       -2     
  Lines       34945    34874      -71     
==========================================
- Hits        18315    18314       -1     
+ Misses      16630    16560      -70     
Impacted Files Coverage Δ
boa_engine/src/vm/mod.rs 48.98% <ø> (ø)
fuzz/fuzz_targets/common.rs 0.00% <0.00%> (ø)
boa_engine/src/context/mod.rs 64.61% <100.00%> (+0.18%) ⬆️
...arser/src/parser/expression/left_hand_side/call.rs 54.09% <0.00%> (-1.64%) ⬇️
boa_engine/src/environments/runtime.rs 47.71% <0.00%> (-0.71%) ⬇️
boa_parser/src/lexer/cursor.rs 87.90% <0.00%> (-0.47%) ⬇️
boa_examples/src/bin/commuter_visitor.rs 0.00% <0.00%> (ø)
boa_examples/src/bin/classes.rs
boa_examples/src/bin/jsarraybuffer.rs
boa_engine/src/object/mod.rs 45.77% <0.00%> (+0.10%) ⬆️
... and 1 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@Razican

Razican commented Nov 4, 2022

Copy link
Copy Markdown
Member

I guess this depends on the parser fuzzer, so let's merge that first :)

@addisoncrump
addisoncrump marked this pull request as draft November 6, 2022 15:36
@addisoncrump
addisoncrump force-pushed the fuzz-vm branch 2 times, most recently from feaffb6 to 2adbe98 Compare November 6, 2022 17:40
@addisoncrump
addisoncrump marked this pull request as ready for review November 6, 2022 18:01

@jedel1043 jedel1043 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.

There was an issue asking for a new feature for limits on loops: #2350. NoInstructionsRemain could be reused to implement this.

Comment thread boa_engine/src/error.rs Resolved
Comment thread fuzz/fuzz_targets/vm-implied.rs Resolved
@addisoncrump

Copy link
Copy Markdown
Contributor Author

There was an issue asking for a new feature for limits on loops: #2350. NoInstructionsRemain could be reused to implement this.

We are on one mind here lol

@jedel1043

jedel1043 commented Nov 6, 2022 •

Copy link
Copy Markdown
Member

Now that I think about it, you don't need to juggle with conversions of the NoInstructionsRemain error! The VM bails before you can execute anything that could call to_opaque. We just need to panic inside to_opaque if a user tries to convert a NoInstructionsRemain error into an object.

@addisoncrump

Copy link
Copy Markdown
Contributor Author

Can the error even be manipulated? Not sure how boa makes native errors available to users.

@addisoncrump

Copy link
Copy Markdown
Contributor Author

Now that I think about it, you don't need to juggle with conversions of the NoInstructionsRemain error! The VM bails before you can execute anything that could call to_opaque. We just need to panic inside to_opaque if a user tries to convert a NoInstructionsRemain error into an object.

This isn't quite true. Consider:

while (true) try {} catch {}

The catch attempts to convert it into an object between instructions, so we actually do care. I previously panicked on conversion and had a bunch of false positives (including the one above).

@jedel1043

Copy link
Copy Markdown
Member

Ah, right, the check is inside execute_instruction. Maybe the check should be moved to the while loop inside run?

@addisoncrump

Copy link
Copy Markdown
Contributor Author

That's up to y'all; I don't really know what the preference on execution order is.

@jedel1043

Copy link
Copy Markdown
Member

I mean, a NoInstructionsRemain error shouldn't be circumventable from JS, for obvious reasons. I think bailing directly makes more sense for that type of error.

@addisoncrump

Copy link
Copy Markdown
Contributor Author

It already isn't -- it immediately throws another in any catch block.

@jedel1043

Copy link
Copy Markdown
Member

Yes, but I think it should directly quit execution instead of trying to execute a catch that won't be executed anyways.

@addisoncrump
addisoncrump requested review from HalidOdat and jedel1043 and removed request for HalidOdat, Razican, jasonwilliams, jedel1043 and raskad November 14, 2022 13:29
@addisoncrump

Copy link
Copy Markdown
Contributor Author

That is not what I thought those buttons did, whoops

@Razican Razican 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.

Thanks!! LGTM!

@Razican

Razican commented Nov 15, 2022

Copy link
Copy Markdown
Member

@jedel1043 could you check if your comments were addressed?

@jedel1043 jedel1043 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.

Nice work!

@jedel1043

Copy link
Copy Markdown
Member

bors r+

bors Bot pushed a commit that referenced this pull request Nov 15, 2022
This Pull Request offers a basic VM fuzzer which relies on implied oracles (namely, "does it crash or timeout?").

It changes the following:

- Adds an insns_remaining field to Context, denoting the number of instructions remaining to execute (only available when fuzzing)
- Adds a JsNativeError variant, denoting when the number of instructions has been exceeded (only available when fuzzing)
- Adds a VM fuzzer which looks for cases where Boa may crash on an input

This offers no guarantees about correctness, only assertion violations. Depends on #2400.

Any issues I raise in association with this fuzzer will link back to this fuzzer.

You may run the fuzzer using the following commands:
```bash
$ cd boa_engine
$ cargo +nightly fuzz run -s none vm-implied
```

Co-authored-by: Addison Crump <[email protected]>
@bors

bors Bot commented Nov 15, 2022

Copy link
Copy Markdown

Pull request successfully merged into main.

Build succeeded:

@bors bors Bot changed the title VM Fuzzer [Merged by Bors] - VM Fuzzer Nov 15, 2022
@bors bors Bot closed this Nov 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Enhancement New feature or request C-VM Issues and PRs related to the Boa Virtual Machine.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants