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

Type Confusion in V8 (CVE-2024-9602)

The WASM streaming decoder did not enforce the maximum module size, allowing a module larger than 1 GiB. This led to offset truncation in constant expressions, enabling type confusion where an uninitialised global's placeholder value (undefined) was treated as a reference type, resulting in an arbitrary caged read/write primitive.

Seunghyun Lee Follow

Originally disclosed on Chrome VRP

Bounty$55,000 High View original
  • Fix shipped in 19 days

VULNERABILITY DETAILS

Summary

Type confusion due to WASM streaming decoder size overflow with overly large modules. AsyncStreamingDecoder does not properly check maximum module size, resulting in offset truncation into 30 bits for ConstantExpression::kWireBytesRef constant expressions. This eventually results in a primitive to confuse undefined as any WASM (reference) type, resulting in type confusion (and an instant arbitrary caged RW).

Details

WASM modules must hold an invariant that its size is less than kV8MaxWasmModuleSize = 1024 * 1024 * 1024 (1 GiB):

C++
// https://source.chromium.org/chromium/chromium/src/+/main:v8/src/wasm/wasm-limits.h;drc=f84fb630ee9aa58f7493db195d3ab6e0b254425e;l=49
constexpr size_t kV8MaxWasmModuleSize = 1024 * 1024 * 1024;  // = 1 GiB

However, AsyncStreamingDecoder only checks this limit on each section sizes and not the whole module:

C++
// https://source.chromium.org/chromium/chromium/src/+/main:v8/src/wasm/streaming-decoder.cc;l=465
class AsyncStreamingDecoder::DecodeSectionLength : public DecodeVarInt32 {
 public:
  explicit DecodeSectionLength(uint8_t id, uint32_t module_offset)
      : DecodeVarInt32(max_module_size(), "section length"),    // [!] checks each section size, not the whole module
        section_id_(id),
        module_offset_(module_offset) {}

  std::unique_ptr<DecodingState> NextWithValue(
      AsyncStreamingDecoder* streaming) override;

 private:
  const uint8_t section_id_;
  // The start offset of this section in the module.
  const uint32_t module_offset_;
};

This allows a module to grow over 1 GiB, which results in offset truncation in ConstantExpression::kWireBytesRef constant expressions:

C++
// https://source.chromium.org/chromium/chromium/src/+/main:v8/src/wasm/constant-expression.h;drc=247e36d85da39a66a1f68b46ef4aebf7dfdfdb03;l=31
// A representation of a constant expression. The most common expression types
// are hard-coded, while the rest are represented as a {WireBytesRef}.
class ConstantExpression {
 public:
  // ...
  static constexpr ConstantExpression WireBytes(uint32_t offset,
                                                uint32_t length) {
    return ConstantExpression(OffsetField::encode(offset) |
                              LengthField::encode(length) |
                              KindField::encode(kWireBytesRef));
  }
  // ...
  V8_EXPORT_PRIVATE WireBytesRef wire_bytes_ref() const;

 private:
  static constexpr int kValueBits = 32;
  static constexpr int kLengthBits = 30;   // [!] length limited to 30 bits (under 1 GiB)
  static constexpr int kOffsetBits = 30;
  static constexpr int kKindBits = 3;

  // There are two possible combinations of fields: offset + length + kind if
  // kind = kWireBytesRef, or value + kind for anything else.
  using ValueField = base::BitField<uint32_t, 0, kValueBits, uint64_t>;
  using OffsetField = base::BitField<uint32_t, 0, kOffsetBits, uint64_t>;
  using LengthField = OffsetField::Next<uint32_t, kLengthBits>;
  using KindField = LengthField::Next<Kind, kKindBits>;

  // ...
  uint64_t bit_field_ = 0;
};

// https://source.chromium.org/chromium/chromium/src/+/main:v8/src/wasm/constant-expression.cc;drc=8cab41c0837d9b869abdb0e5ca6a929b302f0d6a;l=23
WireBytesRef ConstantExpression::wire_bytes_ref() const {
  DCHECK_EQ(kind(), kWireBytesRef);
  return WireBytesRef(OffsetField::decode(bit_field_),
                      LengthField::decode(bit_field_));
}

With a constant expression located in an offset over 1 GiB, ConstantExpression::wire_bytes_ref() uses a truncated offset to fetch the WireBytesRef. This function is notably used in EvaluateConstantExpression():

C++
// https://source.chromium.org/chromium/chromium/src/+/main:v8/src/wasm/constant-expression.cc;drc=8cab41c0837d9b869abdb0e5ca6a929b302f0d6a;l=29
ValueOrError EvaluateConstantExpression(
    Zone* zone, ConstantExpression expr, ValueType expected, Isolate* isolate,
    Handle<WasmTrustedInstanceData> trusted_instance_data,
    Handle<WasmTrustedInstanceData> shared_trusted_instance_data) {
  switch (expr.kind()) {
    // ...
    case ConstantExpression::kWireBytesRef: {
      WireBytesRef ref = expr.wire_bytes_ref();

      base::Vector<const uint8_t> module_bytes =
          trusted_instance_data->native_module()->wire_bytes();

      const uint8_t* start = module_bytes.begin() + ref.offset();
      const uint8_t* end = module_bytes.begin() + ref.end_offset();

      auto sig = FixedSizeSignature<ValueType>::Returns(expected);
      // We have already validated the expression, so we might as well
      // revalidate it as non-shared, which is strictly more permissive.
      // TODO(14616): Rethink this.
      constexpr bool kIsShared = false;
      FunctionBody body(&sig, ref.offset(), start, end, kIsShared);
      WasmDetectedFeatures detected;
      const WasmModule* module = trusted_instance_data->module();
      ValueOrError result;
      {
        // We need a scope for the decoder because its destructor resets some
        // Zone elements, which has to be done before we reset the Zone
        // afterwards.
        // We use FullValidationTag so we do not have to create another template
        // instance of WasmFullDecoder, which would cost us >50Kb binary code
        // size.
        WasmFullDecoder<Decoder::FullValidationTag, ConstantExpressionInterface,
                        kConstantExpression>
            decoder(zone, module, WasmEnabledFeatures::All(), &detected, body,
                    module, isolate, trusted_instance_data,
                    shared_trusted_instance_data);

        decoder.DecodeFunctionBody();

        result = decoder.interface().has_error()
                     ? ValueOrError(decoder.interface().error())
                     : ValueOrError(decoder.interface().computed_value());
      }

      zone->Reset();

      return result;
    }
  }
}

This function is called on every cases that require constant expression evaluation (global init, data/table segment offset, element segment entry, etc). Unfortunately, WasmFullDecoder<Decoder::FullValidationTag, ...> is used which typechecks the expression result type with the expected type - only valid typechecked expression are allowed. (Note: failure cases still successfully result in a kWasmVoid typed WasmValue, but this is difficult to exploit.)

This can still be exploited by tricking InstanceBuilder::InitGlobals() into using a yet uninitialized reference typed global value, which initially has the placeholder value undefined.

DecodeGlobalSection() originally enforces initialization order of the globals by the decoding phase inside consume_init_expr():

