[libcxx-commits] [compiler-rt] [libcxx] [libcxxabi] [libunwind] [runtimes][PAC] Harden unwinding when possible (PR #143230)

Daniil Kovalev via libcxx-commits libcxx-commits at lists.llvm.org
Sun Oct 19 14:53:59 PDT 2025


================
@@ -118,22 +118,62 @@ _LIBUNWIND_HIDDEN int __unw_set_reg(unw_cursor_t *cursor, unw_regnum_t regNum,
   typedef LocalAddressSpace::pint_t pint_t;
   AbstractUnwindCursor *co = (AbstractUnwindCursor *)cursor;
   if (co->validReg(regNum)) {
-    co->setReg(regNum, (pint_t)value);
     // special case altering IP to re-find info (being called by personality
     // function)
     if (regNum == UNW_REG_IP) {
       unw_proc_info_t info;
       // First, get the FDE for the old location and then update it.
       co->getInfo(&info);
-      co->setInfoBasedOnIPRegister(false);
+
+      pint_t sp = (pint_t)co->getReg(UNW_REG_SP);
+
+#if defined(_LIBUNWIND_TARGET_AARCH64_AUTHENTICATED_UNWINDING)
+      {
+        // It is only valid to set the IP within the current function.
+        // This is important for ptrauth, otherwise the IP cannot be correctly
+        // signed.
+        // We re-sign to a more usable form and then use it directly.
+        union {
----------------
kovdan01 wrote:

Please avoid using unions here as well since reading from `authenticated_value` while `opaque_value` was the last assigned member is UB in C++.

I've prepared a fix which works on my side. You are welcome to just apply that if you are happy with the fix implementation. See commit a29af825c71d70e83445cd4214f7145642201506 from my branch [ptrauth-unwinding-2025-10-19](https://github.com/kovdan01/llvm-project/commits/ptrauth-unwinding-2025-10-19/)

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


More information about the libcxx-commits mailing list