Skip to content
Memory corruption Write-up Advanced

CVE-2024-5274: A Minor Flaw in V8 Parser Leading to Catastrophes

A bug in V8's parser caused the `this` variable to be incorrectly marked as used in a class static block, leading to inconsistent bytecode after flushing. An attacker could exploit this to access the NativeContext and achieve type confusion, potentially leading to code execution.

darknavy.org

Published on darknavy.org

In May of this year, we noticed that Chrome fixed a V8 vulnerability that was being exploited in the wild in this update. We quickly pinpointed the fix for this vulnerability and discovered that it was a rare bug in the Parser module, which piqued our interest greatly.

DARKNAVY, on darknavy.org

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

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

How it worked

Root cause

The parser failed to isolate the expression scope when parsing a class static block, so a `this` reference inside the block incorrectly propagated to the outer function's scope.

Impact

An attacker could exploit this to achieve type confusion and potentially execute arbitrary code within the V8 engine.

What the attacker needed

Ability to run JavaScript in V8; trigger bytecode flushing

How it was found

  1. Create a function that contains an arrow function with a default parameter that is a class with a static block using `this`.
  2. Call the function to generate bytecode that incorrectly allocates `this` in the function context.
  3. Trigger bytecode flushing to discard the function's bytecode.
  4. Call the function again to regenerate bytecode without the unnecessary `this` allocation.
  5. Observe that inner functions still reference the old context slot, leading to access to the NativeContext.

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 write-up has not been written yet. The Original tab links to the source.

A parser bug in the JavaScript engine V8 made a function think it used a special variable called `this` when it didn't. This caused the engine to generate different code after a cleanup step, letting an attacker access internal objects and confuse types, which can lead to taking over the program.

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.

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.