C++
  void DecodeGlobalSection() {
    uint32_t globals_count = consume_count("globals count", kV8MaxWasmGlobals);
    uint32_t imported_globals = static_cast<uint32_t>(module_->globals.size());
    // It is important to not resize the globals vector from the beginning,      // [!] this enforces initialization order
    // because we use its current size when decoding the initializer.
    module_->globals.reserve(imported_globals + globals_count);
    for (uint32_t i = 0; ok() && i < globals_count; ++i) {
      // ...
      ConstantExpression init = consume_init_expr(module_.get(), type, shared);
      module_->globals.push_back(
          WasmGlobal{.type = type,
                     .mutability = mutability,
                     .init = init,
                     .index = 0,  // set later in CalculateGlobalOffsets
                     .shared = shared});
      if (shared) module_->has_shared_part = true;
    }
  }

At InstanceBuilder::InitGlobals(), we have all the module_->globals entries ready but are initializing them in order starting from index 0. This allows us to use a global value that is yet uninitialized, which returns undefined but is typed to be the global's type. In the attached PoC, we set up the module so that global[0] is initialized with global.get 0, which uses its own placeholder value of undefined.

This finally results in a type confusion, where using the global value results in undefined being confused as the global's type. This interestingly also immediately leads to arbitrary caged read/write primitive, as undefined has the following memory layout:

Text
pwndbg> x/4wx 0x121300000068
0x121300000068: 0x000004f5      0x00000000      0x7ff80000      0x00005bb1

The entry at index 2, 0x7ff80000, corresponds to the length field for WasmArray types. Thus we can confuse undefined to a i32 array and obtain caged read/write primitive.

Note: This bug also implies that wasm_max_module_size should never be allowed to be set higher than the current kV8MaxWasmModuleSize limit. However, there are no such invariants enforced.

Note 2: This bug may also be exploitable by overflowing the module size outside of int/uint32_t range, but this has not been investigated further as overflowing 1 GiB is already enough.

Bisect

  • Module size check bug introduced by commit 549692c in M63 that introduced WASM streaming compilation.
  • 30-bit offset optimization introduced by commit e557383 in M99 that optimizes constant expression decoding.

VERSION

See bisect commit release info in Chromium Dash for more info: 549692c, e557383

Current exploit uses WasmGC, but this may also be exploitable even before the introduction of WasmGC as the underlying bug is technically irrelevant with WasmGC.

This (at least) affects all Chrome builds with WasmGC available by default, which is M112 up to latest (M112 ~ M118 behind Origin Trials, later shipped in M119~). The root cause exists from M99~, any may even affect M63~ if int/uint32_t overflow is feasible.

Chrome Version: M112 (?) ~ latest (tested on latest canary, 131.0.6727.0)
Operating System: All

REPRODUCTION CASE

Attached poc.html which exploits the vulnerability to obtain arbitrary caged read/write, then writes into cage offset 0x4242424 a value of 0x13333337 to demonstrate a crash.

In my local environment the repro required ~5GB of resident memory, so I recommend running this on an environment with 8GB or more memory. Also, ClusterFuzz may have a hard time reproing due to 1 GiB module creation - locally it repros in 3 seconds, but I recommend giving CF up to 60 seconds.

FOR CRASHES, PLEASE INCLUDE THE FOLLOWING ADDITIONAL INFORMATION

Type of crash: Renderer
Crash State: Crashes within JIT code, while trying to array.set which results in writing 0x13333337 into cage offset 0x4242424.

CREDIT INFORMATION

Reporter credit: Seunghyun Lee (@0x10n) of CMU CyLab


Full exploit coming soon... (again??)

The original report as published on the Chromium issue tracker, by Seunghyun Lee (@0x10n). Images and videos are our own copies; raw HTML is shown as text. View it on Chromium issue tracker.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 11 min read.

Context

This report describes a type confusion bug in V8, the JavaScript and WebAssembly engine used by Google Chrome. The affected component is the WebAssembly (WASM) streaming decoder, specifically AsyncStreamingDecoder, together with the constant expression representation used during module decoding and instantiation. The bug was reported through the Chrome VRP by Seunghyun Lee (@0x10n) of CMU CyLab, rated high severity, and disclosed on 2024-10-08. The platform records a bounty of 55,000 USD. The report itself is an advisory-style write-up with code references, a bisect, and a reproduction case; it does not include HTTP requests or responses.

WASM modules are supposed to obey an invariant: the total module size must stay below kV8MaxWasmModuleSize, which is 1 GiB. The streaming decoder is the code path that compiles a module while its bytes are still arriving, for example when a module is fetched over the network and compiled incrementally. Constant expressions are the small expressions used in places such as global initialisers, data and table segment offsets, and element segment entries. They are decoded once and stored in a compact form, then evaluated later during instantiation.

The report's summary states the issue plainly: a type confusion caused by a WASM streaming decoder size overflow with overly large modules. AsyncStreamingDecoder does not properly check the maximum module size, which results in offset truncation into 30 bits for ConstantExpression::kWireBytesRef constant expressions. The end result is a primitive that confuses undefined as any WASM reference type, giving type confusion and, per the report, an immediate arbitrary caged read/write.

Setup

The report does not describe any accounts, roles, or remote tooling. The relevant preconditions are version and platform based:

  1. The target is Chrome's V8 engine, with the WASM streaming compilation path in use.
  2. The exploit as written uses WasmGC, so it needs a build where WasmGC is available by default. The report says this is M112 up to latest, with M112 to M118 behind Origin Trials and later shipped in M119 onwards.
  3. The root cause exists from M99 onwards, and may even affect M63 onwards if an int/uint32_t overflow of the module size is feasible.
  4. The reporter tested on the latest canary at the time, Chrome 131.0.6727.0, and states the operating system is "All".
  5. The reproduction needs a large amount of memory. In the reporter's local environment it required about 5 GB of resident memory, so they recommend an environment with 8 GB or more. They note ClusterFuzz may struggle to reproduce because of the 1 GiB module creation, that it reproduces locally in 3 seconds, and that ClusterFuzz should be given up to 60 seconds.

The report does not list any specific build flags, debug settings, or command lines beyond the above.

Finding it

The researcher started from the documented invariant that a WASM module must be smaller than 1 GiB:

C++
// https://source.chromium.org/chromium/chromium/src/+/main:v8/src/wasm/wasm-limits.h;drc=[redacted];l=49
constexpr size_t kV8MaxWasmModuleSize = 1024 * 1024 * 1024;  // = 1 GiB

They then observed that AsyncStreamingDecoder only enforces this limit on each section size, not on the whole module. The relevant state class is DecodeSectionLength, which passes max_module_size() as the limit to the varint decoder for the section length:

C++
// https://source.chromium.org/chromium/chromium/src/+/main:v8/src/wasm/streaming-decoder.cc;l=465
class AsyncStreamingDecoder::DecodeSectionLength : public DecodeVarInt32 {
 public:
  explicit DecodeSectionLength(uint8_t id, uint32_t module_offset)
      : DecodeVarInt32(max_module_size(), "section length"),    // [!] checks each section size, not the whole module
        section_id_(id),
        module_offset_(module_offset) {}

