Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Kuan-Ying Lee via Gdb-patches <gdb-patches@sourceware.org>
To: Luis Machado <luis.machado@linaro.org>,
	"gdb-patches@sourceware.org" <gdb-patches@sourceware.org>
Cc: "James Hsu (徐慶薰)" <James.Hsu@mediatek.com>,
	"Nicholas Tang (鄭秦輝)" <nicholas.tang@mediatek.com>,
	"Zhiyong Wang (王志勇)" <Zhiyong.Wang@mediatek.com>,
	"Chinwen Chang (張錦文)" <chinwen.chang@mediatek.com>
Subject: Re: [PATCH] AArch64 pauth: Indicate addresses in backtrace for kernel
Date: Wed, 27 Oct 2021 11:27:59 +0800	[thread overview]
Message-ID: <1cf5b86b782785a4fa754475acd7377acd14bab4.camel@mediatek.com> (raw)
In-Reply-To: <a24fad7e-fa2f-4a05-5bfd-ea9e289a6c12@linaro.org>

On Tue, 2021-10-26 at 20:46 +0800, Luis Machado wrote:
> Hi!
> 
> Second time's the charm.
> 
> On 10/25/21 8:47 AM, Kuan-Ying Lee via Gdb-patches wrote:
> > Armv8.3-a Pointer Authentication cause the function return address
> > to
> > be changed. GDB need to use address bit[55] to know which mode is
> > active
> > and mask/unmask the link register in order to get backtrace.
> > 
> > If address is in kernel mode, we mask the address. If address is in
> > user mode,
> > we need to unmask the address.
> > ---
> >   gdb/aarch64-tdep.c | 5 ++++-
> >   1 file changed, 4 insertions(+), 1 deletion(-)
> > 
> > diff --git a/gdb/aarch64-tdep.c b/gdb/aarch64-tdep.c
> > index 4b5af4616af..d4bb4305cea 100644
> > --- a/gdb/aarch64-tdep.c
> > +++ b/gdb/aarch64-tdep.c
> > @@ -257,7 +257,10 @@ aarch64_frame_unmask_lr (struct gdbarch_tdep
> > *tdep,
> >       {
> >         int cmask_num = AARCH64_PAUTH_CMASK_REGNUM (tdep-
> > >pauth_reg_base);
> >         CORE_ADDR cmask = frame_unwind_register_unsigned
> > (this_frame, cmask_num);
> > -      addr = addr & ~cmask;
> > +      if (addr & 0x0080000000000000ULL)
> 
> I think we should define this constant in aarch64-tdep.h to make it
> more 
> obvious:
> 
> #define AARCH64_PAC_VA_RANGE_BIT 55
> #define AARCH64_PAC_VA_RANGE_MASK (1ULL << AARCH64_PAC_VA_RANGE_BIT)
> 
> > +        addr = addr | cmask;
> > +      else
> > +        addr = addr & ~cmask;
> 
> For the unmasking of the address, it would be nice to put this into
> a 
> separate function that unmasks an address given a particular mask
> value. 
> Something like this:
> 
> static CORE_ADDR
> aarch64_unmask_address (CORE_ADDR address, CORE_ADDR mask)
> {
>    /* Unmask kernel mode and user mode addresses appropriately based
> on
>       the VA range bit.  */
>    if (address & AARCH64_PAC_VA_RANGE_MASK)
>      address | mask;
>    else
>      address & ~mask;
> 
>    return address;
> }
> 
> If we ever need to unmask kernel/user addresses somewhere else in
> the 
> code, we can just call this function from now on.

Got it.
> 
> Could you please send a v2 of the patch with the suggested changes?

Sure.
Thanks for the suggestions.

> 
> Thanks for the patch.


      reply	other threads:[~2021-10-27  3:28 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-25 11:47 Kuan-Ying Lee via Gdb-patches
2021-10-25 12:07 ` Luis Machado via Gdb-patches
2021-10-26 12:22   ` Kuan-Ying Lee via Gdb-patches
2021-10-26 12:30     ` Luis Machado via Gdb-patches
2021-10-26 12:46 ` Luis Machado via Gdb-patches
2021-10-27  3:27   ` Kuan-Ying Lee via Gdb-patches [this message]

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=1cf5b86b782785a4fa754475acd7377acd14bab4.camel@mediatek.com \
    --to=gdb-patches@sourceware.org \
    --cc=James.Hsu@mediatek.com \
    --cc=Kuan-Ying.Lee@mediatek.com \
    --cc=Zhiyong.Wang@mediatek.com \
    --cc=chinwen.chang@mediatek.com \
    --cc=luis.machado@linaro.org \
    --cc=nicholas.tang@mediatek.com \
    /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