Changeset 262100 in webkit


Ignore:
Timestamp:
May 23, 2020, 9:35:29 AM (5 years ago)
Author:
Caio Lima
Message:

[bmalloc] Fix OOM errors on MIPS after r261667
https://bugs.webkit.org/show_bug.cgi?id=212016

Reviewed by Yusuke Suzuki.

JSTests:

  • stress/array-buffer-view-watchpoint-can-be-fired-in-really-add-in-dfg.js:
  • stress/big-int-mod-memory-stress.js:
  • stress/incremental-marking-should-not-dead-lock-in-new-property-transition.js:

Source/bmalloc:

The way we were calculating newBegin and newEnd on
ObjectTypeTable::set when index is out of bounds didn't consider
cases where bits->begin() - bits->count() or index - ObjectTypeTable::Bits::bitCountPerWord * 4
can underflow and bits->end() + bits->count() can overflow.
Given that, the value used is going to be index or index + 1.
Since we extend the size of bitvector everytime we have an OOB, this can cause a pathological case
that memory will keep extending quite often until systems reachs OOM.
It is reproducible on ARMv7 and MIPS architectures on
stress/array-buffer-view-watchpoint-can-be-fired-in-really-add-in-dfg.js,
stress/big-int-mod-memory-stress.js and some other tests.
This patch is including a verification if those operations are going
to overflow/underflow, and properly set newBegin to 0 and newEnd
to UINT_MAX when we observe such behavior.

  • bmalloc/ObjectTypeTable.cpp:

(bmalloc::ObjectTypeTable::set):