  std::unique_ptr<DecodingState> NextWithValue(
      AsyncStreamingDecoder* streaming) override;

 private:
  const uint8_t section_id_;
  // The start offset of this section in the module.
  const uint32_t module_offset_;
};

Because the check is per section, a module can grow beyond 1 GiB in total while each individual section stays within the limit. That matters because constant expressions store their location in the module as a WireBytesRef, and the compact representation of a constant expression only reserves 30 bits for the offset and 30 bits for the length:

C++
// https://source.chromium.org/chromium/chromium/src/+/main:v8/src/wasm/constant-expression.h;drc=[redacted];l=31
// A representation of a constant expression. The most common expression types
// are hard-coded, while the rest are represented as a {WireBytesRef}.
class ConstantExpression {
 public:
  // ...
  static constexpr ConstantExpression WireBytes(uint32_t offset,
                                                uint32_t length) {
    return ConstantExpression(OffsetField::encode(offset) |
                              LengthField::encode(length) |
                              KindField::encode(kWireBytesRef));
  }
  // ...
  V8_EXPORT_PRIVATE WireBytesRef wire_bytes_ref() const;

 private:
  static constexpr int kValueBits = 32;
  static constexpr int kLengthBits = 30;   // [!] length limited to 30 bits (under 1 GiB)
  static constexpr int kOffsetBits = 30;
  static constexpr int kKindBits = 3;

  // There are two possible combinations of fields: offset + length + kind if
  // kind = kWireBytesRef, or value + kind for anything else.
  using ValueField = base::BitField<uint32_t, 0, kValueBits, uint64_t>;
  using OffsetField = base::BitField<uint32_t, 0, kOffsetBits, uint64_t>;
  using LengthField = OffsetField::Next<uint32_t, kLengthBits>;
  using KindField = LengthField::Next<Kind, kKindBits>;

  // ...
  uint64_t bit_field_ = 0;
};

// https://source.chromium.org/chromium/chromium/src/+/main:v8/src/wasm/constant-expression.cc;drc=[redacted];l=23
WireBytesRef ConstantExpression::wire_bytes_ref() const {
  DCHECK_EQ(kind(), kWireBytesRef);
  return WireBytesRef(OffsetField::decode(bit_field_),
                      LengthField::decode(bit_field_));
}

The 30-bit offset field is the key. Once a module grows beyond 1 GiB, offsets are truncated into 30 bits, and wire_bytes_ref() later decodes that truncated value. The decoder then fetches the expression bytes from the wrong place in the module.

Exploitation

Step 1: build a module larger than 1 GiB

The first step is to get a module past the 1 GiB limit. Because AsyncStreamingDecoder checks only section lengths, a module whose total size exceeds 1 GiB but whose sections each fit within the limit is accepted by the streaming path. The report does not give the exact module layout used in the PoC.

Step 2: place a constant expression beyond the 1 GiB boundary

With the module grown over 1 GiB, ConstantExpression::wire_bytes_ref() returns a truncated offset. That function is used in EvaluateConstantExpression():

C++
// https://source.chromium.org/chromium/chromium/src/+/main:v8/src/wasm/constant-expression.cc;drc=[redacted];l=29
ValueOrError EvaluateConstantExpression(
    Zone* zone, ConstantExpression expr, ValueType expected, Isolate* isolate,
    Handle<WasmTrustedInstanceData> trusted_instance_data,
    Handle<WasmTrustedInstanceData> shared_trusted_instance_data) {
  switch (expr.kind()) {
    // ...
    case ConstantExpression::kWireBytesRef: {
      WireBytesRef ref = expr.wire_bytes_ref();

      base::Vector<const uint8_t> module_bytes =
          trusted_instance_data->native_module()->wire_bytes();

      const uint8_t* start = module_bytes.begin() + ref.offset();
      const uint8_t* end = module_bytes.begin() + ref.end_offset();

      auto sig = FixedSizeSignature<ValueType>::Returns(expected);
      // We have already validated the expression, so we might as well
      // revalidate it as non-shared, which is strictly more permissive.
      // TODO(14616): Rethink this.
      constexpr bool kIsShared = false;
      FunctionBody body(&sig, ref.offset(), start, end, kIsShared);
      WasmDetectedFeatures detected;
      const WasmModule* module = trusted_instance_data->module();
      ValueOrError result;
      {
        // We need a scope for the decoder because its destructor resets some
        // Zone elements, which has to be done before we reset the Zone
        // afterwards.
        // We use FullValidationTag so we do not have to create another template
        // instance of WasmFullDecoder, which would cost us >50Kb binary code
        // size.
        WasmFullDecoder<Decoder::FullValidationTag, ConstantExpressionInterface,
                        kConstantExpression>
            decoder(zone, module, WasmEnabledFeatures::All(), &detected, body,
                    module, isolate, trusted_instance_data,
                    shared_trusted_instance_data);

        decoder.DecodeFunctionBody();

        result = decoder.interface().has_error()
                     ? ValueOrError(decoder.interface().error())
                     : ValueOrError(decoder.interface().computed_value());
      }

      zone->Reset();

      return result;
    }
  }
}

This function is called in every case that requires constant expression evaluation: global initialisers, data and table segment offsets, element segment entries, and similar. The truncated offset means the decoder reads the expression from the wrong bytes.

Step 3: work around the full validation check

The report notes a complication. EvaluateConstantExpression() uses WasmFullDecoder<Decoder::FullValidationTag, ...>, which type-checks the expression result against the expected type. Only valid, type-checked expressions are allowed through. The report adds that failure cases still successfully result in a kWasmVoid typed WasmValue, but that this is difficult to exploit.

Step 4: use an uninitialised global to get undefined typed as a reference

The way around the validation is to abuse the order in which globals are initialised. DecodeGlobalSection() enforces initialisation order during decoding by not resizing the globals vector up front:

C++
  void DecodeGlobalSection() {
    uint32_t globals_count = consume_count("globals count", kV8MaxWasmGlobals);
    uint32_t imported_globals = static_cast<uint32_t>(module_->globals.size());
    // It is important to not resize the globals vector from the beginning,      // [!] this enforces initialization order
    // because we use its current size when decoding the initializer.
    module_->globals.reserve(imported_globals + globals_count);
    for (uint32_t i = 0; ok() && i < globals_count; ++i) {
      // ...
      ConstantExpression init = consume_init_expr(module_.get(), type, shared);
      module_->globals.push_back(
          WasmGlobal{.type = type,
                     .mutability = mutability,
                     .init = init,
                     .index = 0,  // set later in CalculateGlobalOffsets
                     .shared = shared});
      if (shared) module_->has_shared_part = true;
    }
  }

At instantiation, InstanceBuilder::InitGlobals() has all the module_->globals entries ready but initialises them in order starting from index 0. That means a global initialiser can refer to a global that has not been initialised yet. The uninitialised slot holds the placeholder value undefined, but it is typed as the global's declared type. In the PoC, the module is set up so that global[0] is initialised with global.get 0, which reads its own placeholder value of undefined.

