public inbox for gdb-prs@sourceware.org help / color / mirror / Atom feed
From: "david.spickett at linaro dot org" <sourceware-bugzilla@sourceware.org> To: gdb-prs@sourceware.org Subject: [Bug gdb/28947] New: GDB does not remove AArch64 pointer signatures before doing memory accesses Date: Mon, 07 Mar 2022 11:32:53 +0000 [thread overview] Message-ID: <bug-28947-4717@http.sourceware.org/bugzilla/> (raw) https://sourceware.org/bugzilla/show_bug.cgi?id=28947 Bug ID: 28947 Summary: GDB does not remove AArch64 pointer signatures before doing memory accesses Product: gdb Version: HEAD Status: UNCONFIRMED Severity: normal Priority: P2 Component: gdb Assignee: unassigned at sourceware dot org Reporter: david.spickett at linaro dot org Target Milestone: --- I'm using a somewhat recent build from source: ``` $ ./gdb --version GNU gdb (GDB) 12.0.50.20220208-git ``` binutils @ 481153777e278b71e694fd2db6b897f7a9e3dcb8 Compile the following: ``` #include <stddef.h> int main(int argc, char const *argv[]) { char* buf[16]; #define sign_ptr(ptr) \ __asm__ __volatile__("pacdza %0" \ : "=r"(ptr) \ : "r"(ptr)) // Set top byte including where memory tag bits would go. char *buf_with_non_address = (char *)((size_t)buf | (size_t)0xff << 56); sign_ptr(buf_with_non_address); // Address is now: // <4 bit user tag><4 bit memory tag><pointer signature><virtual address> return 0; // Set break point at this line. } ``` With: ``` aarch64-unknown-linux-gnu-gcc -march=armv8.3-a main.c -o prog -g ``` Then run it on an AArch64 machine that has pointer authentication enabled. Break at the indicated line where main returns. Expected behaviour: GDB would know that pointer signatures are "non-address bits" (not part of the virtual address) and remove them before attempting to do a memory access on a signed pointer. Actual behaviour: GDB does not remove these bits so it attempts to read a completely different memory location. (one cannot be mapped in any case) ``` (gdb) p &buf $4 = (char *(*)[16]) 0xfffffffff268 (gdb) p buf_with_non_address $5 = 0xff75fffffffff268 <error: Cannot access memory at address 0xff75fffffffff268> (gdb) x buf 0xfffffffff268: 0x00000000 (gdb) x buf_with_non_address 0xff75fffffffff268: Cannot access memory at address 0xff75fffffffff268 ``` I've been looking at this issue for lldb and it seems that other non-address bits like the top byte can be left in when giving ptrace a virtual address. Probably because the hardware ignores it for us. (this behaviour isn't guaranteed by the kernel though as far as I know) With pointer authentication, running code is expected to "auth" the pointer before use. This would remove the signature bits if successful. So a memory read/write with a signature still attached is always going to be a failure of some kind. GDB or GDB server should remove these signature bits before it gets to ptrace so that the user doesn't have to manually auth these pointers. For what it's worth, for lldb I'm looking at doing this in lldb not lldb-server. Keeps the server simple and fixes some other things like our memory caching along the way. Same approach might work for GDB as well. -- You are receiving this mail because: You are on the CC list for the bug.
next reply other threads:[~2022-03-07 11:32 UTC|newest] Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-03-07 11:32 david.spickett at linaro dot org [this message] 2022-03-07 11:45 ` [Bug gdb/28947] " luis.machado at arm dot com 2022-03-07 11:46 ` luis.machado at arm dot com 2022-03-07 13:28 ` luis.machado at arm dot com 2022-05-24 8:04 ` luis.machado at arm dot com 2022-05-24 8:06 ` luis.machado at arm dot com 2022-05-24 9:06 ` david.spickett at linaro dot org 2022-05-26 8:23 ` luis.machado at arm dot com 2022-09-15 7:58 ` luis.machado at arm dot com 2022-12-16 11:19 ` cvs-commit at gcc dot gnu.org 2022-12-16 11:22 ` luis.machado at arm dot com
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=bug-28947-4717@http.sourceware.org/bugzilla/ \ --to=sourceware-bugzilla@sourceware.org \ --cc=gdb-prs@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: linkBe 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).