]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
aarch64: redefine RETURN_ADDRESS to strip PAC
authorSzabolcs Nagy <szabolcs.nagy@arm.com>
Wed, 15 Apr 2020 16:40:45 +0000 (17:40 +0100)
committerSzabolcs Nagy <szabolcs.nagy@arm.com>
Fri, 12 Jun 2020 13:34:39 +0000 (14:34 +0100)
RETURN_ADDRESS is used at several places in glibc to mean a valid
code address of the call site, but with pac-ret it may contain a
pointer authentication code (PAC), so its definition is adjusted.

This is gcc PR target/95891: __builtin_return_address should not
expose signed pointers to user code where it can cause ABI issues.
In glibc RETURN_ADDRESS is only changed if it is built with pac-ret.
There is no detection for the specific gcc issue because it is
hard to test and the additional xpac does not cause problems.

sysdeps/aarch64/sysdep.h

index 2879aeaa5cf42f0e26b4e99c8877f3e47d9465ab..593bdd35a2cf467b5430a2c1c57251a6d3835470 100644 (file)
@@ -44,6 +44,13 @@ strip_pac (void *p)
   asm ("hint 7 // xpaclri" : "+r"(ra));
   return ra;
 }
+
+/* This is needed when glibc is built with -mbranch-protection=pac-ret
+   with a gcc that is affected by PR target/95891.  */
+# if HAVE_AARCH64_PAC_RET
+#  undef RETURN_ADDRESS
+#  define RETURN_ADDRESS(n) strip_pac (__builtin_return_address (n))
+# endif
 #endif
 
 #ifdef __ASSEMBLER__