Step 5: turn the confusion into a caged read/write primitive

The result is a type confusion in which undefined is treated as the global's type. The report says this immediately leads to an arbitrary caged read/write primitive, because of the memory layout of undefined:

Text
pwndbg> x/4wx 0x121300000068
0x121300000068: 0x000004f5      0x00000000      0x7ff80000      0x00005bb1

The entry at index 2, 0x7ff80000, corresponds to the length field for WasmArray types. By confusing undefined with an i32 array, the attacker obtains a caged read/write primitive.

Step 6: demonstrate the crash

The attached poc.html exploits the vulnerability to obtain arbitrary caged read/write, then writes the value 0x13333337 into cage offset 0x4242424 to demonstrate a crash. The crash type is a renderer crash, and the crash state is described as crashing within JIT code while trying to array.set, which results in writing 0x13333337 into cage offset 0x4242424.

Root cause

There are two interacting mistakes:

  1. AsyncStreamingDecoder enforces kV8MaxWasmModuleSize per section rather than for the whole module. A module can therefore exceed 1 GiB in total while every section passes the check.
  2. ConstantExpression stores the offset and length of a kWireBytesRef in 30 bits each. The 30-bit length is consistent with a module under 1 GiB, but the 30-bit offset is only safe if the module really cannot exceed 1 GiB. Once the module is larger, offsets above 1 GiB are truncated, and wire_bytes_ref() returns a wrong location.

The existing defence that should have caught this is the full validation performed by WasmFullDecoder<Decoder::FullValidationTag, ...> inside EvaluateConstantExpression(). It type-checks the expression result against the expected type, so a straightforward mismatch is rejected. The report works around it by using an uninitialised global: the value is undefined, but the type is the declared global type, so validation sees a consistent type. The report also notes that failure cases produce a kWasmVoid typed WasmValue, which is difficult to exploit.

The report adds two notes. First, the bug implies that wasm_max_module_size should never be allowed to be set higher than the current kV8MaxWasmModuleSize limit, but no such invariant is enforced. Second, the bug may also be exploitable by overflowing the module size outside the int/uint32_t range, but this was not investigated further because overflowing 1 GiB is already enough.

Impact

Under the conditions described, an attacker who can get a crafted WASM module compiled through the streaming path can obtain an arbitrary caged read/write primitive in the renderer. The report demonstrates this by writing a chosen value to a chosen cage offset, which crashes the renderer inside JIT code. The report describes the primitive as immediate once the type confusion is reached, and states that the exploit uses WasmGC, although the underlying bug is described as technically irrelevant to WasmGC. The report hedges the older-version impact: the root cause exists from M99, and may affect M63 onwards only if an int/uint32_t overflow of the module size is feasible. The report does not claim a sandbox escape or any impact outside the renderer.

Fix

It does state that wasm_max_module_size should never be allowed to be set higher than the current kV8MaxWasmModuleSize limit, an invariant the report says is not enforced.

Variants to test

  1. Other streaming decoders with per-section limits. Look for decoders that validate each chunk or section against a maximum but never track the cumulative size. A positive result is a module that is accepted while its total size exceeds the documented maximum.
  2. Other compact bit-field representations of offsets. Search for structures that pack an offset into fewer bits than the address space or maximum object size requires. A positive result is a truncated offset that is later used to index a buffer.
  3. Other lazy initialisation orders. Look for initialisers that can read a slot before it is written, especially where the slot has a default value of a different type. A positive result is a value of one type being observed where another type is expected.
  4. Other places where a default value such as undefined has a memory layout that overlaps a length or size field. A positive result is a length field derived from a constant such as 0x7ff80000.
  5. The int/uint32_t overflow path mentioned in Note 2. Try module sizes that overflow the 32-bit range rather than just exceeding 1 GiB. A positive result is a size check that passes because of wraparound.
  6. Configuration overrides of maximum sizes. Check whether any build or runtime setting can raise a maximum module size above the limit assumed by the compact representation. A positive result is a configuration in which the two limits disagree.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 25 min read.

What happened, in plain words

Google Chrome contains a piece of software called V8. V8 is the engine that reads JavaScript and WebAssembly code and turns it into instructions the computer can run. Think of it as the translator sitting between a web page and your processor: the page hands it code, and V8 decides whether the code is allowed and how to execute it quickly.

WebAssembly, usually shortened to WASM, is a second language that browsers understand. It is not written by hand very often; instead, other languages such as C or Rust are compiled into WASM so that heavy programs (games, video editors, scientific tools) can run inside a web page at near-native speed. A WASM program is delivered as a file called a module. A module is a long sequence of bytes, and inside it there are sections: one section lists the functions, another lists the memory, another lists the globals, and so on.

This report describes a bug in the part of V8 that reads a WASM module while it is still arriving over the network. That part is called the streaming decoder, and the specific class involved is AsyncStreamingDecoder. "Streaming" means the engine does not wait for the whole file to download before starting work; it processes the bytes as they come in, like reading a book page by page as the pages are printed rather than waiting for the finished book.

The bug is a type confusion. A type confusion happens when a program stores a value of one kind but later treats it as a value of a different kind. A simple everyday comparison: you have a box labelled "shoes" and a box labelled "books". If a mix-up makes the program open the "books" box expecting shoes, it will read the wrong contents and behave unpredictably. In memory, a value's type tells the engine how many bytes it occupies and how to interpret them. Confuse the type and the engine reads the wrong number of bytes, or reads a number where it expected a pointer.

