Skip to content

Commit fb57671

Browse files
szuendmibrunin
authored andcommitted
[Backport] CVE-2024-9959: Use after free in DevTools
Manual cherry-pick of patch originally reviewed on https://chromium-review.googlesource.com/c/chromium/src/+/5886170: Fix accessing disposed V8 session in page agent Scripts running as part of Page.evaluateScriptOnNewDocument can pause the page. During a pause we can detach the DevTools session, but the page agent is still in the middle of running the "DidCreateMainWorldContext" probe. This means any additional Page.evaluateScriptOnNewDocument scripts would attempt to eval on a detached V8 session. This CL fixes this by overriding InspectorBaseAgent::Dispose in the page agent and resetting `v8_session_` to a nullptr which we can check for before evaling more scripts. This check is only necessary for page agent methods that execute more than one JS script as for all the others we wouldn't call the probes on a disposed agent in the first place. [email protected], [email protected] Fixed: 368672129 Change-Id: I4c3361c8116a64343206da991e503aaa6bd917f6 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5886170 Reviewed-by: Danil Somsikov <[email protected]> Reviewed-by: Andrey Kosyakov <[email protected]> Commit-Queue: Simon Zünd <[email protected]> Cr-Commit-Position: refs/heads/main@{#1359730} Reviewed-on: https://codereview.qt-project.org/c/qt/qtwebengine-chromium/+/597921 Reviewed-by: Michal Klocek <[email protected]>
1 parent e2405bd commit fb57671

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

chromium/third_party/blink/renderer/core/inspector/inspector_page_agent.cc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,7 +1036,7 @@ void InspectorPageAgent::DidCreateMainWorldContext(LocalFrame* frame) {
10361036
return;
10371037
}
10381038
ScriptState* script_state = ToScriptStateForMainWorld(frame);
1039-
if (!script_state) {
1039+
if (!script_state || !v8_session_) {
10401040
return;
10411041
}
10421042

@@ -1061,7 +1061,7 @@ void InspectorPageAgent::EvaluateScriptOnNewDocument(
10611061
*DOMWrapperWorld::EnsureIsolatedWorld(
10621062
ToIsolate(window->GetFrame()), world->GetWorldId()));
10631063
}
1064-
if (!script_state) {
1064+
if (!script_state || !v8_session_) {
10651065
return;
10661066
}
10671067

@@ -1972,6 +1972,11 @@ void InspectorPageAgent::Trace(Visitor* visitor) const {
19721972
InspectorBaseAgent::Trace(visitor);
19731973
}
19741974

1975+
void InspectorPageAgent::Dispose() {
1976+
InspectorBaseAgent::Dispose();
1977+
v8_session_ = nullptr;
1978+
}
1979+
19751980
protocol::Response InspectorPageAgent::getOriginTrials(
19761981
const String& frame_id,
19771982
std::unique_ptr<protocol::Array<protocol::Page::OriginTrial>>*

chromium/third_party/blink/renderer/core/inspector/inspector_page_agent.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ class CORE_EXPORT InspectorPageAgent final
269269
bool ScreencastEnabled();
270270

271271
void Trace(Visitor*) const override;
272+
void Dispose() override;
272273

273274
private:
274275
struct IsolatedWorldRequest;

0 commit comments

Comments
 (0)