Inappropriate implementation in V8 (CVE-2024-9121)
A debug assertion in V8's parser fails when parsing a class with a static function, due to a mismatch in function literal IDs. An attacker could trigger a crash in debug builds, but the report does not claim any impact on release builds.
Tashita Software Security Follow
Originally disclosed on Chrome VRP
- Fix shipped in 31 days
Security Bug
Important: Please do not change the component of this bug manually.
Please READ THIS FAQ before filing a bug: https://chromium.googlesource.com/chromium/src/+/HEAD/docs/security/faq.md
Please see the following link for instructions on filing security bugs: https://www.chromium.org/Home/chromium-security/reporting-security-bugs
Reports may be eligible for reward payments under the Chrome VRP: https://g.co/chrome/vrp
NOTE: Security bugs are normally made public once a fix has been widely deployed.
VULNERABILITY DETAILS
DCHECK on V8 Parser while parsing Class Static Functions.
Stack Trace
#
# Fatal error in ../../src/parsing/parser.cc, line 1120
# Debug check failed: class_info.static_elements_function_id == initializer_id (3 vs. 2).
#
#
#
#FailureMessage Object: 0x7fff9480e098
==== C stack trace ===============================
./v8_12.8.374.24/v8/out/x64.debug/libv8_libbase.so(v8::base::debug::StackTrace::StackTrace()+0x1e) [0x7f657912917e]
./v8_12.8.374.24/v8/out/x64.debug/libv8_libplatform.so(+0x5757d) [0x7f657908457d]
./v8_12.8.374.24/v8/out/x64.debug/libv8_libbase.so(V8_Fatal(char const*, int, char const*, ...)+0x205) [0x7f65790fc675]
./v8_12.8.374.24/v8/out/x64.debug/libv8_libbase.so(+0x5601c) [0x7f65790fc01c]
./v8_12.8.374.24/v8/out/x64.debug/libv8_libbase.so(V8_Dcheck(char const*, int, char const*)+0x4d) [0x7f65790fc74d]
./v8_12.8.374.24/v8/out/x64.debug/libv8.so(v8::internal::Parser::ParseClassForMemberInitialization(v8::internal::FunctionKind, int, int, int, v8::internal::AstRawString const*)+0x41a) [0x7f6575b8dffa]
./v8_12.8.374.24/v8/out/x64.debug/libv8.so(v8::internal::Parser::ParseFunction(v8::internal::Isolate*, v8::internal::ParseInfo*, v8::internal::Handle<v8::internal::SharedFunctionInfo>)+0x6a2) [0x7f6575b8d802]
./v8_12.8.374.24/v8/out/x64.debug/libv8.so(v8::internal::parsing::ParseFunction(v8::internal::ParseInfo*, v8::internal::Handle<v8::internal::SharedFunctionInfo>, v8::internal::Isolate*, v8::internal::parsing::ReportStatisticsMode)+0x362) [0x7f6575be22f2]
./v8_12.8.374.24/v8/out/x64.debug/libv8.so(v8::internal::parsing::ParseAny(v8::internal::ParseInfo*, v8::internal::Handle<v8::internal::SharedFunctionInfo>, v8::internal::Isolate*, v8::internal::parsing::ReportStatisticsMode)+0x1dc) [0x7f6575be254c]
./v8_12.8.374.24/v8/out/x64.debug/libv8.so(+0x6e71a0e) [0x7f6575071a0e]
./v8_12.8.374.24/v8/out/x64.debug/libv8.so(v8::internal::ErrorUtils::NewCalledNonCallableError(v8::internal::Isolate*, v8::internal::Handle<v8::internal::Object>)+0x7b) [0x7f657507291b]
./v8_12.8.374.24/v8/out/x64.debug/libv8.so(+0x7bbadd2) [0x7f6575dbadd2]
./v8_12.8.374.24/v8/out/x64.debug/libv8.so(v8::internal::Runtime_ThrowCalledNonCallable(int, unsigned long*, v8::internal::Isolate*)+0xf8) [0x7f6575dbaca8]
./v8_12.8.374.24/v8/out/x64.debug/libv8.so(+0x608133d) [0x7f657428133d]
Reproduction Steps
- Build 12.8.374.24 with Debug mode by adding
is_debug = trueinto args.gn. - Execute the testcase attached:
./d8 reduced_dcheck_class_static_function.js - It should print the DCheck mentioned on the Stack Trace.
Root Cause
Initial considerations:
- The misaligment between
class_info.static_elements_function_idandinitializer_idtriggers the DCheck which happens insideParseClassForMemberInitializationfunction:DCHECK_EQ(class_info.static_elements_function_id, initializer_id); ParseClassForMemberInitializationreceives theinitializer_idby parameter.class_info.static_elements_function_idgets the value offunction_literal_id_which is a member ofparser-base.hfunction_literal_id_can be manipulated by the functions:GetNextFunctionLiteralId,SkipFunctionLiteralsandResetFunctionLiteralId.
The problem:
FunctionLiteral* Parser::ParseClassForMemberInitialization(
FunctionKind initalizer_kind, int initializer_pos, int initializer_id,
int initializer_end_pos, const AstRawString* class_name) {
...
ResetFunctionLiteralId(); //[1]
SkipFunctionLiterals(initializer_id - 1); //[2]
...
ParseClassLiteralBody(class_info, class_name, class_token_pos, Token::kEos); //[3]
if (initalizer_kind == FunctionKind::kClassMembersInitializerFunction) {
...
} else {
DCHECK_EQ(class_info.static_elements_function_id, initializer_id); //[4]
initializer = CreateStaticElementsInitializer(class_name, &class_info);
}
...
}
...
DCHECK_EQ(initializer->function_literal_id(), initializer_id); //[5]
...
}
[1] and [2] are used to set an initial value to function_literal_id_. As can be observed, it sets the value of initializer_id - 1, assuming that function_literal_id_ will be increased only once. The problem is that ParseClassLiteralBody ([3]) increases multiple times the function_literal_id_ variable causing the misaligment.
Multiple Increases of function_literal_id_:
template <typename Impl>
typename ParserBase<Impl>::ClassLiteralPropertyT
ParserBase<Impl>::ParseClassPropertyDefinition(ClassInfo* class_info,
ParsePropertyInfo* prop_info,
bool has_extends) {
...
if (name_token == Token::kStatic) {
...
if (peek() == Token::kLeftParen) {
...
} else if (peek() == Token::kAssign || peek() == Token::kSemicolon ||
peek() == Token::kRightBrace) {
...
} else {
prop_info->is_static = true;
name_expression = ParseProperty(prop_info); //[6]
}
} else {
...
}
switch (prop_info->kind) {
case ParsePropertyKind::kAssign:
case ParsePropertyKind::kClassField:
case ParsePropertyKind::kShorthandOrClassField:
case ParsePropertyKind::kNotSet: {
...
ExpressionT initializer = ParseMemberInitializer(
class_info, property_beg_pos, prop_info->is_static); //[7]
...
//[8]
[6] ParseProperty increases the function_literal_id_ via ParseFunctionLiteral function. Full backtrace:
#0 0x00004f0e3d4d174b in v8::internal::ParserBase<v8::internal::Parser>::GetNextFunctionLiteralId (this=0x7fff7da5ec50) at ../../src/parsing/parser-base.h:296
#1 0x00004f0e3d4c39b0 in v8::internal::Parser::ParseFunctionLiteral (this=0x7fff7da5ec50, function_name=0x559dcbee9108, function_name_location=..., function_name_validity=v8::internal::kFunctionNameValidityUnknown, kind=v8::internal::FunctionKind::kNormalFunction,
function_token_pos=0x18, function_syntax_kind=v8::internal::FunctionSyntaxKind::kAnonymousExpression, language_mode=v8::internal::LanguageMode::kStrict, arguments_for_wrapped_function=0x0) at ../../src/parsing/parser.cc:2733
#2 0x00004f0e3d4f6a83 in v8::internal::ParserBase<v8::internal::Parser>::ParseFunctionExpression (this=0x7fff7da5ec50) at ../../src/parsing/parser-base.h:3960
#3 0x00004f0e3d4f54cd in v8::internal::ParserBase<v8::internal::Parser>::ParsePrimaryExpression (this=0x7fff7da5ec50) at ../../src/parsing/parser-base.h:2121
#4 0x00004f0e3d4f45a7 in v8::internal::ParserBase<v8::internal::Parser>::ParseMemberExpression (this=0x7fff7da5ec50) at ../../src/parsing/parser-base.h:3987
#5 0x00004f0e3d4f4447 in v8::internal::ParserBase<v8::internal::Parser>::ParseLeftHandSideExpression (this=0x7fff7da5ec50) at ../../src/parsing/parser-base.h:3709
#6 0x00004f0e3d4f32ba in v8::internal::ParserBase<v8::internal::Parser>::ParsePostfixExpression (this=0x7fff7da5ec50) at ../../src/parsing/parser-base.h:3676
#7 0x00004f0e3d4f2bde in v8::internal::ParserBase<v8::internal::Parser>::ParseUnaryExpression (this=0x7fff7da5ec50) at ../../src/parsing/parser-base.h:3666
#8 0x00004f0e3d4f24ac in v8::internal::ParserBase<v8::internal::Parser>::ParseBinaryExpression (this=0x7fff7da5ec50, prec=0x6) at ../../src/parsing/parser-base.h:3548
#9 0x00004f0e3d4f1dac in v8::internal::ParserBase<v8::internal::Parser>::ParseLogicalExpression (this=0x7fff7da5ec50) at ../../src/parsing/parser-base.h:3318
#10 0x00004f0e3d4f07fa in v8::internal::ParserBase<v8::internal::Parser>::ParseConditionalExpression (this=0x7fff7da5ec50) at ../../src/parsing/parser-base.h:3303
#11 0x00004f0e3d4f0316 in v8::internal::ParserBase<v8::internal::Parser>::ParseAssignmentExpressionCoverGrammar (this=0x7fff7da5ec50) at ../../src/parsing/parser-base.h:3090
#12 0x00004f0e3d4d77e5 in v8::internal::ParserBase<v8::internal::Parser>::ParseAssignmentExpression (this=0x7fff7da5ec50) at ../../src/parsing/parser-base.h:2229
#13 0x00004f0e3d5002e4 in v8::internal::ParserBase<v8::internal::Parser>::ParseProperty (this=0x7fff7da5ec50, prop_info=0x7fff7da5e700) at ../../src/parsing/parser-base.h:2486
[7] ParseMemberInitializer increases the function_literal_id_ via EnsureStaticElementsScope. Full backtrace:
#0 0x00004f0e3d4d174b in v8::internal::ParserBase<v8::internal::Parser>::GetNextFunctionLiteralId (this=0x7fff7da5ec50) at ../../src/parsing/parser-base.h:296
#1 0x00004f0e3d5036f8 in v8::internal::ParserBase<v8::internal::Parser>::ClassInfo::EnsureStaticElementsScope (this=0x7fff7da5e7e0, parser=0x7fff7da5ec50, beg_pos=0x10) at ../../src/parsing/parser-base.h:623
#2 0x00004f0e3d504576 in v8::internal::ParserBase<v8::internal::Parser>::ParseMemberInitializer (this=0x7fff7da5ec50, class_info=0x7fff7da5e7e0, beg_pos=0x10, is_static=0x1) at ../../src/parsing/parser-base.h:2696
[8] At this moment, the mismatch is already set. The function returns until the DCheck is hit.
Bisect: Introduced Commit
Commit: cca606336c6753a2ddcd425019c1be11f9ba6216
Title: [parser] Only reparse the relevant segments for class initializers
Review: https://chromium-review.googlesource.com/c/v8/v8/+/5676330
Bisect: Introduced Major Chrome
Chrome Stable: 128.0.6613.84
VERSION
Chrome Version: [128.0.6613.113] + [stable] Operating System: [All]
REPRODUCTION CASE
Attached: reduced_dcheck_class_static_function.js
FOR CRASHES, PLEASE INCLUDE THE FOLLOWING ADDITIONAL INFORMATION
Type of crash: [Browser]
CREDIT INFORMATION
Reporter credit: Tashita Software Security
Context
V8 is the JavaScript engine used by Chrome. Before code runs, V8 parses it, and the parser assigns every function literal an identifier (function_literal_id_) that later stages rely on to match a function's scope with its compiled body. Class definitions with static members are parsed in a special path: ParseClassForMemberInitialization re-parses the class body to build the initialiser for static elements, and it has to arrive at exactly the same literal identifiers as the first pass.
This report describes a debug assertion failure in that path. When a class contains a static member whose name is a function expression, the parser increments function_literal_id_ more times than the initialiser path expects, and a DCHECK in ParseClassForMemberInitialization fires. The issue was tracked as CVE-2024-9121, an inappropriate implementation in V8, rated high severity, and was disclosed on 1 October 2024. The reporter credit is Tashita Software Security, and the Chrome VRP paid a bounty of 8,000 USD.
Setup
The researcher built V8 from source at version 12.8.374.24 in debug mode. The only build change needed was to add is_debug = true to args.gn. The test case was run with the d8 shell, the standalone V8 command line tool, using a reduced JavaScript file named reduced_dcheck_class_static_function.js.
The report lists the affected Chrome version as 128.0.6613.113 on the stable channel, with the operating system listed as all. The crash type is recorded as browser.
Finding it
The reduced test case is a class static function, as its file name suggests; the report does not include its contents. In that shape the parser walks the property name through ParseProperty, which parses a function literal and consumes a literal id, and then walks the member initialiser through ParseMemberInitializer, which calls EnsureStaticElementsScope and consumes another literal id. The initialiser re-parse path had assumed only one increment would happen between resetting the counter and checking it.
On a debug build the mismatch is not silent: the engine aborts with a fatal error. The stack trace from the reduced test case is:
#
# Fatal error in ../../src/parsing/parser.cc, line 1120
# Debug check failed: class_info.static_elements_function_id == initializer_id (3 vs. 2).
#
#
#
#FailureMessage Object: 0x7fff9480e098
==== C stack trace ===============================
./v8_12.8.374.24/v8/out/x64.debug/libv8_libbase.so(v8::base::debug::StackTrace::StackTrace()+0x1e) [0x7f657912917e]
./v8_12.8.374.24/v8/out/x64.debug/libv8_libplatform.so(+0x5757d) [0x7f657908457d]
./v8_12.8.374.24/v8/out/x64.debug/libv8_libbase.so(V8_Fatal(char const*, int, char const*, ...)+0x205) [0x7f65790fc675]
./v8_12.8.374.24/v8/out/x64.debug/libv8_libbase.so(+0x5601c) [0x7f65790fc01c]
./v8_12.8.374.24/v8/out/x64.debug/libv8_libbase.so(V8_Dcheck(char const*, int, char const*)+0x4d) [0x7f65790fc74d]
./v8_12.8.374.24/v8/out/x64.debug/libv8.so(v8::internal::Parser::ParseClassForMemberInitialization(v8::internal::FunctionKind, int, int, int, v8::internal::AstRawString const*)+0x41a) [0x7f6575b8dffa]
./v8_12.8.374.24/v8/out/x64.debug/libv8.so(v8::internal::Parser::ParseFunction(v8::internal::Isolate*, v8::internal::ParseInfo*, v8::internal::Handle<v8::internal::SharedFunctionInfo>)+0x6a2) [0x7f6575b8d802]
./v8_12.8.374.24/v8/out/x64.debug/libv8.so(v8::internal::parsing::ParseFunction(v8::internal::ParseInfo*, v8::internal::Handle<v8::internal::SharedFunctionInfo>, v8::internal::Isolate*, v8::internal::parsing::ReportStatisticsMode)+0x362) [0x7f6575be22f2]
./v8_12.8.374.24/v8/out/x64.debug/libv8.so(v8::internal::parsing::ParseAny(v8::internal::ParseInfo*, v8::internal::Handle<v8::internal::SharedFunctionInfo>, v8::internal::Isolate*, v8::internal::parsing::ReportStatisticsMode)+0x1dc) [0x7f6575be254c]
./v8_12.8.374.24/v8/out/x64.debug/libv8.so(+0x6e71a0e) [0x7f6575071a0e]
./v8_12.8.374.24/v8/out/x64.debug/libv8.so(v8::internal::ErrorUtils::NewCalledNonCallableError(v8::internal::Isolate*, v8::internal::Handle<v8::internal::Object>)+0x7b) [0x7f657507291b]
./v8_12.8.374.24/v8/out/x64.debug/libv8.so(+0x7bbadd2) [0x7f6575dbadd2]
./v8_12.8.374.24/v8/out/x64.debug/libv8.so(v8::internal::Runtime_ThrowCalledNonCallable(int, unsigned long*, v8::internal::Isolate*)+0xf8) [0x7f6575dbaca8]
./v8_12.8.374.24/v8/out/x64.debug/libv8.so(+0x608133d) [0x7f657428133d]
The check that failed compares class_info.static_elements_function_id with initializer_id and reports the values 3 and 2, so the static elements scope had advanced one literal id further than the initialiser id passed into the function.
Exploitation
Step 1: build a debug V8
Build 12.8.374.24 in debug mode by adding the following to args.gn:
is_debug = true
The reproduction uses a debug build, where the failing check is active.
Step 2: run the reduced test case
Execute the attached test case with the d8 shell:
./d8 reduced_dcheck_class_static_function.js
The expected result is the fatal error and stack trace shown above. The report does not include the contents of the test case file, only its name.
Root cause
The assertion lives in ParseClassForMemberInitialization, which receives initializer_id as a parameter and compares it against class_info.static_elements_function_id. That field takes its value from function_literal_id_, a member of parser-base.h that can be moved by GetNextFunctionLiteralId, SkipFunctionLiterals and ResetFunctionLiteralId.
The relevant part of the function is:
FunctionLiteral* Parser::ParseClassForMemberInitialization(
FunctionKind initalizer_kind, int initializer_pos, int initializer_id,
int initializer_end_pos, const AstRawString* class_name) {
...
ResetFunctionLiteralId(); //[1]
SkipFunctionLiterals(initializer_id - 1); //[2]
...
ParseClassLiteralBody(class_info, class_name, class_token_pos, Token::kEos); //[3]
if (initalizer_kind == FunctionKind::kClassMembersInitializerFunction) {
...
} else {
DCHECK_EQ(class_info.static_elements_function_id, initializer_id); //[4]
initializer = CreateStaticElementsInitializer(class_name, &class_info);
}
...
}
...
DCHECK_EQ(initializer->function_literal_id(), initializer_id); //[5]
...
}
Steps [1] and [2] reset the counter and then skip forward to initializer_id - 1, which assumes that parsing the class body will increment function_literal_id_ exactly once. ParseClassLiteralBody at [3] can increment it more than once, and the mismatch is then caught at [4].
The extra increments come from ParseClassPropertyDefinition:
template <typename Impl>
typename ParserBase<Impl>::ClassLiteralPropertyT
ParserBase<Impl>::ParseClassPropertyDefinition(ClassInfo* class_info,
ParsePropertyInfo* prop_info,
bool has_extends) {
...
if (name_token == Token::kStatic) {
...
if (peek() == Token::kLeftParen) {
...
} else if (peek() == Token::kAssign || peek() == Token::kSemicolon ||
peek() == Token::kRightBrace) {
...
} else {
prop_info->is_static = true;
name_expression = ParseProperty(prop_info); //[6]
}
} else {
...
}
switch (prop_info->kind) {
case ParsePropertyKind::kAssign:
case ParsePropertyKind::kClassField:
case ParsePropertyKind::kShorthandOrClassField:
case ParsePropertyKind::kNotSet: {
...
ExpressionT initializer = ParseMemberInitializer(
class_info, property_beg_pos, prop_info->is_static); //[7]
...
//[8]
At [6], ParseProperty consumes a literal id through ParseFunctionLiteral. The backtrace for that increment is:
#0 0x00004f0e3d4d174b in v8::internal::ParserBase<v8::internal::Parser>::GetNextFunctionLiteralId (this=0x7fff7da5ec50) at ../../src/parsing/parser-base.h:296
#1 0x00004f0e3d4c39b0 in v8::internal::Parser::ParseFunctionLiteral (this=0x7fff7da5ec50, function_name=0x559dcbee9108, function_name_location=..., function_name_validity=v8::internal::kFunctionNameValidityUnknown, kind=v8::internal::FunctionKind::kNormalFunction,
function_token_pos=0x18, function_syntax_kind=v8::internal::FunctionSyntaxKind::kAnonymousExpression, language_mode=v8::internal::LanguageMode::kStrict, arguments_for_wrapped_function=0x0) at ../../src/parsing/parser.cc:2733
#2 0x00004f0e3d4f6a83 in v8::internal::ParserBase<v8::internal::Parser>::ParseFunctionExpression (this=0x7fff7da5ec50) at ../../src/parsing/parser-base.h:3960
#3 0x00004f0e3d4f54cd in v8::internal::ParserBase<v8::internal::Parser>::ParsePrimaryExpression (this=0x7fff7da5ec50) at ../../src/parsing/parser-base.h:2121
#4 0x00004f0e3d4f45a7 in v8::internal::ParserBase<v8::internal::Parser>::ParseMemberExpression (this=0x7fff7da5ec50) at ../../src/parsing/parser-base.h:3987
#5 0x00004f0e3d4f4447 in v8::internal::ParserBase<v8::internal::Parser>::ParseLeftHandSideExpression (this=0x7fff7da5ec50) at ../../src/parsing/parser-base.h:3709
#6 0x00004f0e3d4f32ba in v8::internal::ParserBase<v8::internal::Parser>::ParsePostfixExpression (this=0x7fff7da5ec50) at ../../src/parsing/parser-base.h:3676
#7 0x00004f0e3d4f2bde in v8::internal::ParserBase<v8::internal::Parser>::ParseUnaryExpression (this=0x7fff7da5ec50) at ../../src/parsing/parser-base.h:3666
#8 0x00004f0e3d4f24ac in v8::internal::ParserBase<v8::internal::Parser>::ParseBinaryExpression (this=0x7fff7da5ec50, prec=0x6) at ../../src/parsing/parser-base.h:3548
#9 0x00004f0e3d4f1dac in v8::internal::ParserBase<v8::internal::Parser>::ParseLogicalExpression (this=0x7fff7da5ec50) at ../../src/parsing/parser-base.h:3318
#10 0x00004f0e3d4f07fa in v8::internal::ParserBase<v8::internal::Parser>::ParseConditionalExpression (this=0x7fff7da5ec50) at ../../src/parsing/parser-base.h:3303
#11 0x00004f0e3d4f0316 in v8::internal::ParserBase<v8::internal::Parser>::ParseAssignmentExpressionCoverGrammar (this=0x7fff7da5ec50) at ../../src/parsing/parser-base.h:3090
#12 0x00004f0e3d4d77e5 in v8::internal::ParserBase<v8::internal::Parser>::ParseAssignmentExpression (this=0x7fff7da5ec50) at ../../src/parsing/parser-base.h:2229
#13 0x00004f0e3d5002e4 in v8::internal::ParserBase<v8::internal::Parser>::ParseProperty (this=0x7fff7da5ec50, prop_info=0x7fff7da5e700) at ../../src/parsing/parser-base.h:2486
At [7], ParseMemberInitializer consumes another literal id through EnsureStaticElementsScope. The backtrace for that increment is:
#0 0x00004f0e3d4d174b in v8::internal::ParserBase<v8::internal::Parser>::GetNextFunctionLiteralId (this=0x7fff7da5ec50) at ../../src/parsing/parser-base.h:296
#1 0x00004f0e3d5036f8 in v8::internal::ParserBase<v8::internal::Parser>::ClassInfo::EnsureStaticElementsScope (this=0x7fff7da5e7e0, parser=0x7fff7da5ec50, beg_pos=0x10) at ../../src/parsing/parser-base.h:623
#2 0x00004f0e3d504576 in v8::internal::ParserBase<v8::internal::Parser>::ParseMemberInitializer (this=0x7fff7da5ec50, class_info=0x7fff7da5e7e0, beg_pos=0x10, is_static=0x1) at ../../src/parsing/parser-base.h:2696
By [8] the mismatch is already established, and the function returns up the stack until the check at [4] fires.
The report attributes the regression to commit [redacted], titled "[parser] Only reparse the relevant segments for class initializers", reviewed at https://chromium-review.googlesource.com/c/v8/v8/+/5676330. The first major Chrome release containing it, per the bisect, was Chrome Stable 128.0.6613.84.
Impact
The observable effect in the report is a fatal debug assertion during parsing of a class static function, which aborts the engine. The report does not describe a release-mode consequence, and the failing check is a debug-only assertion, so the practical impact on shipped Chrome builds is not established by the text. The severity assigned by the program was high.
Fix
The report does not state which change fixed the issue. It identifies the mismatch between static_elements_function_id and initializer_id after ParseClassLiteralBody as the root cause.
Variants to test
- The reduced case on other V8 versions around 12.8.374.24 in debug builds. A positive result is the same
Debug check failed: class_info.static_elements_function_id == initializer_idfatal error. - Other member-name expressions that parse a function literal, combined with a static member initialiser. A positive result is the same assertion or a related literal-id mismatch in the initialiser path.
- Classes with several static members, mixing function-expression names and initialisers, to see whether the gap between
static_elements_function_idandinitializer_idgrows with each member. A positive result is a larger difference in the assertion message than the 3 vs. 2 seen here. - The same shapes under the class members initialiser kind rather than the static elements kind, to check whether the other branch of
ParseClassForMemberInitializationis affected. A positive result is a failure at the later check oninitializer->function_literal_id().
What happened, in plain words
Chrome runs JavaScript, the language that makes web pages interactive. The part of Chrome that reads and understands JavaScript is called V8. Before any JavaScript can run, V8 has to read it and break it into pieces, a bit like a proofreader marking up a manuscript before it goes to print. This reading step is called parsing.
While parsing, V8 gives every function it finds a number, so that later stages can tell one function apart from another. Think of it like giving every parcel in a warehouse a tracking number: if two parcels end up with the same number, or a number is skipped, the sorting machine gets confused.
This report is about a situation where V8's internal numbering goes wrong. When a class (a template for creating objects in JavaScript) has a static member (a member that belongs to the class itself rather than to individual objects made from it), V8 can count one number too many. In a special build of V8 used for testing, called a debug build, the engine notices the mismatch and stops with a fatal error. The reproduction uses a debug build, where the check is active.
The problem was catalogued as CVE-2024-9121. CVE stands for Common Vulnerabilities and Exposures: a public catalogue number given to a known security flaw so people can refer to it unambiguously. It was classified as an "inappropriate implementation" in V8, rated high severity, and made public on 1 October 2024. The person or team credited is Tashita Software Security, and Google's Chrome Vulnerability Reward Program (VRP, a scheme that pays people for reporting security bugs) paid a bounty of 8,000 US dollars.
Context
V8 is the JavaScript engine used by Chrome. An engine, in this sense, is the component that takes the text of a program and turns it into something the computer can actually execute. Before code runs, V8 parses it. The parser assigns every function literal an identifier, stored in a variable called function_literal_id_. A function literal is simply a function written out in the code, as opposed to one that is referenced by name from somewhere else. Later stages rely on these identifiers to match a function's scope (the region of code where its variables are visible) with its compiled body (the version translated into machine instructions).
Class definitions with static members are parsed in a special path: a function called ParseClassForMemberInitialization re-parses the class body to build the initialiser for static elements. An initialiser is the piece of code that sets up a value when something is created. Because the class body is parsed a second time, the parser has to arrive at exactly the same literal identifiers as the first pass. If the two passes disagree, the identifiers no longer line up.
This report describes a debug assertion failure in that path. An assertion is a check a program makes about its own internal state, like a self-check a cashier does on the till before opening: if the numbers do not add up, the program stops rather than carry on with bad data. A DCHECK is a particular kind of assertion in V8 that only exists in debug builds. When a class contains a static member whose name is a function expression, the parser increments function_literal_id_ more times than the initialiser path expects, and a DCHECK in ParseClassForMemberInitialization fires.
The issue was tracked as CVE-2024-9121, an inappropriate implementation in V8, rated high severity, and was disclosed on 1 October 2024. The reporter credit is Tashita Software Security, and the Chrome VRP paid a bounty of 8,000 USD.
Setup
The researcher built V8 from source at version 12.8.374.24 in debug mode. Building from source means compiling the program yourself from its code, rather than downloading a ready-made copy. The only build change needed was to add is_debug = true to args.gn. args.gn is a configuration file that tells the build system which options to use; setting is_debug = true switches on the debug build, which includes the extra self-checks.
The test case was run with the d8 shell, the standalone V8 command line tool. A shell here means a small program that lets you run JavaScript directly without a browser around it, useful for testing the engine in isolation. The file used was a reduced JavaScript file named reduced_dcheck_class_static_function.js. "Reduced" means the researcher trimmed the original triggering code down to the smallest version that still reproduces the problem, which makes it easier to analyse.
The report lists the affected Chrome version as 128.0.6613.113 on the stable channel, with the operating system listed as all. The crash type is recorded as browser.
Finding it
The reduced test case is a class static function, as its file name suggests; the report does not include its contents. In that shape the parser walks the property name through ParseProperty, which parses a function literal and consumes a literal id, and then walks the member initialiser through ParseMemberInitializer, which calls EnsureStaticElementsScope and consumes another literal id. "Consumes" here means it takes the next number from the counter, the way a ticket machine hands out the next ticket in sequence. The initialiser re-parse path had assumed only one increment would happen between resetting the counter and checking it.
On a debug build the mismatch is not silent: the engine aborts with a fatal error. The stack trace from the reduced test case is:
#
# Fatal error in ../../src/parsing/parser.cc, line 1120
# Debug check failed: class_info.static_elements_function_id == initializer_id (3 vs. 2).
#
#
#
#FailureMessage Object: 0x7fff9480e098
==== C stack trace ===============================
./v8_12.8.374.24/v8/out/x64.debug/libv8_libbase.so(v8::base::debug::StackTrace::StackTrace()+0x1e) [0x7f657912917e]
./v8_12.8.374.24/v8/out/x64.debug/libv8_libplatform.so(+0x5757d) [0x7f657908457d]
./v8_12.8.374.24/v8/out/x64.debug/libv8_libbase.so(V8_Fatal(char const*, int, char const*, ...)+0x205) [0x7f65790fc675]
./v8_12.8.374.24/v8/out/x64.debug/libv8_libbase.so(+0x5601c) [0x7f65790fc01c]
./v8_12.8.374.24/v8/out/x64.debug/libv8_libbase.so(V8_Dcheck(char const*, char const*)+0x4d) [0x7f65790fc74d]
./v8_12.8.374.24/v8/out/x64.debug/libv8.so(v8::internal::Parser::ParseClassForMemberInitialization(v8::internal::FunctionKind, int, int, int, v8::internal::AstRawString const*)+0x41a) [0x7f6575b8dffa]
./v8_12.8.374.24/v8/out/x64.debug/libv8.so(v8::internal::Parser::ParseFunction(v8::internal::Isolate*, v8::internal::ParseInfo*, v8::internal::Handle<v8::internal::SharedFunctionInfo>)+0x6a2) [0x7f6575b8d802]
./v8_12.8.374.24/v8/out/x64.debug/libv8.so(v8::internal::parsing::ParseFunction(v8::internal::ParseInfo*, v8::internal::Handle<v8::internal::SharedFunctionInfo>, v8::internal::Isolate*, v8::internal::parsing::ReportStatisticsMode)+0x362) [0x7f6575be22f2]
./v8_12.8.374.24/v8/out/x64.debug/libv8.so(v8::internal::parsing::ParseAny(v8::internal::ParseInfo*, v8::internal::Handle<v8::internal::SharedFunctionInfo>, v8::internal::Isolate*, v8::internal::parsing::ReportStatisticsMode)+0x1dc) [0x7f6575be254c]
./v8_12.8.374.24/v8/out/x64.debug/libv8.so(+0x6e71a0e) [0x7f6575071a0e]
./v8_12.8.374.24/v8/out/x64.debug/libv8.so(v8::internal::ErrorUtils::NewCalledNonCallableError(v8::internal::Isolate*, v8::internal::Handle<v8::internal::Object>)+0x7b) [0x7f657507291b]
./v8_12.8.374.24/v8/out/x64.debug/libv8.so(+0x7bbadd2) [0x7f6575dbadd2]
./v8_12.8.374.24/v8/out/x64.debug/libv8.so(v8::internal::Runtime_ThrowCalledNonCallable(int, unsigned long*, v8::internal::Isolate*)+0xf8) [0x7f6575dbaca8]
./v8_12.8.374.24/v8/out/x64.debug/libv8.so(+0x608133d) [0x7f657428133d]
This block is the engine's own account of what went wrong, printed at the moment it gave up. Line by line:
- The first lines say the fatal error happened in
parser.cc, line 1120, and that a debug check failed. The check was comparingclass_info.static_elements_function_idwithinitializer_id, and the two values were 3 and 2. FailureMessage Objectis an internal memory address where the failure details were stored. Addresses like this are meaningless outside the machine that produced them.- The
C stack tracesection lists the chain of function calls that led to the failure, from the outermost call at the top to the innermost at the bottom. Each line names a shared library file (.so), a function, and an offset. Reading it from the bottom up tells you the order in which the code was entered. - The line mentioning
V8_Dcheckis the assertion mechanism itself. The line mentioningParseClassForMemberInitializationis the function where the check lives. The lines below it show the parser being invoked to parse a function, which is how the class body got there in the first place.
The check that failed compares class_info.static_elements_function_id with initializer_id and reports the values 3 and 2, so the static elements scope had advanced one literal id further than the initialiser id passed into the function.
Exploitation
Step 1: build a debug V8
Build 12.8.374.24 in debug mode by adding the following to args.gn:
is_debug = true
This single line tells the build system to produce a debug build. In plain terms, it is the switch that turns on all the internal self-checks, including the DCHECK that catches this bug. The reproduction uses a debug build, where the failing check is active.
Step 2: run the reduced test case
Execute the attached test case with the d8 shell:
./d8 reduced_dcheck_class_static_function.js
This command runs the d8 program (the ./ means "the copy in the current folder") and hands it the JavaScript file to execute. The expected result is the fatal error and stack trace shown above. The report does not include the contents of the test case file, only its name.
Root cause
The assertion lives in ParseClassForMemberInitialization, which receives initializer_id as a parameter and compares it against class_info.static_elements_function_id. A parameter is a value handed to a function when it is called, like an ingredient handed to a cook. That field takes its value from function_literal_id_, a member of parser-base.h that can be moved by GetNextFunctionLiteralId, SkipFunctionLiterals and ResetFunctionLiteralId. In other words, three helper functions can change the counter: one takes the next number, one skips ahead by a given amount, and one resets it to the start.
The relevant part of the function is:
FunctionLiteral* Parser::ParseClassForMemberInitialization(
FunctionKind initalizer_kind, int initializer_pos, int initializer_id,
int initializer_end_pos, const AstRawString* class_name) {
...
ResetFunctionLiteralId(); //[1]
SkipFunctionLiterals(initializer_id - 1); //[2]
...
ParseClassLiteralBody(class_info, class_name, class_token_pos, Token::kEos); //[3]
if (initalizer_kind == FunctionKind::kClassMembersInitializerFunction) {
...
} else {
DCHECK_EQ(class_info.static_elements_function_id, initializer_id); //[4]
initializer = CreateStaticElementsInitializer(class_name, &class_info);
}
...
}
...
DCHECK_EQ(initializer->function_literal_id(), initializer_id); //[5]
...
}
Line by line:
- The first lines declare the function and its parameters: the kind of initialiser, a start position, the
initializer_idnumber, an end position, and the class name. ResetFunctionLiteralId(); //[1]puts the counter back to its starting value, like resetting a tally counter to zero.SkipFunctionLiterals(initializer_id - 1); //[2]then fast-forwards the counter to one below the target number. The idea is that parsing the class body will add exactly one more, landing on the target.ParseClassLiteralBody(...); //[3]is the step that parses the class body. This is where the extra increments happen.- The
ifbranch handles one kind of initialiser; theelsebranch handles the static elements case, and inside it theDCHECK_EQ(...) //[4]compares the two numbers.DCHECK_EQmeans "debug check that these two are equal". CreateStaticElementsInitializer(...)builds the initialiser once the check has passed.- The final
DCHECK_EQ(initializer->function_literal_id(), initializer_id); //[5]is a second check, further down, that the initialiser's own identifier matches the expected one.
Steps [1] and [2] reset the counter and then skip forward to initializer_id - 1, which assumes that parsing the class body will increment function_literal_id_ exactly once. ParseClassLiteralBody at [3] can increment it more than once, and the mismatch is then caught at [4].
The extra increments come from ParseClassPropertyDefinition:
template <typename Impl>
typename ParserBase<Impl>::ClassLiteralPropertyT
ParserBase<Impl>::ParseClassPropertyDefinition(ClassInfo* class_info,
ParsePropertyInfo* prop_info,
bool has_extends) {
...
if (name_token == Token::kStatic) {
...
if (peek() == Token::kLeftParen) {
...
} else if (peek() == Token::kAssign || peek() == Token::kSemicolon ||
peek() == Token::kRightBrace) {
...
} else {
prop_info->is_static = true;
name_expression = ParseProperty(prop_info); //[6]
}
} else {
...
}
switch (prop_info->kind) {
case ParsePropertyKind::kAssign:
case ParsePropertyKind::kClassField:
case ParsePropertyKind::kShorthandOrClassField:
case ParsePropertyKind::kNotSet: {
...
ExpressionT initializer = ParseMemberInitializer(
class_info, property_beg_pos, prop_info->is_static); //[7]
...
//[8]
Line by line:
- The function
ParseClassPropertyDefinitionis responsible for reading one member definition inside a class body. - The
if (name_token == Token::kStatic)branch is taken when the member is markedstatic. - If the next token is a left parenthesis, it is a static method; if it is an equals sign, a semicolon or a right brace, it is a static field without a function name. Otherwise, the code sets
prop_info->is_static = trueand callsParseProperty(prop_info); //[6]to read the member's name. - The
switchbelow handles the kinds of member that can have an initialiser. For those, it callsParseMemberInitializer(...); //[7]to read the initialiser. - The comment
//[8]marks the point where the mismatch is already in place.
At [6], ParseProperty consumes a literal id through ParseFunctionLiteral. The backtrace for that increment is:
#0 0x00004f0e3d4d174b in v8::internal::ParserBase<v8::internal::Parser>::GetNextFunctionLiteralId (this=0x7fff7da5ec50) at ../../src/parsing/parser-base.h:296
#1 0x00004f0e3d4c39b0 in v8::internal::Parser::ParseFunctionLiteral (this=0x7fff7da5ec50, function_name=0x559dcbee9108, function_name_location=..., function_name_validity=v8::internal::kFunctionNameValidityUnknown, kind=v8::internal::FunctionKind::kNormalFunction,
function_token_pos=0x18, function_syntax_kind=v8::internal::FunctionSyntaxKind::kAnonymousExpression, language_mode=v8::internal::LanguageMode::kStrict, arguments_for_wrapped_function=0x0) at ../../src/parsing/parser.cc:2733
#2 0x00004f0e3d4f6a83 in v8::internal::ParserBase<v8::internal::Parser>::ParseFunctionExpression (this=0x7fff7da5ec50) at ../../src/parsing/parser-base.h:3960
#3 0x00004f0e3d4f54cd in v8::internal::ParserBase<v8::internal::Parser>::ParsePrimaryExpression (this=0x7fff7da5ec50) at ../../src/parsing/parser-base.h:2121
#4 0x00004f0e3d4f45a7 in v8::internal::ParserBase<v8::internal::Parser>::ParseMemberExpression (this=0x7fff7da5ec50) at ../../src/parsing/parser-base.h:3987
#5 0x00004f0e3d4f4447 in v8::internal::ParserBase<v8::internal::Parser>::ParseLeftHandSideExpression (this=0x7fff7da5ec50) at ../../src/parsing/parser-base.h:3709
#6 0x00004f0e3d4f32ba in v8::internal::ParserBase<v8::internal::Parser>::ParsePostfixExpression (this=0x7fff7da5ec50) at ../../src/parsing/parser-base.h:3676
#7 0x00004f0e3d4f2bde in v8::internal::ParserBase<v8::internal::Parser>::ParseUnaryExpression (this=0x7fff7da5ec50) at ../../src/parsing/parser-base.h:3666
#8 0x00004f0e3d4f24ac in v8::internal::ParserBase<v8::internal::Parser>::ParseBinaryExpression (this=0x7fff7da5ec50, prec=0x6) at ../../src/parsing/parser-base.h:3548
#9 0x00004f0e3d4f1dac in v8::internal::ParserBase<v8::internal::Parser>::ParseLogicalExpression (this=0x7fff7da5ec50) at ../../src/parsing/parser-base.h:3318
#10 0x00004f0e3d4f07fa in v8::internal::ParserBase<v8::internal::Parser>::ParseConditionalExpression (this=0x7fff7da5ec50) at ../../src/parsing/parser-base.h:3303
#11 0x00004f0e3d4f0316 in v8::internal::ParserBase<v8::internal::Parser>::ParseAssignmentExpressionCoverGrammar (this=0x7fff7da5ec50) at ../../src/parsing/parser-base.h:3090
#12 0x00004f0e3d4d77e5 in v8::internal::ParserBase<v8::internal::Parser>::ParseAssignmentExpression (this=0x7fff7da5ec50) at ../../src/parsing/parser-base.h:2229
#13 0x00004f0e3d5002e4 in v8::internal::ParserBase<v8::internal::Parser>::ParseProperty (this=0x7fff7da5ec50, prop_info=0x7fff7da5e700) at ../../src/parsing/parser-base.h:2486
This is another stack trace, read from the bottom up. The bottom line is ParseProperty, the function called at [6]. Above it are the parsing functions that led into it, ending at the top with GetNextFunctionLiteralId, the function that actually hands out the next number. So the chain shows exactly how reading a property name ended up consuming a literal id.
At [7], ParseMemberInitializer consumes another literal id through EnsureStaticElementsScope. The backtrace for that increment is:
#0 0x00004f0e3d4d174b in v8::internal::ParserBase<v8::internal::Parser>::GetNextFunctionLiteralId (this=0x7fff7da5ec50) at ../../src/parsing/parser-base.h:296
#1 0x00004f0e3d5036f8 in v8::internal::ParserBase<v8::internal::Parser>::ClassInfo::EnsureStaticElementsScope (this=0x7fff7da5e7e0, parser=0x7fff7da5ec50, beg_pos=0x10) at ../../src/parsing/parser-base.h:623
#2 0x00004f0e3d504576 in v8::internal::ParserBase<v8::internal::Parser>::ParseMemberInitializer (this=0x7fff7da5ec50, class_info=0x7fff7da5e7e0, beg_pos=0x10, is_static=0x1) at ../../src/parsing/parser-base.h:2696
This shorter trace shows the second increment. The bottom line is ParseMemberInitializer, called at [7]. Above it is EnsureStaticElementsScope, and at the top is again GetNextFunctionLiteralId, taking another number. Two separate calls have now each taken a number, when the code expected only one.
By [8] the mismatch is already established, and the function returns up the stack until the check at [4] fires.
The report attributes the regression to commit [redacted], titled "[parser] Only reparse the relevant segments for class initializers", reviewed at https://chromium-review.googlesource.com/c/v8/v8/+/5676330. A commit is a recorded change to the source code, and a regression is a bug introduced by a change that previously worked. The first major Chrome release containing it, per the bisect, was Chrome Stable 128.0.6613.84. A bisect is a technique for finding the exact change that introduced a bug by testing versions in between, halving the range each time, much like finding a faulty bulb in a long string by testing the middle first.
Impact
The observable effect in the report is a fatal debug assertion during parsing of a class static function, which aborts the engine. The report does not describe a release-mode consequence, and the failing check is a debug-only assertion, so the practical impact on shipped Chrome builds is not established by the text. The severity assigned by the program was high.
Fix
The report does not state which change fixed the issue. It identifies the mismatch between static_elements_function_id and initializer_id after ParseClassLiteralBody as the root cause.
Variants to test
- The reduced case on other V8 versions around 12.8.374.24 in debug builds. A positive result is the same
Debug check failed: class_info.static_elements_function_id == initializer_idfatal error. - Other member-name expressions that parse a function literal, combined with a static member initialiser. A positive result is the same assertion or a related literal-id mismatch in the initialiser path.
- Classes with several static members, mixing function-expression names and initialisers, to see whether the gap between
static_elements_function_idandinitializer_idgrows with each member. A positive result is a larger difference in the assertion message than the 3 vs. 2 seen here. - The same shapes under the class members initialiser kind rather than the static elements kind, to check whether the other branch of
ParseClassForMemberInitializationis affected. A positive result is a failure at the later check oninitializer->function_literal_id().
Glossary
- V8: the JavaScript engine inside Chrome that reads and executes JavaScript code.
- JavaScript: the programming language used to make web pages interactive.
- Parser: the part of an engine that reads source code and breaks it into structured pieces before it runs.
- Function literal: a function written out directly in the code, rather than referred to by name from elsewhere.
- Identifier (literal id): a number the parser assigns to each function so later stages can tell functions apart.
- Scope: the region of a program in which a particular variable or function is visible.
- Compiled body: the version of a function translated into instructions the computer can execute.
- Class: a template in JavaScript for creating objects, which can have members belonging to the class itself or to individual objects.
- Static member: a member that belongs to the class itself rather than to objects created from it.
- Initialiser: the code that sets up a value when something is created.
- Assertion: a check a program makes about its own internal state, stopping if the state is wrong.
- DCHECK: a debug-only assertion in V8, removed from release builds.
- Debug build: a version of a program compiled with extra internal checks and diagnostic output, used for testing.
- Release build: the version of a program shipped to users, without debug-only checks.
- Compiled out: removed entirely by the compiler, so the code is not present in the final program.
- Stack trace: a printed list of the function calls that led to a particular point, usually a crash.
- Shared library (
.so): a file of compiled code that programs load and use at runtime. args.gn: a configuration file that tells the build system which options to use.d8: the standalone command line shell for running V8 JavaScript outside a browser.- Reduced test case: a triggering piece of code trimmed to the smallest version that still reproduces the problem.
- Function expression: a function written inline as part of an expression.
- Token: a small unit of source text, such as a word or a punctuation mark.
- Parameter: a value handed to a function when it is called.
- CVE: Common Vulnerabilities and Exposures, a public catalogue number for a known security flaw.
- Chrome VRP: Chrome Vulnerability Reward Program, a scheme that pays people for reporting security bugs.
- Bounty: the payment made for a valid security report.
- Severity: a rating of how serious a flaw is.
- Commit: a recorded change to a project's source code.
- Regression: a bug introduced by a change to code that previously worked.
- Bisect: a technique for finding the change that introduced a bug by testing versions in between and halving the range each time.
- Stable channel: the normal, widely used release of Chrome.
- Inappropriate implementation: a flaw category meaning the code does not implement its intended behaviour correctly.