[libunwind] [libunwind][AArch64] Protect PC within libunwind's context. (PR #113368)

Daniel Kiss via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 6 02:29:02 PST 2024


================
@@ -1845,8 +1884,14 @@ class _LIBUNWIND_HIDDEN Registers_arm64 {
 
   uint64_t  getSP() const         { return _registers.__sp; }
   void      setSP(uint64_t value) { _registers.__sp = value; }
-  uint64_t  getIP() const         { return _registers.__pc; }
-  void      setIP(uint64_t value) { _registers.__pc = value; }
+  uint64_t getIP() const { return auth(_registers.__pc, getAuthSalt()); }
+  void setIP(uint64_t value) {
+    // First authenticate the current value of the IP to ensure the context
+    // is still valid. This also ensure the setIP can't be used for signing
+    // arbitrary values.
+    auth(_registers.__pc, getAuthSalt());
----------------
DanielKristofKiss wrote:

A system without TBI and FPAC could be problematic as [signing](https://developer.arm.com/documentation/ddi0602/2024-09/Shared-Pseudocode/aarch64-functions-pac?lang=en#impl-aarch64.InsertPAC.6) adds PAC to the top bits ( ```result = ((ptr<63:56> EOR PAC<63:56>) : bit55 : ptr<54:0>); ```)
While XPAC's [Strip](https://developer.arm.com/documentation/ddi0602/2024-09/Shared-Pseudocode/aarch64-functions-pac?lang=en )) throws those way. (```original_ptr =  extfield<63:bottom_PAC_bit> : A<bottom_PAC_bit-1:0>;```)

I had a version 88b512720752c31374ca75b4c2ccab8b00b25fb1 for that cross checked the auth and xpac result but it [failed on bots](https://github.com/llvm/llvm-project/actions/runs/11524630174/job/32086008467#step:5:5362) as they don't have FPAC nor TBI and even PAC disabled but there are bits in the top part of the LR. 
xpac drop those bits always regardless of PAC status.

I'm planning to make this configurable, e.g when compiled with `-mbranch-protection`. 

I'm happy to hear more ideas.

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


More information about the cfe-commits mailing list