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

Runtime limits on "bad neighbors". #2350

Open
rhomber opened this issue Oct 17, 2022 · 3 comments
Open

Runtime limits on "bad neighbors". #2350

rhomber opened this issue Oct 17, 2022 · 3 comments
Labels
API enhancement New feature or request vm Issues and PRs related to the Boa Virtual Machine.

Comments

@rhomber
Copy link

rhomber commented Oct 17, 2022

As discussed on Discord (I'm Lyran Sage). We'd love to see some features added that can prevent untrusted code from preventing the execution of other tasks. It's our goal to be able to run several user provided scripts on the same thread at the same time (probably a runtime per execution).

To enable this to work and limit a single script from "blocking" the thread we need to have configurable limits on:

  1. Loops, to prevent "while(1)" attacks.
  2. Recursion or stack depth. Ideally based on stack depth.

Anything else that you guys can think of that could possibly lock up execution? I think the above two covers everything though really?

Thanks so much!

David

@rhomber rhomber added the enhancement New feature or request label Oct 17, 2022
@jedel1043 jedel1043 added API vm Issues and PRs related to the Boa Virtual Machine. labels Oct 17, 2022
@addisoncrump
Copy link
Contributor

The VM fuzzer PR (#2401) adds a mechanism for restricting the number of instructions. Could probably be used to complete (1) here.

@y21
Copy link
Contributor

y21 commented Nov 25, 2022

Memory limits might also be worth adding to the list (unless this already exists), otherwise one bad actor can OOM the whole process and bring all other scripts with it.

Also, I don't think limiting bytecode instructions is a good/reliable way to guard against lock ups, since this has no effect on native builtins.
For example, RegEx execution happens in native Rust code for the most part, and code abusing catastrophic backtracking will get the engine stuck in native code for a long while:

use boa_engine::Context;
fn main() {
    let mut cx = Context::builder().instructions_remaining(500).build();
    dbg!(cx.eval("/(a+)+b/.test('a'.repeat(31) + 'c');"));
}

This piece of JS code uses 13 instructions until it gets stuck.

There are plenty of other builtins that spend all of their time in native code and given long and complicated strings, can easily lock up the engine. Another example is BigInt('1'.repeat(1e7)).

@HalidOdat
Copy link
Member

If no body is working on Loops, to prevent "while(1)" attacks., I'll try to solve this :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API enhancement New feature or request vm Issues and PRs related to the Boa Virtual Machine.
Projects
Status: To do
Development

No branches or pull requests

5 participants