The report was submitted through the Chrome VRP. VRP stands for Vulnerability Reward Program: a scheme where Google pays people who privately report security bugs instead of exploiting them. The researcher is Seunghyun Lee (@0x10n) of CMU CyLab. The platform records the severity as high, a bounty of 55,000 USD, and a disclosure date of 2024-10-08. The report is written in the style of an advisory: it contains code references, a bisect (a search through the project's history to find which change introduced the bug), and a reproduction case. It does not contain HTTP requests or responses, so there are none to show here.

The report's own summary says it directly: a type confusion caused by a WASM streaming decoder size overflow with overly large modules. AsyncStreamingDecoder does not properly check the maximum module size, which results in offset truncation into 30 bits for ConstantExpression::kWireBytesRef constant expressions. The end result is a primitive that confuses undefined as any WASM reference type, giving type confusion and, per the report, an immediate arbitrary caged read/write.

Several of those words need unpacking before the rest makes sense.

  • An offset is a position inside a block of bytes, counted from the start. If a file is a street, an offset is a house number.
  • Truncation means throwing away the high-order part of a number because there is no room to store it. If you can only write four digits and the true value is 12345, you write 2345. The number is now wrong, and any position calculated from it points somewhere else.
  • A constant expression is a small expression that produces a fixed value, used in places such as the starting value of a global variable, or the starting position of a data segment. The engine decodes these once, stores them compactly, and evaluates them later when the module is set up.
  • undefined is JavaScript's value for "nothing here yet". It is not the same as zero or null; it is a distinct value with its own internal representation.
  • A caged read/write primitive means the attacker can read and write memory inside a reserved region (the "cage") at addresses of their choosing. It is a powerful building block for further exploitation.

Setup

The report does not describe any accounts, roles, or remote tooling. There is nothing to log into and no server to configure. The relevant preconditions are about versions and hardware:

  1. The target is Chrome's V8 engine, with the WASM streaming compilation path in use. In other words, the module must be compiled while it streams in, not after a complete download.
  2. The exploit as written uses WasmGC. WasmGC is the WebAssembly garbage collection extension: it lets WASM programs create structured objects (arrays, structs) that the engine manages and cleans up automatically, much like JavaScript objects. The exploit needs a build where WasmGC is available by default. The report says this is M112 up to latest, with M112 to M118 behind Origin Trials and later shipped in M119 onwards. "M" followed by a number is Chrome's milestone numbering: M112 is the 112th major release. An Origin Trial is a way for sites to opt into an unfinished feature before it ships to everyone.
  3. The root cause exists from M99 onwards, and may even affect M63 onwards if an int/uint32_t overflow of the module size is feasible. An int or uint32_t is a fixed-width integer: 32 bits can hold values up to about 4.29 billion. If a size counter wraps past that, it starts again from zero, which is another way to defeat a size check.
  4. The reporter tested on the latest canary at the time, Chrome 131.0.6727.0, and states the operating system is "All". Canary is Chrome's experimental early-release channel, where changes appear before they reach stable users.
  5. The reproduction needs a large amount of memory. In the reporter's local environment it required about 5 GB of resident memory, so they recommend an environment with 8 GB or more. Resident memory is the portion of RAM a process is actually holding at that moment. They note ClusterFuzz may struggle to reproduce because of the 1 GiB module creation, that it reproduces locally in 3 seconds, and that ClusterFuzz should be given up to 60 seconds. ClusterFuzz is Google's automated system for running crash tests at scale; a 1 GiB input is unusual and may hit time or memory limits there.

The report does not list any specific build flags, debug settings, or command lines beyond the above.

Finding it

The researcher started from a documented rule, an invariant, that a WASM module must be smaller than 1 GiB. An invariant is a condition the code assumes is always true; if it is ever false, everything built on top of it can break. Here is the constant that defines the limit:

C++
// https://source.chromium.org/chromium/chromium/src/+/main:v8/src/wasm/wasm-limits.h;drc=[redacted];l=49
constexpr size_t kV8MaxWasmModuleSize = 1024 * 1024 * 1024;  // = 1 GiB

Line by line:

  • The first line is a comment giving the source location: the file wasm-limits.h in V8's source tree, at a specific revision and line 49. It is a pointer for anyone who wants to check the code themselves.
  • constexpr size_t kV8MaxWasmModuleSize = 1024 * 1024 * 1024; declares a compile-time constant named kV8MaxWasmModuleSize. size_t is an unsigned integer type used for sizes. The value is 1024 multiplied by itself three times, which is 1,073,741,824 bytes, or 1 GiB (one gibibyte). The comment restates this.

The researcher then observed that AsyncStreamingDecoder only enforces this limit on each section size, not on the whole module. The relevant state class is DecodeSectionLength, which passes max_module_size() as the limit to the varint decoder for the section length:

C++
// https://source.chromium.org/chromium/chromium/src/+/main:v8/src/wasm/streaming-decoder.cc;l=465
class AsyncStreamingDecoder::DecodeSectionLength : public DecodeVarInt32 {
 public:
  explicit DecodeSectionLength(uint8_t id, uint32_t module_offset)
      : DecodeVarInt32(max_module_size(), "section length"),    // [!] checks each section size, not the whole module
        section_id_(id),
        module_offset_(module_offset) {}

  std::unique_ptr<DecodingState> NextWithValue(
      AsyncStreamingDecoder* streaming) override;

 private:
  const uint8_t section_id_;
  // The start offset of this section in the module.
  const uint32_t module_offset_;
};

Line by line:

  • The comment again points to the source file and line.
  • class AsyncStreamingDecoder::DecodeSectionLength : public DecodeVarInt32 { defines a class, a blueprint for an object. This one represents the decoder's state while it is reading a section's length. The : public DecodeVarInt32 part means it inherits from DecodeVarInt32, a helper that reads variable-length integers. A varint is an integer encoded in a variable number of bytes: small numbers take one byte, larger numbers take more. Section lengths are stored this way.
  • explicit DecodeSectionLength(uint8_t id, uint32_t module_offset) is the constructor, the code that runs when the object is created. It takes a section id (an 8-bit unsigned number, uint8_t) and the offset of the section within the module (a 32-bit unsigned number, uint32_t).
  • : DecodeVarInt32(max_module_size(), "section length"), initialises the parent class with a maximum value and a label. max_module_size() returns the limit to apply. The label "section length" is used in error messages. The comment marked [!] is the researcher's annotation: this checks each section size, not the whole module.
  • section_id_(id), and module_offset_(module_offset) {} store the two arguments in member variables. The {} is an empty constructor body.
  • std::unique_ptr<DecodingState> NextWithValue(AsyncStreamingDecoder* streaming) override; declares a function that will be called once the length has been read. std::unique_ptr is a smart pointer that owns an object and frees it automatically. override says this function replaces one from the parent class.
  • const uint8_t section_id_; and const uint32_t module_offset_; are the stored fields. The comment explains that module_offset_ is the start offset of this section in the module.

Because the check is per section, a module can grow beyond 1 GiB in total while each individual section stays within the limit. That matters because constant expressions store their location in the module as a WireBytesRef, and the compact representation of a constant expression only reserves 30 bits for the offset and 30 bits for the length:

C++
// https://source.chromium.org/chromium/chromium/src/+/main:v8/src/wasm/constant-expression.h;drc=[redacted];l=31
// A representation of a constant expression. The most common expression types
// are hard-coded, while the rest are represented as a {WireBytesRef}.
class ConstantExpression {
 public:
  // ...
  static constexpr ConstantExpression WireBytes(uint32_t offset,
                                                uint32_t length) {
    return ConstantExpression(OffsetField::encode(offset) |
                              LengthField::encode(length) |
                              KindField::encode(kWireBytesRef));
  }
  // ...
  V8_EXPORT_PRIVATE WireBytesRef wire_bytes_ref() const;

 private:
  static constexpr int kValueBits = 32;
  static constexpr int kLengthBits = 30;   // [!] length limited to 30 bits (under 1 GiB)
  static constexpr int kOffsetBits = 30;
  static constexpr int kKindBits = 3;

  // There are two possible combinations of fields: offset + length + kind if
  // kind = kWireBytesRef, or value + kind for anything else.
  using ValueField = base::BitField<uint32_t, 0, kValueBits, uint64_t>;
  using OffsetField = base::BitField<uint32_t, 0, kOffsetBits, uint64_t>;
  using LengthField = OffsetField::Next<uint32_t, kLengthBits>;
  using KindField = LengthField::Next<Kind, kKindBits>;

  // ...
  uint64_t bit_field_ = 0;
};

// https://source.chromium.org/chromium/chromium/src/+/main:v8/src/wasm/constant-expression.cc;drc=[redacted];l=23
WireBytesRef ConstantExpression::wire_bytes_ref() const {
  DCHECK_EQ(kind(), kWireBytesRef);
  return WireBytesRef(OffsetField::decode(bit_field_),
                      LengthField::decode(bit_field_));
}

Line by line:

  • The first comment explains the purpose of the class: it represents a constant expression. Common expression types are hard-coded as their own kinds, while the rest are stored as a WireBytesRef, which is simply a pair of numbers (offset and length) pointing into the module's raw bytes.
  • class ConstantExpression { starts the class definition.
  • static constexpr ConstantExpression WireBytes(uint32_t offset, uint32_t length) { is a factory function. It takes an offset and a length, both 32-bit unsigned integers, and builds a ConstantExpression.
  • return ConstantExpression(OffsetField::encode(offset) | LengthField::encode(length) | KindField::encode(kWireBytesRef)); packs three values into one number using bitwise OR (|). Each field is shifted into its own bit positions and combined. This is like writing three short numbers into three separate columns of a single form.
  • V8_EXPORT_PRIVATE WireBytesRef wire_bytes_ref() const; declares a function that unpacks the stored fields back into a WireBytesRef.
  • static constexpr int kValueBits = 32; says a plain value uses 32 bits.
  • static constexpr int kLengthBits = 30; says the length field gets 30 bits. The comment marked [!] notes that 30 bits is enough for a length under 1 GiB, because 2 to the power 30 is 1,073,741,824, exactly 1 GiB.
  • static constexpr int kOffsetBits = 30; says the offset field also gets 30 bits. This is the crucial line: an offset of 1 GiB or more cannot fit in 30 bits.
  • static constexpr int kKindBits = 3; says the kind field gets 3 bits, enough to label up to eight kinds.
  • The comment explains the two layouts: offset plus length plus kind when the kind is kWireBytesRef, or value plus kind for anything else.
  • using ValueField = base::BitField<uint32_t, 0, kValueBits, uint64_t>; defines a helper type for reading and writing a 32-bit value starting at bit 0, stored inside a 64-bit integer. base::BitField is a Chromium utility for exactly this kind of packing.
  • using OffsetField = base::BitField<uint32_t, 0, kOffsetBits, uint64_t>; defines the offset field: 30 bits starting at bit 0.
  • using LengthField = OffsetField::Next<uint32_t, kLengthBits>; defines the length field as the next 30 bits after the offset.
  • using KindField = LengthField::Next<Kind, kKindBits>; defines the kind field as the next 3 bits after the length.
  • uint64_t bit_field_ = 0; is the single 64-bit number that holds everything, initialised to zero.
  • The second block, WireBytesRef ConstantExpression::wire_bytes_ref() const {, is the unpacking function. DCHECK_EQ(kind(), kWireBytesRef); is a debug-only assertion that the kind really is kWireBytesRef; in release builds it compiles away. return WireBytesRef(OffsetField::decode(bit_field_), LengthField::decode(bit_field_)); reads the 30-bit offset and 30-bit length back out and returns them as a WireBytesRef.

The 30-bit offset field is the key. Once a module grows beyond 1 GiB, offsets are truncated into 30 bits, and wire_bytes_ref() later decodes that truncated value. The decoder then fetches the expression bytes from the wrong place in the module. To return to the street comparison: the house number is written on a form with only four boxes, so house 1,234,567 becomes 234,567, and the delivery goes to the wrong door.

Exploitation

Step 1: build a module larger than 1 GiB

The first step is to get a module past the 1 GiB limit. Because AsyncStreamingDecoder checks only section lengths, a module whose total size exceeds 1 GiB but whose sections each fit within the limit is accepted by the streaming path. The report does not give the exact module layout used in the PoC, only that the module is built so that a constant expression ends up at an offset over 1 GiB. PoC stands for proof of concept: a small demonstration that the bug is real.

Step 2: place a constant expression beyond the 1 GiB boundary

With the module grown over 1 GiB, ConstantExpression::wire_bytes_ref() returns a truncated offset. That function is used in EvaluateConstantExpression():

C++
// https://source.chromium.org/chromium/chromium/src/+/main:v8/src/wasm/constant-expression.cc;drc=[redacted];l=29
ValueOrError EvaluateConstantExpression(
    Zone* zone, ConstantExpression expr, ValueType expected, Isolate* isolate,
    Handle<WasmTrustedInstanceData> trusted_instance_data,
    Handle<WasmTrustedInstanceData> shared_trusted_instance_data) {
  switch (expr.kind()) {
    // ...
    case ConstantExpression::kWireBytesRef: {
      WireBytesRef ref = expr.wire_bytes_ref();

      base::Vector<const uint8_t> module_bytes =
          trusted_instance_data->native_module()->wire_bytes();

      const uint8_t* start = module_bytes.begin() + ref.offset();
      const uint8_t* end = module_bytes.begin() + ref.end_offset();

      auto sig = FixedSizeSignature<ValueType>::Returns(expected);
      // We have already validated the expression, so we might as well
      // revalidate it as non-shared, which is strictly more permissive.
      // TODO(14616): Rethink this.
      constexpr bool kIsShared = false;
      FunctionBody body(&sig, ref.offset(), start, end, kIsShared);
      WasmDetectedFeatures detected;
      const WasmModule* module = trusted_instance_data->module();
      ValueOrError result;
      {
        // We need a scope for the decoder because its destructor resets some
        // Zone elements, which has to be done before we reset the Zone
        // afterwards.
        // We use FullValidationTag so we do not have to create another template
        // instance of WasmFullDecoder, which would cost us >50Kb binary code
        // size.
        WasmFullDecoder<Decoder::FullValidationTag, ConstantExpressionInterface,
                        kConstantExpression>
            decoder(zone, module, WasmEnabledFeatures::All(), &detected, body,
                    module, isolate, trusted_instance_data,
                    shared_trusted_instance_data);

        decoder.DecodeFunctionBody();

        result = decoder.interface().has_error()
                     ? ValueOrError(decoder.interface().error())
                     : ValueOrError(decoder.interface().computed_value());
      }

      zone->Reset();

      return result;
    }
  }
}

Line by line:

  • The comment points to the source file and line.
  • ValueOrError EvaluateConstantExpression( begins a function that returns either a value or an error. Its parameters are: Zone* zone, a scratch memory area used during compilation; ConstantExpression expr, the expression to evaluate; ValueType expected, the type the result must have; Isolate* isolate, the object representing one isolated JavaScript/WASM execution context; and two handles to trusted instance data, one for the normal instance and one for the shared part. A handle is a managed pointer that keeps an object alive while it is in use.
  • switch (expr.kind()) { branches on the kind of expression.
  • case ConstantExpression::kWireBytesRef: { handles the case where the expression is stored as a reference into the module's bytes.
  • WireBytesRef ref = expr.wire_bytes_ref(); unpacks the offset and length. If the offset was truncated earlier, ref now holds the wrong offset.
  • base::Vector<const uint8_t> module_bytes = trusted_instance_data->native_module()->wire_bytes(); fetches the module's raw bytes. A Vector here is a simple view over a contiguous block of memory.
  • const uint8_t* start = module_bytes.begin() + ref.offset(); computes a pointer to the start of the expression by adding the (possibly wrong) offset to the beginning of the module bytes.
  • const uint8_t* end = module_bytes.begin() + ref.end_offset(); computes the end pointer the same way.
  • auto sig = FixedSizeSignature<ValueType>::Returns(expected); builds a function signature that returns the expected type.
  • The comment explains that the expression was already validated, so it is revalidated as non-shared, which is more permissive. TODO(14616) is a note to revisit this decision.
  • constexpr bool kIsShared = false; sets the shared flag to false.
  • FunctionBody body(&sig, ref.offset(), start, end, kIsShared); wraps the byte range in a FunctionBody, the object the decoder reads from.
  • WasmDetectedFeatures detected; will record which WASM features the expression uses.
  • const WasmModule* module = trusted_instance_data->module(); gets the module description.
  • ValueOrError result; declares the result variable.
  • The inner { ... } block creates a scope so the decoder is destroyed before the zone is reset. The comment explains why: the decoder's destructor resets some zone elements, and that must happen first.
  • The comment also explains the choice of FullValidationTag: it avoids creating a second template instance of WasmFullDecoder, which would cost more than 50 KB of binary code size. A template is a C++ feature that generates code for each combination of types; each new combination adds to the program's size.
  • WasmFullDecoder<Decoder::FullValidationTag, ConstantExpressionInterface, kConstantExpression> decoder(...) creates the decoder with full validation enabled, passing the zone, module, all enabled features, the detected-features recorder, the body, and the instance data.
  • decoder.DecodeFunctionBody(); runs the decoder over the expression bytes.
  • result = decoder.interface().has_error() ? ValueOrError(decoder.interface().error()) : ValueOrError(decoder.interface().computed_value()); stores either the error or the computed value, depending on whether decoding failed.
  • zone->Reset(); clears the scratch memory.
  • return result; returns the outcome.

This function is called in every case that requires constant expression evaluation: global initialisers, data and table segment offsets, element segment entries, and similar. A global is a named variable stored in the module. A data segment is a block of initial bytes copied into memory when the module starts. A table is an array of function references. An element segment fills a table. The truncated offset means the decoder reads the expression from the wrong bytes.

Step 3: work around the full validation check

The report notes a complication. EvaluateConstantExpression() uses WasmFullDecoder<Decoder::FullValidationTag, ...>, which type-checks the expression result against the expected type. Only valid, type-checked expressions are allowed through. In everyday terms: even if the delivery goes to the wrong house, the recipient checks that the parcel matches the label before accepting it. The report adds that failure cases still successfully result in a kWasmVoid typed WasmValue, but that this is difficult to exploit. kWasmVoid means "no value"; a WasmValue is the internal representation of a WASM value.

Step 4: use an uninitialised global to get undefined typed as a reference

The way around the validation is to abuse the order in which globals are initialised. DecodeGlobalSection() enforces initialisation order during decoding by not resizing the globals vector up front:

C++
  void DecodeGlobalSection() {
    uint32_t globals_count = consume_count("globals count", kV8MaxWasmGlobals);
    uint32_t imported_globals = static_cast<uint32_t>(module_->globals.size());
    // It is important to not resize the globals vector from the beginning,      // [!] this enforces initialization order
    // because we use its current size when decoding the initializer.
    module_->globals.reserve(imported_globals + globals_count);
    for (uint32_t i = 0; ok() && i < globals_count; ++i) {
      // ...
      ConstantExpression init = consume_init_expr(module_.get(), type, shared);
      module_->globals.push_back(
          WasmGlobal{.type = type,
                     .mutability = mutability,
                     .init = init,
                     .index = 0,  // set later in CalculateGlobalOffsets
                     .shared = shared});
      if (shared) module_->has_shared_part = true;
    }
  }

Line by line:

  • void DecodeGlobalSection() { begins the function that reads the globals section of a module.
  • uint32_t globals_count = consume_count("globals count", kV8MaxWasmGlobals); reads how many globals the module defines, with an upper limit kV8MaxWasmGlobals and a label for error messages.
  • uint32_t imported_globals = static_cast<uint32_t>(module_->globals.size()); counts globals imported from elsewhere, which come first. static_cast is an explicit type conversion.
  • The comment marked [!] explains that the vector is deliberately not resized at the start, because its current size is used while decoding each initialiser. This is what enforces initialisation order: when decoding global number N, only globals 0 to N-1 exist in the list.
  • module_->globals.reserve(imported_globals + globals_count); reserves enough room for all globals without changing the size. Reserving capacity is like booking seats without filling them yet.
  • for (uint32_t i = 0; ok() && i < globals_count; ++i) { loops over each global, stopping early if an error occurred.
  • ConstantExpression init = consume_init_expr(module_.get(), type, shared); reads the initialiser expression for this global.
  • module_->globals.push_back(WasmGlobal{...}); appends the global to the list. The fields are its type, whether it can be modified (mutability), its initialiser, an index placeholder set to 0 with a comment that it is set later in CalculateGlobalOffsets, and whether it belongs to the shared part.
  • if (shared) module_->has_shared_part = true; records that the module has a shared section.

At instantiation, InstanceBuilder::InitGlobals() has all the module_->globals entries ready but initialises them in order starting from index 0. That means a global initialiser can refer to a global that has not been initialised yet. The uninitialised slot holds the placeholder value undefined, but it is typed as the global's declared type. In the PoC, the module is set up so that global[0] is initialised with global.get 0, which reads its own placeholder value of undefined. global.get is the WASM instruction that reads a global's value.

Step 5: turn the confusion into a caged read/write primitive

The result is a type confusion in which undefined is treated as the global's type. The report says this immediately leads to an arbitrary caged read/write primitive, because of the memory layout of undefined:

Text
pwndbg> x/4wx 0x121300000068
0x121300000068: 0x000004f5      0x00000000      0x7ff80000      0x00005bb1

Line by line:

  • pwndbg> x/4wx 0x121300000068 is a command typed into pwndbg, a debugging tool built on GDB. x means examine memory, /4wx means four words in hexadecimal, and 0x121300000068 is the address to look at.
  • The second line shows four 32-bit words at that address: 0x000004f5, 0x00000000, 0x7ff80000, and 0x00005bb1. These are the raw contents of the undefined value's memory.

The entry at index 2, 0x7ff80000, corresponds to the length field for WasmArray types. A WasmArray is a WASM garbage-collected array object. By confusing undefined with an i32 array, the attacker obtains a caged read/write primitive. i32 is a 32-bit integer type.

Step 6: demonstrate the crash

The attached poc.html exploits the vulnerability to obtain arbitrary caged read/write, then writes the value 0x13333337 into cage offset 0x4242424 to demonstrate a crash. The crash type is a renderer crash, and the crash state is described as crashing within JIT code while trying to array.set, which results in writing 0x13333337 into cage offset 0x4242424. A renderer is the Chrome process that draws a page and runs its code; it is sandboxed from the rest of the system. JIT stands for just-in-time compilation: turning code into machine instructions while the program runs, for speed. array.set is the WASM instruction that stores a value into an array element. The chosen numbers are arbitrary markers so the crash is easy to recognise.

Root cause

There are two interacting mistakes:

  1. AsyncStreamingDecoder enforces kV8MaxWasmModuleSize per section rather than for the whole module. A module can therefore exceed 1 GiB in total while every section passes the check.
  2. ConstantExpression stores the offset and length of a kWireBytesRef in 30 bits each. The 30-bit length is consistent with a module under 1 GiB, but the 30-bit offset is only safe if the module really cannot exceed 1 GiB. Once the module is larger, offsets above 1 GiB are truncated, and wire_bytes_ref() returns a wrong location.

The existing defence that should have caught this is the full validation performed by WasmFullDecoder<Decoder::FullValidationTag, ...> inside EvaluateConstantExpression(). It type-checks the expression result against the expected type, so a straightforward mismatch is rejected. The report works around it by using an uninitialised global: the value is undefined, but the type is the declared global type, so validation sees a consistent type. The report also notes that failure cases produce a kWasmVoid typed WasmValue, which is difficult to exploit.

The report adds two notes. First, the bug implies that wasm_max_module_size should never be allowed to be set higher than the current kV8MaxWasmModuleSize limit, but no such invariant is enforced. wasm_max_module_size is a configurable maximum; if it can be raised above the limit the compact representation assumes, the same truncation becomes possible. Second, the bug may also be exploitable by overflowing the module size outside the int/uint32_t range, but this was not investigated further because overflowing 1 GiB is already enough.

Impact

Under the conditions described, an attacker who can get a crafted WASM module compiled through the streaming path can obtain an arbitrary caged read/write primitive in the renderer. The report demonstrates this by writing a chosen value to a chosen cage offset, which crashes the renderer inside JIT code. The report describes the primitive as immediate once the type confusion is reached, and states that the exploit uses WasmGC, although the underlying bug is described as technically irrelevant to WasmGC. The report hedges the older-version impact: the root cause exists from M99, and may affect M63 onwards only if an int/uint32_t overflow of the module size is feasible. The report does not claim a sandbox escape or any impact outside the renderer. A sandbox escape would mean breaking out of the restricted renderer process to affect the rest of the machine; the report does not claim that.

Fix

It does state that wasm_max_module_size should never be allowed to be set higher than the current kV8MaxWasmModuleSize limit, an invariant the report says is not enforced.

Variants to test

  1. Other streaming decoders with per-section limits. Look for decoders that validate each chunk or section against a maximum but never track the cumulative size. A positive result is a module that is accepted while its total size exceeds the documented maximum.
  2. Other compact bit-field representations of offsets. Search for structures that pack an offset into fewer bits than the address space or maximum object size requires. A positive result is a truncated offset that is later used to index a buffer.
  3. Other lazy initialisation orders. Look for initialisers that can read a slot before it is written, especially where the slot has a default value of a different type. A positive result is a value of one type being observed where another type is expected.
  4. Other places where a default value such as undefined has a memory layout that overlaps a length or size field. A positive result is a length field derived from a constant such as 0x7ff80000.
  5. The int/uint32_t overflow path mentioned in Note 2. Try module sizes that overflow the 32-bit range rather than just exceeding 1 GiB. A positive result is a size check that passes because of wraparound.
  6. Configuration overrides of maximum sizes. Check whether any build or runtime setting can raise a maximum module size above the limit assumed by the compact representation. A positive result is a configuration in which the two limits disagree.

Glossary

  • API: Application Programming Interface, a defined set of functions one piece of software offers to another so they can talk to each other.
  • AsyncStreamingDecoder: the V8 class that decodes a WASM module while its bytes are still arriving.
  • Bisect: a search through a project's change history to find the exact commit that introduced a bug.
  • Bit: the smallest unit of data, a single 0 or 1. Thirty bits can represent values up to 2 to the power 30, which is 1 GiB.
  • Bit field: a way of packing several small numbers into one larger number by assigning each a range of bits.
  • Bounty: a payment made by a company to a researcher who reports a security bug.
  • Cage: a reserved region of memory inside which an engine keeps its objects, so that a bug cannot reach memory outside it.
  • Canary: Chrome's experimental early-release channel.
  • ClusterFuzz: Google's automated system for running crash tests at scale.
  • Constant expression: a small expression that produces a fixed value, used for things such as a global's starting value.
  • Crash: when a program stops working because of an error it cannot recover from.
  • Data segment: a block of initial bytes copied into a WASM module's memory at startup.
  • Element segment: a block of function references used to fill a WASM table at startup.
  • Global: a named variable stored in a WASM module.
  • Handle: a managed pointer that keeps an object alive while it is in use.
  • i32: a 32-bit integer type in WASM.
  • Instance: a running copy of a WASM module, with its own memory and globals.
  • Instantiation: the process of turning a decoded module into a running instance.
  • Invariant: a condition the code assumes is always true.
  • Isolate: the object representing one isolated JavaScript/WASM execution context in V8.
  • JIT: just-in-time compilation, turning code into machine instructions while the program runs.
  • kWasmVoid: the WASM type meaning "no value".
  • kWireBytesRef: the constant expression kind that stores an offset and length pointing into the module's raw bytes.
  • Module: a WASM program as delivered, a long sequence of bytes divided into sections.
  • Offset: a position inside a block of bytes, counted from the start.
  • Origin Trial: a way for websites to opt into an unfinished browser feature before it ships to everyone.
  • PoC: proof of concept, a small demonstration that a bug is real.
  • Primitive: a basic capability an attacker builds on, such as reading or writing memory.
  • pwndbg: a debugging tool built on GDB, used to inspect memory.
  • Renderer: the Chrome process that draws a page and runs its code, sandboxed from the rest of the system.
  • Resident memory: the portion of RAM a process is actually holding at a given moment.
  • Sandbox escape: breaking out of a restricted process to affect the rest of the machine.
  • Section: one part of a WASM module, such as the list of functions or the list of globals.
  • Streaming: processing data as it arrives rather than waiting for all of it.
  • Truncation: throwing away the high-order part of a number because there is no room to store it.
  • Type confusion: a bug where a value of one type is treated as a value of another type.
  • undefined: JavaScript's value for "nothing here yet", distinct from zero and null.
  • Varint: an integer encoded in a variable number of bytes, small numbers in fewer bytes.
  • V8: the JavaScript and WebAssembly engine used by Chrome.
  • VRP: Vulnerability Reward Program, a scheme that pays researchers for privately reported security bugs.
  • WASM: WebAssembly, a binary language browsers can run at near-native speed.
  • WasmArray: a garbage-collected array object in the WasmGC extension.
  • WasmGC: the WebAssembly garbage collection extension, which lets WASM programs create managed objects.
  • WasmValue: V8's internal representation of a WASM value.
  • WireBytesRef: a pair of numbers, offset and length, pointing into a module's raw bytes.
  • Zone: a scratch memory area used during compilation and reset afterwards.

More by Seunghyun Lee

View all

14 more disclosed reports, best first.

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.