public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Adhemerval Zanella <adhemerval.zanella@linaro.org>
To: libc-alpha@sourceware.org
Subject: Re: [PATCH 11/12] aarch64: redefine RETURN_ADDRESS to strip PAC
Date: Fri, 8 May 2020 14:44:58 -0300	[thread overview]
Message-ID: <60967e5e-f6fb-c556-d7fb-ec3c737ed2fd@linaro.org> (raw)
In-Reply-To: <20200430174518.GG29015@arm.com>



On 30/04/2020 14:45, Szabolcs Nagy wrote:
> RETURN_ADDRESS is used at several places in glibc to mean a valid
> code address of the call site, but with pac-ret that includes a
> pointer authentication code, so the definition is adjusted.
> 
> XPAC is added unconditionally for now, but it's only needed if
> glibc is compiled with -mbranch-protection=pac-ret. Inline asm
> is used instead of __builtin_aarch64_xpaclri since that's an
> undocumented builtin and not available in all supported gccs.
> ---
>  sysdeps/aarch64/sysdep.h | 10 ++++++++++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/sysdeps/aarch64/sysdep.h b/sysdeps/aarch64/sysdep.h
> index 63a04a70cd..87f19b9bef 100644
> --- a/sysdeps/aarch64/sysdep.h
> +++ b/sysdeps/aarch64/sysdep.h
> @@ -35,6 +35,16 @@
>  
>  #define PTR_SIZE	(1<<PTR_LOG_SIZE)
>  
> +/* Strip pointer authentication code from pointer p.  */
> +#define XPAC(p) ({					\
> +  register void *__ra asm ("x30") = (p);		\
> +  asm ("hint 7 // xpaclri" : "+r"(__ra));		\
> +  __ra;})
> +
> +/* This is needed when glibc is built with -mbranch-protection=pac-ret.  */
> +#undef RETURN_ADDRESS
> +#define RETURN_ADDRESS(n) XPAC(__builtin_return_address(n))
> +

Maybe use a inline function instead?

  #ifndef __ASSEMBLER__
  # include <sys/cdefs.h>
  /* Strip pointer authentication code from pointer p.  */
  static __always_inline void *
  return_address (unsigned int n)
  { 
    register void *ra asm ("x30") = __builtin_return_address (n);
    asm ("hint 7 // xpaclri" : "+r" (ra));
    return ra;
  }

  /* This is needed when glibc is built with -mbranch-protection=pac-ret.  */
  # undef RETURN_ADDRESS
  # define RETURN_ADDRESS(n) return_address (n)
  #endif


>  #ifdef	__ASSEMBLER__
>  
>  /* Syntactic details of assembler.  */


  reply	other threads:[~2020-05-08 17:45 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-30 17:34 [PATCH 00/12] aarch64: branch protection support Szabolcs Nagy
2020-04-30 17:37 ` [PATCH 01/12] elf.h: Add PT_GNU_PROPERTY Szabolcs Nagy
2020-05-07 14:49   ` Adhemerval Zanella
2020-04-30 17:37 ` [PATCH 02/12] elf.h: add aarch64 property definitions Szabolcs Nagy
2020-05-07 14:50   ` Adhemerval Zanella
2020-04-30 17:39 ` [PATCH 03/12] aarch64: Add BTI landing pads to assembly code Szabolcs Nagy
2020-05-07 16:55   ` Adhemerval Zanella
2020-05-11 11:38     ` Szabolcs Nagy
2020-05-11 19:13       ` Adhemerval Zanella
2020-04-30 17:40 ` [PATCH 04/12] aarch64: Rename place holder .S files to .c Szabolcs Nagy
2020-05-07 18:29   ` Adhemerval Zanella
2020-04-30 17:41 ` [PATCH 05/12] aarch64: fix swapcontext for BTI Szabolcs Nagy
2020-05-07 18:42   ` Adhemerval Zanella
2020-04-30 17:42 ` [PATCH 06/12] aarch64: fix RTLD_START " Szabolcs Nagy
2020-05-07 18:49   ` Adhemerval Zanella
2020-05-07 19:24     ` Szabolcs Nagy
2020-05-07 19:55       ` Adhemerval Zanella
2020-05-07 20:14         ` Szabolcs Nagy
2020-05-07 20:20           ` Adhemerval Zanella
2020-04-30 17:42 ` [PATCH 07/12] aarch64: fix syscalls " Szabolcs Nagy
2020-05-07 19:40   ` Adhemerval Zanella
2020-05-11 11:46     ` Szabolcs Nagy
2020-04-30 17:43 ` [PATCH 08/12] Rewrite abi-note.S in C Szabolcs Nagy
2020-04-30 20:07   ` Zack Weinberg
2020-05-01  9:23     ` Szabolcs Nagy
2020-05-01 14:07       ` Zack Weinberg
2020-04-30 17:44 ` [PATCH 09/12] aarch64: support BTI enabled binaries Szabolcs Nagy
2020-05-07 21:07   ` Adhemerval Zanella
2020-05-11 11:04     ` Szabolcs Nagy
2020-05-11 18:38       ` Adhemerval Zanella
2020-04-30 17:44 ` [PATCH 10/12] aarch64: Add pac-ret support to asm files Szabolcs Nagy
2020-05-08 16:59   ` Adhemerval Zanella
2020-05-11  8:27     ` Szabolcs Nagy
2020-05-11 18:39       ` Adhemerval Zanella
2020-04-30 17:45 ` [PATCH 11/12] aarch64: redefine RETURN_ADDRESS to strip PAC Szabolcs Nagy
2020-05-08 17:44   ` Adhemerval Zanella [this message]
2020-05-11 12:38     ` Szabolcs Nagy
2020-05-11 19:15       ` Adhemerval Zanella
2020-05-11 19:21         ` Florian Weimer
2020-05-11 20:13           ` Adhemerval Zanella
2020-05-11 20:18             ` Florian Weimer
2020-05-11 19:22   ` Florian Weimer
2020-05-11 20:45     ` Adhemerval Zanella
2020-05-12  8:42     ` Szabolcs Nagy
2020-04-30 17:45 ` [PATCH 12/12] aarch64: Configure option to build glibc with branch protection Szabolcs Nagy
2020-04-30 19:02   ` Joseph Myers
2020-05-08 17:53   ` Adhemerval Zanella
2020-05-04 11:27 ` [PATCH 00/12] aarch64: branch protection support Szabolcs Nagy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=60967e5e-f6fb-c556-d7fb-ec3c737ed2fd@linaro.org \
    --to=adhemerval.zanella@linaro.org \
    --cc=libc-alpha@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).