Bug 159231 (CVE-2016-4733) - Memory Corruption in TypedArray.copyWithin
Summary: Memory Corruption in TypedArray.copyWithin
Status: RESOLVED FIXED
Alias: CVE-2016-4733
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Major
Assignee: Nobody
URL:
Keywords: HasReduction, InRadar
: 159239 (view as bug list)
Depends on:
Blocks:
 
Reported: 2016-06-28 15:05 PDT by Natalie Silvanovich
Modified: 2017-10-11 10:25 PDT (History)
6 users (show)

See Also:


Attachments
Sample file causing issue (479 bytes, text/html)
2016-06-28 15:05 PDT, Natalie Silvanovich
no flags Details
Patch (36.80 KB, patch)
2016-07-06 12:02 PDT, Keith Miller
fpizlo: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Natalie Silvanovich 2016-06-28 15:05:00 PDT
Created attachment 282289 [details]
Sample file causing issue

There is a bug in TypedArray.copyWithin that can be used to write to an absolute pointer. 

In JavaScriptCore/runtime/JSGenericTypedArrayViewPrototypeFunctions.h, the function genericTypedArrayViewProtoFuncCopyWithin contains the following code:

    long length = thisObject->length();
    long to = argumentClampedIndexFromStartOrEnd(exec, 0, length);
    long from = argumentClampedIndexFromStartOrEnd(exec, 1, length);
    long final = argumentClampedIndexFromStartOrEnd(exec, 2, length, length);

    if (final < from)
        return JSValue::encode(exec->thisValue());

    long count = std::min(length - std::max(to, from), final - from);

    typename ViewClass::ElementType* array = thisObject->typedVector();
    memmove(array + to, array + from, count * thisObject->elementSize);

argumentClampedIndexFromStartOrEnd will call valueOf on a parameter to the copyWithin function, which can contain a function that neuters the this array, causing the variable "array" to be null. However, the "to" and "from" variables can be very large values, up to 0x7fffffff, which could be valid pointers on ARM and 32-bit platforms. This allows an absolute pointer in this range to be written to.

An HTML file demonstrating this issue is attached. This issue affects Safari Technology Preview and WebKit, but has not made it into production Safari yet (TypedArray.copyWithin is not supported).

This bug is subject to a 90 day disclosure deadline. If 90 days elapse
without a broadly available patch, then the bug report will automatically
become visible to the public.

--

[Our ref: https://bugs.chromium.org/p/project-zero/issues/detail?id=862]

Credit is to Natalie Silvanovich of Google Project Zero
Comment 1 Radar WebKit Bug Importer 2016-06-28 17:15:39 PDT
<rdar://problem/27069149>
Comment 2 Keith Miller 2016-07-06 12:02:56 PDT
Created attachment 282920 [details]
Patch
Comment 3 Keith Miller 2016-07-08 09:28:16 PDT
Committed r202982: <http://trac.webkit.org/changeset/202982>
Comment 4 Mark Lam 2016-07-13 11:40:15 PDT
*** Bug 159239 has been marked as a duplicate of this bug. ***