Title: [247799] trunk/Source/_javascript_Core
Revision
247799
Author
[email protected]
Date
2019-07-24 16:51:13 -0700 (Wed, 24 Jul 2019)

Log Message

performJITMemcpy should be PACed with a non-zero diversifier when passed and called via a pointer.
https://bugs.webkit.org/show_bug.cgi?id=200100
<rdar://problem/53474939>

Reviewed by Yusuke Suzuki.

* assembler/ARM64Assembler.h:
(JSC::ARM64Assembler::CopyFunction::CopyFunction):
(JSC::ARM64Assembler::CopyFunction::operator()):
- I choose to use ptrauth_auth_function() here instead of retagCodePtr() because
  retagCodePtr() would auth, assert, and re-pac the pointer.  This is needed in
  general because retagCodePtr() doesn't know that you will consume the pointer
  immediately (and therefore crash imminently if a failed auth is encountered).
  Since we know here that we will call with the auth'ed pointer immediately, we
  can skip the assert.

  This also has the benefit of letting Clang do a peephole optimization to emit
  a blrab instruction with the intended diversifier, instead of emitting multiple
  instructions to auth the pointer into a C function, and then using a blraaz to
  do a C function call.

(JSC::ARM64Assembler::linkJumpOrCall):
(JSC::ARM64Assembler::linkCompareAndBranch):
(JSC::ARM64Assembler::linkConditionalBranch):
(JSC::ARM64Assembler::linkTestAndBranch):
* assembler/LinkBuffer.cpp:
(JSC::LinkBuffer::copyCompactAndLinkCode):
* runtime/JSCPtrTag.h:

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (247798 => 247799)


--- trunk/Source/_javascript_Core/ChangeLog	2019-07-24 23:07:48 UTC (rev 247798)
+++ trunk/Source/_javascript_Core/ChangeLog	2019-07-24 23:51:13 UTC (rev 247799)
@@ -1,3 +1,34 @@
+2019-07-24  Mark Lam  <[email protected]>
+
+        performJITMemcpy should be PACed with a non-zero diversifier when passed and called via a pointer.
+        https://bugs.webkit.org/show_bug.cgi?id=200100
+        <rdar://problem/53474939>
+
+        Reviewed by Yusuke Suzuki.
+
+        * assembler/ARM64Assembler.h:
+        (JSC::ARM64Assembler::CopyFunction::CopyFunction):
+        (JSC::ARM64Assembler::CopyFunction::operator()):
+        - I choose to use ptrauth_auth_function() here instead of retagCodePtr() because
+          retagCodePtr() would auth, assert, and re-pac the pointer.  This is needed in
+          general because retagCodePtr() doesn't know that you will consume the pointer
+          immediately (and therefore crash imminently if a failed auth is encountered).
+          Since we know here that we will call with the auth'ed pointer immediately, we
+          can skip the assert.
+
+          This also has the benefit of letting Clang do a peephole optimization to emit
+          a blrab instruction with the intended diversifier, instead of emitting multiple
+          instructions to auth the pointer into a C function, and then using a blraaz to
+          do a C function call.
+
+        (JSC::ARM64Assembler::linkJumpOrCall):
+        (JSC::ARM64Assembler::linkCompareAndBranch):
+        (JSC::ARM64Assembler::linkConditionalBranch):
+        (JSC::ARM64Assembler::linkTestAndBranch):
+        * assembler/LinkBuffer.cpp:
+        (JSC::LinkBuffer::copyCompactAndLinkCode):
+        * runtime/JSCPtrTag.h:
+
 2019-07-24  Devin Rousso  <[email protected]>
 
         Web Inspector: print the target of `console.screenshot` last so the target is the closest item to the image

Modified: trunk/Source/_javascript_Core/assembler/ARM64Assembler.h (247798 => 247799)


--- trunk/Source/_javascript_Core/assembler/ARM64Assembler.h	2019-07-24 23:07:48 UTC (rev 247798)
+++ trunk/Source/_javascript_Core/assembler/ARM64Assembler.h	2019-07-24 23:51:13 UTC (rev 247799)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2012-2018 Apple Inc. All rights reserved.
+ * Copyright (C) 2012-2019 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -2910,7 +2910,27 @@
         return m_jumpsToLink;
     }
 
+#if CPU(ARM64E)
+    class CopyFunction {
+        typedef void* (*Func)(void*, const void*, size_t);
+    public:
+        CopyFunction(Func func)
+            : m_func(func)
+        {
+            assertIsNullOrTaggedWith(func, CopyFunctionPtrTag);
+        }
+
+        void* operator()(void* dst, const void* src, size_t size)
+        {
+            return ptrauth_auth_function(m_func, ptrauth_key_process_dependent_code, CopyFunctionPtrTag)(dst, src, size);
+        }
+
+    private:
+        Func m_func;
+    };
+#else
     typedef void* (*CopyFunction)(void*, const void*, size_t);
