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

[Merged by Bors] - VM Fuzzer #2401

Closed
wants to merge 8 commits into from
Closed

Conversation

addisoncrump
Copy link
Contributor

@addisoncrump addisoncrump commented Nov 2, 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:

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

@jasonwilliams
Copy link
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
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
Copy link

codecov bot commented Nov 2, 2022

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
Copy link
Member

Razican commented Nov 4, 2022

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
Copy link
Member

@jedel1043 jedel1043 left a comment

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.

boa_engine/src/error.rs Show resolved Hide resolved
fuzz/fuzz_targets/vm-implied.rs Outdated Show resolved Hide resolved
@addisoncrump
Copy link
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
Copy link
Member

jedel1043 commented Nov 6, 2022

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
Contributor Author

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

@addisoncrump
Copy link
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
Member

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

@addisoncrump
Copy link
Contributor Author

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

@jedel1043
Copy link
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
Contributor Author

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

@jedel1043
Copy link
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 Razican, jasonwilliams, raskad, jedel1043 and HalidOdat November 14, 2022 13:29
@addisoncrump
Copy link
Contributor Author

That is not what I thought those buttons did, whoops

Copy link
Member

@Razican Razican left a comment

Choose a reason for hiding this comment

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

Thanks!! LGTM!

@Razican
Copy link
Member

Razican commented Nov 15, 2022

@jedel1043 could you check if your comments were addressed?

Copy link
Member

@jedel1043 jedel1043 left a comment

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
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 <addison.crump@cispa.de>
@bors
Copy link

bors bot commented Nov 15, 2022

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
enhancement New feature or request 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