[libcxx-commits] [libcxx] [PAC] Make __is_function_overridden pauth-aware on ELF platforms (PR #107498)

via libcxx-commits libcxx-commits at lists.llvm.org
Thu Sep 5 18:17:30 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libcxx

Author: Anton Korobeynikov (asl)

<details>
<summary>Changes</summary>

Apparently, there are two almost identical implementations: one for MachO and another one for ELF. The ELF bits somehow slipped while https://github.com/llvm/llvm-project/pull/84573 was reviewed.

The particular implementation is identical to MachO case.

---
Full diff: https://github.com/llvm/llvm-project/pull/107498.diff


1 Files Affected:

- (modified) libcxx/src/include/overridable_function.h (+8) 


``````````diff
diff --git a/libcxx/src/include/overridable_function.h b/libcxx/src/include/overridable_function.h
index e83ca7be7befaf..c56a00defbc56b 100644
--- a/libcxx/src/include/overridable_function.h
+++ b/libcxx/src/include/overridable_function.h
@@ -116,6 +116,14 @@ _LIBCPP_HIDE_FROM_ABI bool __is_function_overridden(_Ret (*__fptr)(_Args...)) no
   uintptr_t __end   = reinterpret_cast<uintptr_t>(&__stop___lcxx_override);
   uintptr_t __ptr   = reinterpret_cast<uintptr_t>(__fptr);
 
+#  if __has_feature(ptrauth_calls)
+  // We must pass a void* to ptrauth_strip since it only accepts a pointer type. Also, in particular,
+  // we must NOT pass a function pointer, otherwise we will strip the function pointer, and then attempt
+  // to authenticate and re-sign it when casting it to a uintptr_t again, which will fail because we just
+  // stripped the function pointer.
+  __ptr = reinterpret_cast<uintptr_t>(ptrauth_strip(reinterpret_cast<void*>(__ptr), ptrauth_key_function_pointer));
+#  endif
+
   return __ptr < __start || __ptr > __end;
 }
 _LIBCPP_END_NAMESPACE_STD

``````````

</details>


https://github.com/llvm/llvm-project/pull/107498


More information about the libcxx-commits mailing list