[llvm] [LFI][AArch64] Add PAC support (PR #207915)

Jacob Bramley via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 21 06:08:26 PDT 2026


================
@@ -296,8 +296,13 @@ before moving it back into ``sp`` with a safe ``add``.
 Link register modification
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
-When the link register is modified, we write the modified value to a
-temporary, before loading it back into ``x30`` with a safe ``add``.
+When the link register is modified, it is guarded back into the sandbox with a
+safe ``add x30, x27, w30, uxtw``. This guard is deferred until the next
+control-flow instruction rather than emitted immediately after the
+modification. Deferral keeps a signed return address intact so that a following
+authentication instruction (such as ``autiasp``) can run before the guard,
+which would otherwise destroy the pointer authentication signature. See
+`Pointer Authentication Code (PAC) support`_.
----------------
jacobbramley wrote:

> [...] the mask that gets inserted before the branch will simply overwrite the PAC bits, causing the later authentication to become a no-op.

I don't understand how, sorry. Authentication of a pointer with no (zero) PAC will normally fail. Otherwise, there'd have been no need to defer the sandboxing in the first place.

I think this code pattern should be pretty unusual, likely only occurring in hand-written code. For that reason, it might be reasonable to simply detect and throw an error when this happens.

Other types of CFI exist, yes, but I inferred that the idea here was to preserve the semantics of the source program whilst adding LFI sandboxing. Was I mistaken?

Thanks!

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


More information about the llvm-commits mailing list