Skip to content

Commit 07655c9

Browse files
caseqmibrunin
authored andcommitted
[Backport] CVE-2021-21138: Use after free in DevTools
Manual backport of patch originally reviewed on https://chromium-review.googlesource.com/c/v8/v8/+/2437383: Do not pause on breaks while installing additional command line API A break may cause the session disconnect (and therefore agents destruction) on a nested message loop. The runtime agent code is generally prepared to handle this during evaluate, but the code outside of it may be not. Besides, having a break before the console API installed is generally not what user wants or expects, so just disable all breaks while installing the API. Bug: chromium:1122487 Change-Id: I1d40f5007f2e1e4ec07a50ef57988513d0309b7e Commit-Queue: Andrey Kosyakov <[email protected]> Reviewed-by: Yang Guo <[email protected]> Cr-Commit-Position: refs/heads/master@{#70209} Reviewed-by: Allan Sandfeld Jensen <[email protected]> Reviewed-by: Michal Klocek <[email protected]>
1 parent b21dac1 commit 07655c9

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

chromium/v8/src/api.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10072,6 +10072,12 @@ debug::PostponeInterruptsScope::PostponeInterruptsScope(v8::Isolate* isolate)
1007210072

1007310073
debug::PostponeInterruptsScope::~PostponeInterruptsScope() {}
1007410074

10075+
debug::DisableBreakScope::DisableBreakScope(v8::Isolate* isolate)
10076+
: scope_(std::make_unique<i::DisableBreak>(
10077+
reinterpret_cast<i::Isolate*>(isolate)->debug())) {}
10078+
debug::DisableBreakScope::~DisableBreakScope() = default;
10079+
10080+
1007510081
Local<String> CpuProfileNode::GetFunctionName() const {
1007610082
const i::ProfileNode* node = reinterpret_cast<const i::ProfileNode*>(this);
1007710083
i::Isolate* isolate = node->isolate();

chromium/v8/src/debug/debug-interface.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ struct CoverageScript;
2121
struct TypeProfileEntry;
2222
struct TypeProfileScript;
2323
class Coverage;
24+
class DisableBreak;
2425
class PostponeInterruptsScope;
2526
class Script;
2627
class TypeProfile;
@@ -502,6 +503,15 @@ class PostponeInterruptsScope {
502503
std::unique_ptr<i::PostponeInterruptsScope> scope_;
503504
};
504505

506+
class DisableBreakScope {
507+
public:
508+
explicit DisableBreakScope(v8::Isolate* isolate);
509+
~DisableBreakScope();
510+
private:
511+
std::unique_ptr<i::DisableBreak> scope_;
512+
};
513+
514+
505515
} // namespace debug
506516
} // namespace v8
507517

chromium/v8/src/inspector/injected-script.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
#include "src/inspector/injected-script.h"
3232

3333
#include "src/inspector/injected-script-source.h"
34+
#include "include/v8-inspector.h"
35+
#include "src/debug/debug-interface.h"
3436
#include "src/inspector/inspected-context.h"
3537
#include "src/inspector/protocol/Protocol.h"
3638
#include "src/inspector/remote-object-id.h"
@@ -43,8 +45,6 @@
4345
#include "src/inspector/v8-stack-trace-impl.h"
4446
#include "src/inspector/v8-value-utils.h"
4547

46-
#include "include/v8-inspector.h"
47-
4848
namespace v8_inspector {
4949

5050
namespace {
@@ -638,6 +638,7 @@ Response InjectedScript::wrapEvaluateResult(
638638

639639
v8::Local<v8::Object> InjectedScript::commandLineAPI() {
640640
if (m_commandLineAPI.IsEmpty()) {
641+
v8::debug::DisableBreakScope disable_break(m_context->isolate());
641642
m_commandLineAPI.Reset(
642643
m_context->isolate(),
643644
m_context->inspector()->console()->createCommandLineAPI(

0 commit comments

Comments
 (0)