LayoutTests:

  • js/script-tests/stack-overflow-regexp.js:
Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified trunk/JSTests/ChangeLog

    r262088 r262100  
     12020-05-23  Caio Lima  <ticaiolima@gmail.com>
     2
     3        [bmalloc] Fix OOM errors on MIPS after r261667
     4        https://bugs.webkit.org/show_bug.cgi?id=212016
     5
     6        Reviewed by Yusuke Suzuki.
     7
     8        * stress/array-buffer-view-watchpoint-can-be-fired-in-really-add-in-dfg.js:
     9        * stress/big-int-mod-memory-stress.js:
     10        * stress/incremental-marking-should-not-dead-lock-in-new-property-transition.js:
     11
    1122020-05-22  Alexey Shvayka  <shvaikalesh@gmail.com>
    213
  • TabularUnified trunk/JSTests/stress/array-buffer-view-watchpoint-can-be-fired-in-really-add-in-dfg.js

    r261862 r262100  
    1 //@ skip if ["arm", "mips", "powerpc", "powerpc64", "s390"].include?($architecture) and $hostOS == "linux"
     1//@ skip if ["arm", "powerpc", "powerpc64", "s390"].include?($architecture) and $hostOS == "linux"
     2//@ requireOptions("-e", "let iterations=40000") if ["mips"].include?($architecture)
    23//@ runDefault("--jitPolicyScale=0")
    34
  • TabularUnified trunk/JSTests/stress/big-int-mod-memory-stress.js

    r261743 r262100  
    1 //@ skip if ["arm", "mips"].include?($architecture)
    21//@ runBigIntEnabled
    32
  • TabularUnified trunk/JSTests/stress/incremental-marking-should-not-dead-lock-in-new-property-transition.js

    r261743 r262100  
    1 //@ skip if ["arm", "mips"].include?($architecture)
    21//@ skip if $hostOS == "playstation"
    32//@ runDefault("--gcIncrementScale=100", "--gcIncrementBytes=10", "--numberOfGCMarkers=1")
  • TabularUnified trunk/LayoutTests/ChangeLog

    r262097 r262100  
     12020-05-23  Caio Lima  <ticaiolima@gmail.com>
     2
     3        [bmalloc] Fix OOM errors on MIPS after r261667
     4        https://bugs.webkit.org/show_bug.cgi?id=212016
     5
     6        Reviewed by Yusuke Suzuki.
     7
     8        * js/script-tests/stack-overflow-regexp.js:
     9
    1102020-05-23  Zalan Bujtas  <zalan@apple.com>
    211
  • TabularUnified trunk/LayoutTests/js/script-tests/stack-overflow-regexp.js

    r261808 r262100  
    11// https://bugs.webkit.org/show_bug.cgi?id=190755
    2 //@ skip if ["arm", "mips"].include?($architecture) and $hostOS == "linux"
     2//@ skip if $architecture == "arm" and $hostOS == "linux"
    33//  &&&&
    44description('Test that we do not overflow the stack while handling regular expressions');
  • TabularUnified trunk/Source/bmalloc/ChangeLog

    r261827 r262100  
     12020-05-23  Caio Lima  <ticaiolima@gmail.com>
     2
     3        [bmalloc] Fix OOM errors on MIPS after r261667
     4        https://bugs.webkit.org/show_bug.cgi?id=212016
     5
     6        Reviewed by Yusuke Suzuki.
     7
     8        The way we were calculating `newBegin` and `newEnd` on
     9        `ObjectTypeTable::set` when index is out of bounds didn't consider
     10        cases where `bits->begin() - bits->count()` or `index - ObjectTypeTable::Bits::bitCountPerWord * 4`
     11        can underflow and `bits->end() + bits->count()` can overflow.
     12        Given that, the value used is going to be `index` or `index + 1`.
     13        Since we extend the size of bitvector everytime we have an OOB, this can cause a pathological case
     14        that memory will keep extending quite often until systems reachs OOM.
     15        It is reproducible on ARMv7 and MIPS architectures on
     16        `stress/array-buffer-view-watchpoint-can-be-fired-in-really-add-in-dfg.js`,
     17        `stress/big-int-mod-memory-stress.js` and some other tests.
     18        This patch is including a verification if those operations are going
     19        to overflow/underflow, and properly set `newBegin` to 0 and `newEnd`
     20        to UINT_MAX when we observe such behavior.
     21
     22        * bmalloc/ObjectTypeTable.cpp:
     23        (bmalloc::ObjectTypeTable::set):
     24
    1252020-05-18  Mark Lam  <mark.lam@apple.com>
    226
  • TabularUnified trunk/Source/bmalloc/bmalloc/ObjectTypeTable.cpp

    r261667 r262100  
    4242            // This is initial allocation of ObjectTypeTable. In this case, it could be possible that for the first registration,
    4343            // some VAs are already allocated for a different purpose, and later they will be reused for bmalloc. In that case,
    44             // soon, we will see a smaller index request than this initial one. We subtract a 128MB offset to the initial newBegin
    45             // to cover such patterns without extending table too quickly.
    46             newBegin = std::min<unsigned>(index, index - ObjectTypeTable::Bits::bitCountPerWord * 4);
     44            // soon, we will see a smaller index request than this initial one. We try to subtract a 128MB offset to the initial
     45            // newBegin to cover such patterns without extending table too quickly, and if we can't subtract 128MB, we will set
     46            // newBegin to 0. 
     47            constexpr unsigned offsetForInitialAllocation = ObjectTypeTable::Bits::bitCountPerWord * 4;
     48            if (index < offsetForInitialAllocation)
     49                newBegin = 0;
     50            else
     51                newBegin = index - offsetForInitialAllocation;
    4752            newEnd = index + 1;
    4853        } else if (index < bits->begin()) {
    4954            BASSERT(bits->begin());
    5055            BASSERT(bits->end());
    51             newBegin = std::min<unsigned>(index, bits->begin() - bits->count());
     56            // We need to verify if "bits->begin() - bits->count()" doesn't underflow,
     57            // otherwise we will set "newBegin" as "index" and it creates a pathological
     58            // case that will keep increasing BitVector everytime we access
     59            // "index < bits->begin()".
     60            if (bits->begin() < bits->count())
     61                newBegin = 0;
     62            else
     63                newBegin = std::min<unsigned>(index, bits->begin() - bits->count());
    5264            newEnd = bits->end();
    5365        } else {
     
    5567            BASSERT(bits->end());
    5668            newBegin = bits->begin();
    57             newEnd = std::max<unsigned>(index + 1, bits->end() + bits->count());
     69            // We need to verify if "bits->end() + bits->count()" doesn't overflow,
     70            // otherwise we will set "newEnd" as "index + 1" and it creates a
     71            // pathological case that will keep increasing BitVector everytime we access
     72            // "index > bits->end()".
     73            if (std::numeric_limits<unsigned>::max() - bits->count() < bits->end())
     74                newEnd = std::numeric_limits<unsigned>::max();
     75            else
     76                newEnd = std::max<unsigned>(index + 1, bits->end() + bits->count());
    5877        }
    5978        newBegin = static_cast<unsigned>(roundDownToMultipleOf<size_t>(ObjectTypeTable::Bits::bitCountPerWord, newBegin));
Note: See TracChangeset for help on using the changeset viewer.