+#endif
 
     static void ALWAYS_INLINE link(LinkRecord& record, uint8_t* from, const uint8_t* fromInstruction8, uint8_t* to, CopyFunction copy)
     {
@@ -2977,7 +2997,7 @@
     }
 
     template<bool isCall>
-    static void linkJumpOrCall(int* from, const int* fromInstruction, void* to, CopyFunction copy = performJITMemcpy)
+    static void linkJumpOrCall(int* from, const int* fromInstruction, void* to, CopyFunction copy = tagCFunctionPtr<CopyFunctionPtrTag>(performJITMemcpy))
     {
         bool link;
         int imm26;
@@ -2998,7 +3018,7 @@
     }
 
     template<bool isDirect>
-    static void linkCompareAndBranch(Condition condition, bool is64Bit, RegisterID rt, int* from, const int* fromInstruction, void* to, CopyFunction copy = performJITMemcpy)
+    static void linkCompareAndBranch(Condition condition, bool is64Bit, RegisterID rt, int* from, const int* fromInstruction, void* to, CopyFunction copy = tagCFunctionPtr<CopyFunctionPtrTag>(performJITMemcpy))
     {
         ASSERT(!(reinterpret_cast<intptr_t>(from) & 3));
         ASSERT(!(reinterpret_cast<intptr_t>(to) & 3));
@@ -3026,7 +3046,7 @@
     }
 
     template<bool isDirect>
-    static void linkConditionalBranch(Condition condition, int* from, const int* fromInstruction, void* to, CopyFunction copy = performJITMemcpy)
+    static void linkConditionalBranch(Condition condition, int* from, const int* fromInstruction, void* to, CopyFunction copy = tagCFunctionPtr<CopyFunctionPtrTag>(performJITMemcpy))
     {
         ASSERT(!(reinterpret_cast<intptr_t>(from) & 3));
         ASSERT(!(reinterpret_cast<intptr_t>(to) & 3));
@@ -3054,7 +3074,7 @@
     }
 
     template<bool isDirect>
-    static void linkTestAndBranch(Condition condition, unsigned bitNumber, RegisterID rt, int* from, const int* fromInstruction, void* to, CopyFunction copy = performJITMemcpy)
+    static void linkTestAndBranch(Condition condition, unsigned bitNumber, RegisterID rt, int* from, const int* fromInstruction, void* to, CopyFunction copy = tagCFunctionPtr<CopyFunctionPtrTag>(performJITMemcpy))
     {
         ASSERT(!(reinterpret_cast<intptr_t>(from) & 3));
         ASSERT(!(reinterpret_cast<intptr_t>(to) & 3));

Modified: trunk/Source/_javascript_Core/assembler/LinkBuffer.cpp (247798 => 247799)


--- trunk/Source/_javascript_Core/assembler/LinkBuffer.cpp	2019-07-24 23:07:48 UTC (rev 247798)
+++ trunk/Source/_javascript_Core/assembler/LinkBuffer.cpp	2019-07-24 23:51:13 UTC (rev 247799)
@@ -228,13 +228,12 @@
 
     recordLinkOffsets(m_assemblerStorage, readPtr, initialSize, readPtr - writePtr);
         
-    for (unsigned i = 0; i < jumpCount; ++i) {
 #if CPU(ARM64E) && ENABLE(FAST_JIT_PERMISSIONS)
-        auto memcpyFunction = memcpy;
+    auto memcpyFunction = tagCFunctionPtr<CopyFunctionPtrTag>(memcpy);
 #else
-        auto memcpyFunction = performJITMemcpy;
+    auto memcpyFunction = tagCFunctionPtr<CopyFunctionPtrTag>(performJITMemcpy);
 #endif
-
+    for (unsigned i = 0; i < jumpCount; ++i) {
         uint8_t* location = codeOutData + jumpsToLink[i].from();
         uint8_t* target = codeOutData + jumpsToLink[i].to() - executableOffsetFor(jumpsToLink[i].to());
         MacroAssembler::link(jumpsToLink[i], outData + jumpsToLink[i].from(), location, target, memcpyFunction);

Modified: trunk/Source/_javascript_Core/runtime/JSCPtrTag.h (247798 => 247799)


--- trunk/Source/_javascript_Core/runtime/JSCPtrTag.h	2019-07-24 23:07:48 UTC (rev 247798)
+++ trunk/Source/_javascript_Core/runtime/JSCPtrTag.h	2019-07-24 23:51:13 UTC (rev 247799)
@@ -35,6 +35,7 @@
     v(B3CCallPtrTag) \
     v(B3CompilationPtrTag) \
     v(BytecodePtrTag) \
+    v(CopyFunctionPtrTag) \
     v(DisassemblyPtrTag) \
     v(ExceptionHandlerPtrTag) \
     v(ExecutableMemoryPtrTag) \
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to