[v5,13/14] aarch64: redefine RETURN_ADDRESS to strip PAC

Message ID 6d42e5c2203cd7f8a9c0de04c12bb96fe09e260e.1592834304.git.szabolcs.nagy@arm.com
State Superseded
Headers show
Series
  • aarch64: branch protection support
Related show

Commit Message

Szabolcs Nagy June 22, 2020, 2:01 p.m.
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 | 7 +++++++
 1 file changed, 7 insertions(+)

-- 
2.17.1

Comments

Andreas Schwab June 22, 2020, 2:14 p.m. | #1
On Jun 22 2020, Szabolcs Nagy wrote:

> This is gcc PR target/95891: __builtin_return_address should not


That bug doesn't exist.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."
Szabolcs Nagy June 22, 2020, 2:17 p.m. | #2
The 06/22/2020 16:14, Andreas Schwab wrote:
> On Jun 22 2020, Szabolcs Nagy wrote:

> 

> > This is gcc PR target/95891: __builtin_return_address should not

> 

> That bug doesn't exist.


sorry it's PR target/94891, i will update the commit message.
Szabolcs Nagy June 22, 2020, 2:23 p.m. | #3
The 06/22/2020 15:17, Szabolcs Nagy wrote:
> The 06/22/2020 16:14, Andreas Schwab wrote:

> > On Jun 22 2020, Szabolcs Nagy wrote:

> > 

> > > This is gcc PR target/95891: __builtin_return_address should not

> > 

> > That bug doesn't exist.

> 

> sorry it's PR target/94891, i will update the commit message.


fixed the comment in the code and the commit message,

the updated series is now in the branch nsz/pacbti-v5.

Patch

diff --git a/sysdeps/aarch64/sysdep.h b/sysdeps/aarch64/sysdep.h
index 2879aeaa5c..593bdd35a2 100644
--- a/sysdeps/aarch64/sysdep.h
+++ b/sysdeps/aarch64/sysdep.h
@@ -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__