Changeset 240193 in webkit


Ignore:
Timestamp:
Jan 18, 2019 7:27:29 PM (5 years ago)
Author:
keith_miller@apple.com
Message:

gigacage slide should randomize both start and end
https://bugs.webkit.org/show_bug.cgi?id=193601

Reviewed by Yusuke Suzuki.

This patch makes it so that the gigacade slide has an arbitrary
distance from the end as well as the start. This is done by
picking a random size then based on that size picking an random
starting offset.

  • bmalloc/Gigacage.h:
  • bmalloc/Heap.cpp:

(bmalloc::Heap::Heap):

Location:
trunk/Source/bmalloc
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/bmalloc/ChangeLog

    r240176 r240193  
     12019-01-18  Keith Miller  <keith_miller@apple.com>
     2
     3        gigacage slide should randomize both start and end
     4        https://bugs.webkit.org/show_bug.cgi?id=193601
     5
     6        Reviewed by Yusuke Suzuki.
     7
     8        This patch makes it so that the gigacade slide has an arbitrary
     9        distance from the end as well as the start. This is done by
     10        picking a random size then based on that size picking an random
     11        starting offset.
     12
     13        * bmalloc/Gigacage.h:
     14        * bmalloc/Heap.cpp:
     15        (bmalloc::Heap::Heap):
     16
    1172019-01-18  Jer Noble  <jer.noble@apple.com>
    218
  • trunk/Source/bmalloc/bmalloc/Algorithm.h

    r237429 r240193  
    100100{
    101101    BASSERT(isPowerOfTwo(divisor));
    102     return reinterpret_cast<T>(mask(reinterpret_cast<uintptr_t>(x), ~(divisor - 1ul)));
     102    static_assert(sizeof(T) == sizeof(uintptr_t), "sizeof(T) must be equal to sizeof(uintptr_t).");
     103    return static_cast<T>(mask(static_cast<uintptr_t>(x), ~(divisor - 1ul)));
     104}
     105
     106template<typename T> inline T* roundDownToMultipleOf(size_t divisor, T* x)
     107{
     108    BASSERT(isPowerOfTwo(divisor));
     109    return reinterpret_cast<T*>(mask(reinterpret_cast<uintptr_t>(x), ~(divisor - 1ul)));
    103110}
    104111
  • trunk/Source/bmalloc/bmalloc/Gigacage.h

    r240175 r240193  
    7171constexpr size_t jsValueGigacageSize = 1 * bmalloc::Sizes::GB;
    7272constexpr size_t gigacageBasePtrsSize = 16 * bmalloc::Sizes::kB;
    73 constexpr size_t minimumCageSizeAfterSlide = bmalloc::Sizes::GB / 2;
     73constexpr size_t maximumCageSizeReductionForSlide = bmalloc::Sizes::GB / 2;
    7474#define GIGACAGE_ALLOCATION_CAN_FAIL 1
    7575#else
     
    7777constexpr size_t jsValueGigacageSize = 16 * bmalloc::Sizes::GB;
    7878constexpr size_t gigacageBasePtrsSize = 4 * bmalloc::Sizes::kB;
    79 constexpr size_t minimumCageSizeAfterSlide = 4 * bmalloc::Sizes::GB;
     79constexpr size_t maximumCageSizeReductionForSlide = 4 * bmalloc::Sizes::GB;
    8080#define GIGACAGE_ALLOCATION_CAN_FAIL 0
    8181#endif
     
    9191static_assert(bmalloc::isPowerOfTwo(primitiveGigacageSize), "");
    9292static_assert(bmalloc::isPowerOfTwo(jsValueGigacageSize), "");
    93 static_assert(primitiveGigacageSize > minimumCageSizeAfterSlide, "");
    94 static_assert(jsValueGigacageSize > minimumCageSizeAfterSlide, "");
     93static_assert(primitiveGigacageSize > maximumCageSizeReductionForSlide, "");
     94static_assert(jsValueGigacageSize > maximumCageSizeReductionForSlide, "");
    9595
    9696constexpr size_t gigacageSizeToMask(size_t size) { return size - 1; }
  • trunk/Source/bmalloc/bmalloc/Heap.cpp

    r240175 r240193  
    6363        if (usingGigacage()) {
    6464            RELEASE_BASSERT(gigacageBasePtr());
    65             uint64_t random;
    66             cryptoRandom(reinterpret_cast<unsigned char*>(&random), sizeof(random));
    67             ptrdiff_t offset = random % (gigacageSize() - Gigacage::minimumCageSizeAfterSlide);
    68             offset = reinterpret_cast<ptrdiff_t>(roundDownToMultipleOf(vmPageSize(), reinterpret_cast<void*>(offset)));
     65            uint64_t random[2];
     66            cryptoRandom(reinterpret_cast<unsigned char*>(random), sizeof(random));
     67            size_t size = roundDownToMultipleOf(vmPageSize(), gigacageSize() - (random[0] % Gigacage::maximumCageSizeReductionForSlide));
     68            ptrdiff_t offset = roundDownToMultipleOf(vmPageSize(), random[1] % (gigacageSize() - size));
    6969            void* base = reinterpret_cast<unsigned char*>(gigacageBasePtr()) + offset;
    70             m_largeFree.add(LargeRange(base, gigacageSize() - offset, 0, 0));
     70            m_largeFree.add(LargeRange(base, size, 0, 0));
    7171        }
    7272#endif
Note: See TracChangeset for help on using the changeset viewer.