Changeset 265097 in webkit


Ignore:
Timestamp:
Jul 30, 2020 2:44:45 PM (4 years ago)
Author:
sbarati@apple.com
Message:

Strip pointers instead of authing for byteOffset to not allow for a possible way to guess data pac
https://bugs.webkit.org/show_bug.cgi?id=214952

Reviewed by Keith Miller.

In the old way of doing things, we would auth the vector pointer before subtracting
the base from it. Since we never validated the auth, this allowed for a
potential data-PAC bypass by just repeatedly calling byteOffset in a loop
and observing the integer result of the operation.

Since byteOffset does no loads/stores, it suffices to just strip the PAC
bits before doing the subtraction. This eliminates any such attacks like
the above because the PAC bits are ignored.

  • dfg/DFGSpeculativeJIT.cpp:

(JSC::DFG::SpeculativeJIT::compileGetTypedArrayByteOffset):

  • ftl/FTLLowerDFGToB3.cpp:

(JSC::FTL::DFG::LowerDFGToB3::compileGetTypedArrayByteOffset):

Location:
trunk/Source/JavaScriptCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r265074 r265097  
     12020-07-30  Saam Barati  <sbarati@apple.com>
     2
     3        Strip pointers instead of authing for byteOffset to not allow for a possible way to guess data pac
     4        https://bugs.webkit.org/show_bug.cgi?id=214952
     5
     6        Reviewed by Keith Miller.
     7
     8        In the old way of doing things, we would auth the vector pointer before subtracting
     9        the base from it. Since we never validated the auth, this allowed for a
     10        potential data-PAC bypass by just repeatedly calling byteOffset in a loop
     11        and observing the integer result of the operation.
     12       
     13        Since byteOffset does no loads/stores, it suffices to just strip the PAC
     14        bits before doing the subtraction. This eliminates any such attacks like
     15        the above because the PAC bits are ignored.
     16
     17        * dfg/DFGSpeculativeJIT.cpp:
     18        (JSC::DFG::SpeculativeJIT::compileGetTypedArrayByteOffset):
     19        * ftl/FTLLowerDFGToB3.cpp:
     20        (JSC::FTL::DFG::LowerDFGToB3::compileGetTypedArrayByteOffset):
     21
    1222020-07-29  Yusuke Suzuki  <ysuzuki@apple.com>
    223
  • trunk/Source/JavaScriptCore/dfg/DFGSpeculativeJIT.cpp

    r264575 r265097  
    73277327
    73287328    m_jit.loadPtr(MacroAssembler::Address(baseGPR, JSArrayBufferView::offsetOfVector()), vectorGPR);
    7329 
    7330     JITCompiler::Jump nullVector = m_jit.branchPtr(JITCompiler::Equal, vectorGPR, TrustedImmPtr(JSArrayBufferView::nullVectorPtr()));
     7329#if CPU(ARM64E)
     7330    m_jit.removeArrayPtrTag(vectorGPR);
     7331#endif
    73317332
    73327333    m_jit.loadPtr(MacroAssembler::Address(baseGPR, JSObject::butterflyOffset()), dataGPR);
    73337334    m_jit.cageWithoutUntagging(Gigacage::JSValue, dataGPR);
    7334 
    7335     cageTypedArrayStorage(baseGPR, vectorGPR);
    7336 
    73377335    m_jit.loadPtr(MacroAssembler::Address(dataGPR, Butterfly::offsetOfArrayBuffer()), arrayBufferGPR);
    7338     // FIXME: This needs caging.
    7339     // https://bugs.webkit.org/show_bug.cgi?id=175515
    73407336    m_jit.loadPtr(MacroAssembler::Address(arrayBufferGPR, ArrayBuffer::offsetOfData()), dataGPR);
    73417337#if CPU(ARM64E)
     
    73477343    JITCompiler::Jump done = m_jit.jump();
    73487344   
    7349 #if CPU(ARM64E)
    7350     nullVector.link(&m_jit);
    7351 #endif
    73527345    emptyByteOffset.link(&m_jit);
    73537346    m_jit.move(TrustedImmPtr(nullptr), vectorGPR);
    73547347   
    73557348    done.link(&m_jit);
    7356 #if !CPU(ARM64E)
    7357     ASSERT(!JSArrayBufferView::nullVectorPtr());
    7358     nullVector.link(&m_jit);
    7359 #endif
    73607349
    73617350    strictInt32Result(vectorGPR, node);
  • trunk/Source/JavaScriptCore/ftl/FTLLowerDFGToB3.cpp

    r265000 r265097  
    43624362
    43634363        LBasicBlock wastefulCase = m_out.newBlock();
    4364         LBasicBlock notNull = m_out.newBlock();
    43654364        LBasicBlock continuation = m_out.newBlock();
    43664365       
    4367         ValueFromBlock nullVectorOut = m_out.anchor(m_out.constIntPtr(0));
     4366        ValueFromBlock nonWastefulResult = m_out.anchor(m_out.constIntPtr(0));
    43684367
    43694368        LValue mode = m_out.load32(basePtr, m_heaps.JSArrayBufferView_mode);
     
    43724371            unsure(continuation), unsure(wastefulCase));
    43734372
    4374         LBasicBlock lastNext = m_out.appendTo(wastefulCase, notNull);
    4375 
    4376         LValue vector = m_out.loadPtr(basePtr, m_heaps.JSArrayBufferView_vector);
    4377         m_out.branch(m_out.equal(vector, m_out.constIntPtr(JSArrayBufferView::nullVectorPtr())),
    4378             unsure(continuation), unsure(notNull));
    4379 
    4380         m_out.appendTo(notNull, continuation);
     4373        LBasicBlock lastNext = m_out.appendTo(wastefulCase, continuation);
     4374
     4375        LValue vectorPtr = m_out.loadPtr(basePtr, m_heaps.JSArrayBufferView_vector);
     4376        vectorPtr = removeArrayPtrTag(vectorPtr);
    43814377
    43824378        LValue butterflyPtr = caged(Gigacage::JSValue, m_out.loadPtr(basePtr, m_heaps.JSObject_butterfly), basePtr);
    43834379        LValue arrayBufferPtr = m_out.loadPtr(butterflyPtr, m_heaps.Butterfly_arrayBuffer);
    43844380
    4385         LValue vectorPtr = caged(Gigacage::Primitive, vector, basePtr);
    4386 
    4387         // FIXME: This needs caging.
    4388         // https://bugs.webkit.org/show_bug.cgi?id=175515
    43894381        LValue dataPtr = m_out.loadPtr(arrayBufferPtr, m_heaps.ArrayBuffer_data);
    43904382        dataPtr = removeArrayPtrTag(dataPtr);
     
    43954387        m_out.appendTo(continuation, lastNext);
    43964388
    4397         setInt32(m_out.castToInt32(m_out.phi(pointerType(), nullVectorOut, wastefulOut)));
     4389        setInt32(m_out.castToInt32(m_out.phi(pointerType(), nonWastefulResult, wastefulOut)));
    43984390    }
    43994391
Note: See TracChangeset for help on using the changeset viewer.