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

vm.runInContext is memory unsafe and can be used to dump core #8537

Closed
deian opened this issue Sep 14, 2016 · 4 comments
Closed

vm.runInContext is memory unsafe and can be used to dump core #8537

deian opened this issue Sep 14, 2016 · 4 comments
Labels
c++ Issues and PRs that require attention from people who are familiar with C++. vm Issues and PRs related to the vm subsystem.

Comments

@deian
Copy link
Member

deian commented Sep 14, 2016

  • Version: 6.5.0
  • Platform:
  • Subsystem: vm

vm.runInContext is memory unsafe and can be used to dump core.

This doesn't seem like a serious security vulnerability (hence my reporting here), but can certainly be used to cause DOS and it might be nice to have a stdlib that is memory safe.

const vm = require('vm');

const target = {a : 1337};

const handler = {
  getOwnPropertyDescriptor: (target, prop) => {
    throw 'w00t';
    // causes FromJust on line 128 of src/node_contextify.cc to dump core
  },
};

const sandbox = new Proxy(target, handler);


const context = new vm.createContext(sandbox);
const script = new vm.Script('');
script.runInContext(context);

Related to: #8539, #8538, #7902

@deian deian changed the title vm.runInContext is memory unsafe and can be used to dump core vm.runInContext is memory unsafe and can be used to dump core Sep 14, 2016
@mscdex mscdex added the vm Issues and PRs related to the vm subsystem. label Sep 14, 2016
@ChALkeR ChALkeR added the c++ Issues and PRs that require attention from people who are familiar with C++. label Sep 14, 2016
@imyller
Copy link
Member

imyller commented Sep 15, 2016

This is a known issue and affects most C++ API functions accepting non-primitive values.

For more information:

#7902 (comment)

@deian
Copy link
Member Author

deian commented Sep 17, 2016

I don't think this fits under that category. (We're the ones that found #7902 FWIW) This is already using MaybeLocal; in fact the bug is using that to cause the crash

@bnoordhuis
Copy link
Member

It's a variation on the same theme. CopyProperties() uses .FromJust() (which is basically success-or-die) when it should be using .FromMaybe() or .IsJust() and propagate pending exceptions.

@cjihrig
Copy link
Contributor

cjihrig commented Sep 18, 2016

@bnoordhuis thanks for hint. Proposed fix in #8649. Sorry if it is way off base.

cjihrig added a commit to cjihrig/node that referenced this issue Sep 20, 2016
This commit prevents thrown JavaScript exceptions from crashing
the process in node_contextify's CopyProperties() function.

Fixes: nodejs#8537
PR-URL: nodejs#8649
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: Franziska Hinkelmann <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Ilkka Myller <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
Fishrock123 pushed a commit that referenced this issue Oct 11, 2016
This commit prevents thrown JavaScript exceptions from crashing
the process in node_contextify's CopyProperties() function.

Fixes: #8537
PR-URL: #8649
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: Franziska Hinkelmann <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Ilkka Myller <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ Issues and PRs that require attention from people who are familiar with C++. vm Issues and PRs related to the vm subsystem.
Projects
None yet
Development

No branches or pull requests

7 participants