Skip to content

fix: ScriptState crash for non-Blink v8::Contexts - #25910

Closed
codebytere wants to merge 2 commits into
masterfrom
fix-context-crash
Closed

codebytere wants to merge 2 commits into
masterfrom
fix-context-crash

Conversation

@codebytere

@codebytere codebytere commented Oct 13, 2020 •

Copy link
Copy Markdown
Member

Description of Change

Closes #25888.

In the renderer process it's possible that a v8::Context will be created by Node.js and therefore not have an associated ScriptState. Blink assumes one will be associated always, and thus crashes when trying to
fetch the DOMWrapperWorld for a ScriptState created from a non-Blink v8::Context.

This adds extra safety checks to ensure that ScriptContext::From correctly returns nullptr for those cases.

Tested with https://gist.github.com/7d0072e815f31a0ef54a625bd0b17d96.

Checklist

Release Notes

Notes: Fixed a potential crash when creating and using a new vm.Context in the renderer process.

@codebytere
codebytere requested a review from a team as a code owner October 13, 2020 05:54
@electron-cation electron-cation Bot added the new-pr 🌱 PR opened recently label Oct 13, 2020
@iron-man-forever

Copy link
Copy Markdown

but the code will hit the electron crash(Utils::ApiCheck) because i::EmbedderDataSlot(*data, index).ToAlignedPointer(&result) always false

@codebytere

codebytere commented Oct 13, 2020 •

Copy link
Copy Markdown
Member Author

@caihuan i didn't experience any issues when testing with https://gist.github.com/7d0072e815f31a0ef54a625bd0b17d96 after this fix -

[69847:1013/095537.481276:INFO:CONSOLE(1)] "10", source: evalmachine. (1)

was successfully printed to console.

@electron-cation electron-cation Bot removed the new-pr 🌱 PR opened recently label Oct 14, 2020
@iron-man-forever

iron-man-forever commented Oct 14, 2020 •

Copy link
Copy Markdown

@caihuan i didn't experience any issues when testing with https://gist.github.com/7d0072e815f31a0ef54a625bd0b17d96 after this fix -

[69847:1013/095537.481276:INFO:CONSOLE(1)] "10", source: evalmachine. (1)

was successfully printed to console.

the problem is post exception on node VM. console.log can print an integer value. you should test code like console.log(aaa).
the enviroment will post exception and hit the crash after cannot find aaa object.
console.log print undefined object not basic type

debug version will crash on Utils::ApiCheck(i::EmbedderDataSlot(*data, index).ToAlignedPointer(&result))

@iron-man-forever iron-man-forever mentioned this pull request Oct 14, 2020
3 tasks done

@zcbenz zcbenz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Patching blink like this would be an endless game, if we fixed console.log it is still possible to crash other unpatched code by passing things like WebAudio.

Even if we managed to patch all places of blink to ignore non-blink contexts, I think it would then raise questions about security.

@zcbenz
zcbenz requested a review from nornagon October 20, 2020 02:19
@codebytere

Copy link
Copy Markdown
Member Author

yeah - we may honestly want to simply leave this broken and mark it somewhere in docs

@nornagon

Copy link
Copy Markdown
Contributor

I agree with @zcbenz here, blink surely assumes in many places that all Contexts come with a ScriptState, and we're never going to be able to patch out all those assumptions.

Using node's vm module in the renderer process is asking for trouble.

@MarshallOfSound

Copy link
Copy Markdown
Member

Using node's vm module in the renderer process is asking for trouble.

So let's deprecate it? The web platform has proposals for a worlds API iirc so The Web Way isn't a too distant future

@codebytere

Copy link
Copy Markdown
Member Author

we already override some stuff in the renderer - seems reasonable to intercept vm and prevent its usage there. I'll close this out and do that.

@gzorin

gzorin commented Sep 22, 2021

Copy link
Copy Markdown

Using node's vm module in the renderer process is asking for trouble.

So let's deprecate it? The web platform has proposals for a worlds API iirc so The Web Way isn't a too distant future

I'm pretty interested in learning more about such a proposal, since at Bloomberg we've needed to hack Chromium quite a bit to get ordinary V8 contexts to cooperate with those created by Blink.

I couldn't find a link to any discussion or documents; do you have any references?

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.

electron crash when using node vm

7 participants