Title: [265097] trunk/Source/_javascript_Core
Revision
265097
Author
[email protected]
Date
2020-07-30 14:44:45 -0700 (Thu, 30 Jul 2020)

Log 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):

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (265096 => 265097)


--- trunk/Source/_javascript_Core/ChangeLog	2020-07-30 21:44:33 UTC (rev 265096)
+++ trunk/Source/_javascript_Core/ChangeLog	2020-07-30 21:44:45 UTC (rev 265097)
@@ -1,3 +1,24 @@
+2020-07-30  Saam Barati  <[email protected]>
+
+        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):
+
 2020-07-29  Yusuke Suzuki  <[email protected]>
 
         [JSC] Add B3::BottomTupleValue node

Modified: trunk/Source/_javascript_Core/dfg/DFGSpeculativeJIT.cpp (265096 => 265097)


--- trunk/Source/_javascript_Core/dfg/DFGSpeculativeJIT.cpp	2020-07-30 21:44:33 UTC (rev 265096)
+++ trunk/Source/_javascript_Core/dfg/DFGSpeculativeJIT.cpp	2020-07-30 21:44:45 UTC (rev 265097)
@@ -7326,17 +7326,13 @@
         TrustedImm32(WastefulTypedArray));
 
     m_jit.loadPtr(MacroAssembler::Address(baseGPR, JSArrayBufferView::offsetOfVector()), vectorGPR);
+#if CPU(ARM64E)
+    m_jit.removeArrayPtrTag(vectorGPR);
+#endif
 
-    JITCompiler::Jump nullVector = m_jit.branchPtr(JITCompiler::Equal, vectorGPR, TrustedImmPtr(JSArrayBufferView::nullVectorPtr()));
-
     m_jit.loadPtr(MacroAssembler::Address(baseGPR, JSObject::butterflyOffset()), dataGPR);
     m_jit.cageWithoutUntagging(Gigacage::JSValue, dataGPR);
-
-    cageTypedArrayStorage(baseGPR, vectorGPR);
-
     m_jit.loadPtr(MacroAssembler::Address(dataGPR, Butterfly::offsetOfArrayBuffer()), arrayBufferGPR);
-    // FIXME: This needs caging.
-    // https://bugs.webkit.org/show_bug.cgi?id=175515
     m_jit.loadPtr(MacroAssembler::Address(arrayBufferGPR, ArrayBuffer::offsetOfData()), dataGPR);
 #if CPU(ARM64E)
     m_jit.removeArrayPtrTag(dataGPR);
@@ -7346,17 +7342,10 @@
     
     JITCompiler::Jump done = m_jit.jump();
     
-#if CPU(ARM64E)
-    nullVector.link(&m_jit);
-#endif
     emptyByteOffset.link(&m_jit);
     m_jit.move(TrustedImmPtr(nullptr), vectorGPR);
     
     done.link(&m_jit);
-#if !CPU(ARM64E)
-    ASSERT(!JSArrayBufferView::nullVectorPtr());
-    nullVector.link(&m_jit);
-#endif
 
     strictInt32Result(vectorGPR, node);
 }

Modified: trunk/Source/_javascript_Core/ftl/FTLLowerDFGToB3.cpp (265096 => 265097)


--- trunk/Source/_javascript_Core/ftl/FTLLowerDFGToB3.cpp	2020-07-30 21:44:33 UTC (rev 265096)
+++ trunk/Source/_javascript_Core/ftl/FTLLowerDFGToB3.cpp	2020-07-30 21:44:45 UTC (rev 265097)
@@ -4361,10 +4361,9 @@
         LValue basePtr = lowCell(m_node->child1());    
 
         LBasicBlock wastefulCase = m_out.newBlock();
-        LBasicBlock notNull = m_out.newBlock();
         LBasicBlock continuation = m_out.newBlock();
         
-        ValueFromBlock nullVectorOut = m_out.anchor(m_out.constIntPtr(0));
+        ValueFromBlock nonWastefulResult = m_out.anchor(m_out.constIntPtr(0));
 
         LValue mode = m_out.load32(basePtr, m_heaps.JSArrayBufferView_mode);
         m_out.branch(
@@ -4371,21 +4370,14 @@
             m_out.notEqual(mode, m_out.constInt32(WastefulTypedArray)),
             unsure(continuation), unsure(wastefulCase));
 
-        LBasicBlock lastNext = m_out.appendTo(wastefulCase, notNull);
+        LBasicBlock lastNext = m_out.appendTo(wastefulCase, continuation);
 
-        LValue vector = m_out.loadPtr(basePtr, m_heaps.JSArrayBufferView_vector);
-        m_out.branch(m_out.equal(vector, m_out.constIntPtr(JSArrayBufferView::nullVectorPtr())), 
-            unsure(continuation), unsure(notNull));
+        LValue vectorPtr = m_out.loadPtr(basePtr, m_heaps.JSArrayBufferView_vector);
+        vectorPtr = removeArrayPtrTag(vectorPtr);
 
-        m_out.appendTo(notNull, continuation);
-
         LValue butterflyPtr = caged(Gigacage::JSValue, m_out.loadPtr(basePtr, m_heaps.JSObject_butterfly), basePtr);
         LValue arrayBufferPtr = m_out.loadPtr(butterflyPtr, m_heaps.Butterfly_arrayBuffer);
 
-        LValue vectorPtr = caged(Gigacage::Primitive, vector, basePtr);
-
-        // FIXME: This needs caging.
-        // https://bugs.webkit.org/show_bug.cgi?id=175515
         LValue dataPtr = m_out.loadPtr(arrayBufferPtr, m_heaps.ArrayBuffer_data);
         dataPtr = removeArrayPtrTag(dataPtr);
 
@@ -4394,7 +4386,7 @@
         m_out.jump(continuation);
         m_out.appendTo(continuation, lastNext);
 
-        setInt32(m_out.castToInt32(m_out.phi(pointerType(), nullVectorOut, wastefulOut)));
+        setInt32(m_out.castToInt32(m_out.phi(pointerType(), nonWastefulResult, wastefulOut)));
     }
 
     void compileGetPrototypeOf()
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to