AArch64 pauth: Indicate unmasked addresses in backtrace

Armv8.3-a Pointer Authentication causes the function return address to be
obfuscated on entry to some functions. GDB must unmask the link register in
order to produce a backtrace.

The following patch adds markers of [PAC] to the bracktrace, to indicate
which addresses needed unmasking.  This includes the backtrace when using MI.

For example, consider the following backtrace:

(gdb) bt
0  0x0000000000400490 in puts@plt ()
1  0x00000000004005dc in foo ("hello") at cbreak-lib.c:6
2  0x0000000000400604 [PAC] in bar () at cbreak-lib.c:12
3  0x0000000000400620 [PAC] in main2 () at cbreak.c:17
4  0x00000000004005b4 in main () at cbreak-3.c:10

The functions in cbreak-lib use pointer auth, which masks the return address
to the previous function, causing the addresses of bar (in the library) and main2
(in the main binary) to require unmasking in order to unwind the backtrace.

An extra bool is added alongside the prev_pc in the frame structure.  At the
point at which the link register is unmasked, the AArch64 port calls into frame
to sets the bool.  This is the most efficient way of doing it.

The marker is also added to the python frame printer, which is always printed if
set.  The marker is not explicitly exposed to the python code.

I expect this will potentially cause issues with some tests in the testsuite
when Armv8.3 pointer authentication is used.  This should be fixed up in the
the future once real hardware is available for full testsuite testing.

gdb/ChangeLog:

        * NEWS: Expand the Pointer Authentication entry.
        * aarch64-tdep.c (aarch64_frame_unmask_address): Rename from this.
        (aarch64_frame_unmask_lr): ... to this.
        (aarch64_prologue_prev_register, aarch64_dwarf2_prev_register):
        Call aarch64_frame_unmask_lr.
        * frame.c (struct frame_info): Add "masked" variable.
        (frame_set_previous_pc_masked) (frame_get_pc_masked): New functions.
        (fprint_frame): Check for masked pc.
        * frame.h (frame_set_previous_pc_masked) (frame_get_pc_masked): New
        declarations.
	* python/py-framefilter.c (py_print_frame): Check for masked pc.
        * stack.c (print_frame): Check for masked pc.

gdb/doc/ChangeLog:

        * gdb.texinfo (AArch64 Pointer Authentication): New subsection.
This commit is contained in:
Alan Hayward
2019-08-07 09:47:57 +01:00
parent fca8e23c31
commit 3d31bc39e6
9 changed files with 82 additions and 11 deletions

View File

@ -123,6 +123,8 @@ struct frame_info
/* Cached copy of the previous frame's resume address. */
struct {
enum cached_copy_status status;
/* Did VALUE require unmasking when being read. */
bool masked;
CORE_ADDR value;
} prev_pc;
@ -161,6 +163,25 @@ struct frame_info
const char *stop_string;
};
/* See frame.h. */
void
set_frame_previous_pc_masked (struct frame_info *frame)
{
frame->prev_pc.masked = true;
}
/* See frame.h. */
bool
get_frame_pc_masked (const struct frame_info *frame)
{
gdb_assert (frame->next != nullptr);
gdb_assert (frame->next->prev_pc.status == CC_VALUE);
return frame->next->prev_pc.masked;
}
/* A frame stash used to speed up frame lookups. Create a hash table
to stash frames previously accessed from the frame cache for
quicker subsequent retrieval. The hash table is emptied whenever
@ -429,8 +450,11 @@ fprint_frame (struct ui_file *file, struct frame_info *fi)
if (fi->next == NULL || fi->next->prev_pc.status == CC_UNKNOWN)
fprintf_unfiltered (file, "<unknown>");
else if (fi->next->prev_pc.status == CC_VALUE)
fprintf_unfiltered (file, "%s",
hex_string (fi->next->prev_pc.value));
{
fprintf_unfiltered (file, "%s", hex_string (fi->next->prev_pc.value));
if (fi->next->prev_pc.masked)
fprintf_unfiltered (file, "[PAC]");
}
else if (fi->next->prev_pc.status == CC_NOT_SAVED)
val_print_not_saved (file);
else if (fi->next->prev_pc.status == CC_UNAVAILABLE)