Patchwork [v2,1/8] AArch64: Add pointer authentication feature

login
register
mail settings
Submitter Alan Hayward
Date March 6, 2019, 1:33 p.m.
Message ID <20190306133325.2531-2-alan.hayward@arm.com>
Download mbox | patch
Permalink /patch/31730/
State New
Headers show

Comments

Alan Hayward - March 6, 2019, 1:33 p.m.
Pointer Authentication is a new feature in AArch64 v8.3-a. When enabled in
the compiler, function return addresses will be mangled by the kernel.

Add register description xml and wire up to aarch64_linux_read_description.
This description includes the two pauth user registers.

Nothing yet uses the feature - that is added in later patches.

gdb/ChangeLog:

2019-03-06  Alan Hayward  <alan.hayward@arm.com>
	    Jiong Wang  <jiong.wang@arm.com>

	* aarch64-linux-nat.c
	(aarch64_linux_nat_target::read_description): Add pauth param.
	* aarch64-linux-tdep.c
	(aarch64_linux_core_read_description): Likewise.
	* aarch64-tdep.c (struct target_desc): Add in pauth.
	(aarch64_read_description): Add pauth param.
	(aarch64_gdbarch_init): Likewise.
	* aarch64-tdep.h (aarch64_read_description): Likewise.
	* arch/aarch64.c (aarch64_create_target_description): Likewise.
	* arch/aarch64.h (aarch64_create_target_description): Likewise.
	* features/Makefile: Add new files.
	* features/aarch64-pauth.c: New file.
	* features/aarch64-pauth.xml: New file.

gdb/doc/ChangeLog:

2019-03-06  Alan Hayward  <alan.hayward@arm.com>
	    Jiong Wang  <jiong.wang@arm.com>

	* gdb.texinfo: Describe pauth feature.

gdb/gdbserver/ChangeLog:

2019-03-06  Alan Hayward  <alan.hayward@arm.com>
	    Jiong Wang  <jiong.wang@arm.com>

	* linux-aarch64-ipa.c (get_ipa_tdesc): Add pauth param.
	(initialize_low_tracepoint): Likewise.
	* linux-aarch64-low.c (aarch64_arch_setup): Likewise.
	* linux-aarch64-tdesc-selftest.c (aarch64_tdesc_test): Likewise.
	* linux-aarch64-tdesc.c (struct target_desc): Likewise.
	(aarch64_linux_read_description): Likewise.
	* linux-aarch64-tdesc.h (aarch64_linux_read_description): Likewise.
---
 gdb/aarch64-linux-nat.c                      |  5 +++--
 gdb/aarch64-linux-tdep.c                     |  4 +++-
 gdb/aarch64-tdep.c                           | 14 +++++++-------
 gdb/aarch64-tdep.h                           |  2 +-
 gdb/arch/aarch64.c                           |  6 +++++-
 gdb/arch/aarch64.h                           |  5 +++--
 gdb/doc/gdb.texinfo                          |  3 +++
 gdb/features/Makefile                        |  1 +
 gdb/features/aarch64-pauth.c                 | 16 ++++++++++++++++
 gdb/features/aarch64-pauth.xml               | 13 +++++++++++++
 gdb/gdbserver/linux-aarch64-ipa.c            |  8 ++++----
 gdb/gdbserver/linux-aarch64-low.c            |  3 ++-
 gdb/gdbserver/linux-aarch64-tdesc-selftest.c |  2 +-
 gdb/gdbserver/linux-aarch64-tdesc.c          | 10 +++++-----
 gdb/gdbserver/linux-aarch64-tdesc.h          |  2 +-
 15 files changed, 68 insertions(+), 26 deletions(-)
 create mode 100644 gdb/features/aarch64-pauth.c
 create mode 100644 gdb/features/aarch64-pauth.xml
Eli Zaretskii - March 6, 2019, 3:36 p.m.
> From: Alan Hayward <Alan.Hayward@arm.com>
> CC: nd <nd@arm.com>, Alan Hayward <Alan.Hayward@arm.com>
> Date: Wed, 6 Mar 2019 13:33:34 +0000
> 
> gdb/doc/ChangeLog:
> 
> 2019-03-06  Alan Hayward  <alan.hayward@arm.com>
> 	    Jiong Wang  <jiong.wang@arm.com>
> 
> 	* gdb.texinfo: Describe pauth feature.

This part is OK, but please mention the name of the node where you are
making the changes, as if it were a function.

Patch

diff --git a/gdb/aarch64-linux-nat.c b/gdb/aarch64-linux-nat.c
index 6f91e9568e..f58a41e195 100644
--- a/gdb/aarch64-linux-nat.c
+++ b/gdb/aarch64-linux-nat.c
@@ -605,8 +605,9 @@  aarch64_linux_nat_target::read_description ()
   ret = ptrace (PTRACE_GETREGSET, tid, NT_ARM_VFP, &iovec);
   if (ret == 0)
     return tdesc_arm_with_neon;
-  else
-    return aarch64_read_description (aarch64_sve_get_vq (tid));
+
+  /* pauth not yet supported.  */
+  return aarch64_read_description (aarch64_sve_get_vq (tid), false);
 }
 
 /* Convert a native/host siginfo object, into/from the siginfo in the
diff --git a/gdb/aarch64-linux-tdep.c b/gdb/aarch64-linux-tdep.c
index 39e607658f..445019accc 100644
--- a/gdb/aarch64-linux-tdep.c
+++ b/gdb/aarch64-linux-tdep.c
@@ -640,7 +640,9 @@  aarch64_linux_core_read_description (struct gdbarch *gdbarch,
   if (target_auxv_search (target, AT_HWCAP, &aarch64_hwcap) != 1)
     return NULL;
 
-  return aarch64_read_description (aarch64_linux_core_read_vq (gdbarch, abfd));
+  /* pauth not yet supported.  */
+  return aarch64_read_description (aarch64_linux_core_read_vq (gdbarch, abfd),
+				   false);
 }
 
 /* Implementation of `gdbarch_stap_is_single_operand', as defined in
diff --git a/gdb/aarch64-tdep.c b/gdb/aarch64-tdep.c
index dd57ef9873..0518837a1f 100644
--- a/gdb/aarch64-tdep.c
+++ b/gdb/aarch64-tdep.c
@@ -69,7 +69,7 @@ 
 #define HA_MAX_NUM_FLDS		4
 
 /* All possible aarch64 target descriptors.  */
-struct target_desc *tdesc_aarch64_list[AARCH64_MAX_SVE_VQ + 1];
+struct target_desc *tdesc_aarch64_list[AARCH64_MAX_SVE_VQ + 1][2/*pauth*/];
 
 /* The standard register names, and all the valid aliases for them.  */
 static const struct
@@ -2885,18 +2885,18 @@  aarch64_displaced_step_hw_singlestep (struct gdbarch *gdbarch,
    (It is not possible to set VQ to zero on an SVE system).  */
 
 const target_desc *
-aarch64_read_description (uint64_t vq)
+aarch64_read_description (uint64_t vq, bool pauth_p)
 {
   if (vq > AARCH64_MAX_SVE_VQ)
     error (_("VQ is %" PRIu64 ", maximum supported value is %d"), vq,
 	   AARCH64_MAX_SVE_VQ);
 
-  struct target_desc *tdesc = tdesc_aarch64_list[vq];
+  struct target_desc *tdesc = tdesc_aarch64_list[vq][pauth_p];
 
   if (tdesc == NULL)
     {
-      tdesc = aarch64_create_target_description (vq);
-      tdesc_aarch64_list[vq] = tdesc;
+      tdesc = aarch64_create_target_description (vq, pauth_p);
+      tdesc_aarch64_list[vq][pauth_p] = tdesc;
     }
 
   return tdesc;
@@ -2961,7 +2961,7 @@  aarch64_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 
   /* Ensure we always have a target description.  */
   if (!tdesc_has_registers (tdesc))
-    tdesc = aarch64_read_description (0);
+    tdesc = aarch64_read_description (0, false);
   gdb_assert (tdesc);
 
   feature_core = tdesc_find_feature (tdesc, "org.gnu.gdb.aarch64.core");
@@ -3190,7 +3190,7 @@  When on, AArch64 specific debugging is enabled."),
   selftests::register_test ("aarch64-process-record",
 			    selftests::aarch64_process_record_test);
   selftests::record_xml_tdesc ("aarch64.xml",
-			       aarch64_create_target_description (0));
+			       aarch64_create_target_description (0, false));
 #endif
 }
 
diff --git a/gdb/aarch64-tdep.h b/gdb/aarch64-tdep.h
index 704eacb50c..3db6bee9f3 100644
--- a/gdb/aarch64-tdep.h
+++ b/gdb/aarch64-tdep.h
@@ -89,7 +89,7 @@  struct gdbarch_tdep
   }
 };
 
-const target_desc *aarch64_read_description (uint64_t vq);
+const target_desc *aarch64_read_description (uint64_t vq, bool pauth_p);
 
 extern int aarch64_process_record (struct gdbarch *gdbarch,
                                struct regcache *regcache, CORE_ADDR addr);
diff --git a/gdb/arch/aarch64.c b/gdb/arch/aarch64.c
index d36ed9d19e..11a15dd94c 100644
--- a/gdb/arch/aarch64.c
+++ b/gdb/arch/aarch64.c
@@ -22,11 +22,12 @@ 
 #include "../features/aarch64-core.c"
 #include "../features/aarch64-fpu.c"
 #include "../features/aarch64-sve.c"
+#include "../features/aarch64-pauth.c"
 
 /* See arch/aarch64.h.  */
 
 target_desc *
-aarch64_create_target_description (uint64_t vq)
+aarch64_create_target_description (uint64_t vq, bool pauth_p)
 {
   target_desc *tdesc = allocate_target_description ();
 
@@ -43,5 +44,8 @@  aarch64_create_target_description (uint64_t vq)
   else
     regnum = create_feature_aarch64_sve (tdesc, regnum, vq);
 
+  if (pauth_p)
+    regnum = create_feature_aarch64_pauth (tdesc, regnum);
+
   return tdesc;
 }
diff --git a/gdb/arch/aarch64.h b/gdb/arch/aarch64.h
index 807a4a6558..4fe6d02f6e 100644
--- a/gdb/arch/aarch64.h
+++ b/gdb/arch/aarch64.h
@@ -24,9 +24,10 @@ 
 
 /* Create the aarch64 target description.  A non zero VQ value indicates both
    the presence of SVE and the Vector Quotient - the number of 128bit chunks in
-   an SVE Z register.  */
+   an SVE Z register.  HAS_PAUTH_P indicates the presence of the PAUTH
+   feature.  */
 
-target_desc *aarch64_create_target_description (uint64_t vq);
+target_desc *aarch64_create_target_description (uint64_t vq, bool has_pauth_p);
 
 /* Register numbers of various important registers.
    Note that on SVE, the Z registers reuse the V register numbers and the V
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index f2028f86b0..e4d8e44cae 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -43076,6 +43076,9 @@  The @samp{org.gnu.gdb.aarch64.sve} feature is optional.  If present,
 it should contain registers @samp{z0} through @samp{z31}, @samp{p0}
 through @samp{p15}, @samp{ffr} and @samp{vg}.
 
+The @samp{org.gnu.gdb.aarch64.pauth} feature is optional.  If present,
+it should contain registers @samp{pauth_dmask} and @samp{pauth_cmask}.
+
 @node ARC Features
 @subsection ARC Features
 @cindex target descriptions, ARC Features
diff --git a/gdb/features/Makefile b/gdb/features/Makefile
index 3d84ca09a1..d0cd4f851f 100644
--- a/gdb/features/Makefile
+++ b/gdb/features/Makefile
@@ -227,6 +227,7 @@  $(outdir)/%.dat: %.xml number-regs.xsl sort-regs.xsl gdbserver-regs.xsl
 
 FEATURE_XMLFILES = aarch64-core.xml \
 	aarch64-fpu.xml \
+	aarch64-pauth.xml \
 	i386/32bit-core.xml \
 	i386/32bit-sse.xml \
 	i386/32bit-linux.xml \
diff --git a/gdb/features/aarch64-pauth.c b/gdb/features/aarch64-pauth.c
new file mode 100644
index 0000000000..e4b84ffb55
--- /dev/null
+++ b/gdb/features/aarch64-pauth.c
@@ -0,0 +1,16 @@ 
+/* THIS FILE IS GENERATED.  -*- buffer-read-only: t -*- vi:set ro:
+  Original: aarch64-pauth.xml */
+
+#include "common/tdesc.h"
+
+static int
+create_feature_aarch64_pauth (struct target_desc *result, long regnum)
+{
+  struct tdesc_feature *feature;
+
+  feature = tdesc_create_feature (result, "org.gnu.gdb.aarch64.pauth");
+  tdesc_create_reg (feature, "pauth_dmask", regnum++, 1, NULL, 64, "int");
+  tdesc_create_reg (feature, "pauth_cmask", regnum++, 1, NULL, 64, "int");
+
+  return regnum;
+}
diff --git a/gdb/features/aarch64-pauth.xml b/gdb/features/aarch64-pauth.xml
new file mode 100644
index 0000000000..9c8987fca7
--- /dev/null
+++ b/gdb/features/aarch64-pauth.xml
@@ -0,0 +1,13 @@ 
+<?xml version="1.0"?>
+<!-- Copyright (C) 2018 Free Software Foundation, Inc.
+
+     Copying and distribution of this file, with or without modification,
+     are permitted in any medium without royalty provided the copyright
+     notice and this notice are preserved.  -->
+
+<!DOCTYPE feature SYSTEM "gdb-target.dtd">
+<feature name="org.gnu.gdb.aarch64.pauth">
+  <reg name="pauth_dmask" bitsize="64"/>
+  <reg name="pauth_cmask" bitsize="64"/>
+</feature>
+
diff --git a/gdb/gdbserver/linux-aarch64-ipa.c b/gdb/gdbserver/linux-aarch64-ipa.c
index 94db53f59a..3804b1e239 100644
--- a/gdb/gdbserver/linux-aarch64-ipa.c
+++ b/gdb/gdbserver/linux-aarch64-ipa.c
@@ -147,12 +147,12 @@  get_raw_reg (const unsigned char *raw_regs, int regnum)
 
 /* Return target_desc to use for IPA, given the tdesc index passed by
    gdbserver.  Index is ignored, since we have only one tdesc
-   at the moment.  SVE not yet supported.  */
+   at the moment.  SVE and pauth not yet supported.  */
 
 const struct target_desc *
 get_ipa_tdesc (int idx)
 {
-  return aarch64_linux_read_description (0);
+  return aarch64_linux_read_description (0, false);
 }
 
 /* Allocate buffer for the jump pads.  The branch instruction has a reach
@@ -204,6 +204,6 @@  alloc_jump_pad_buffer (size_t size)
 void
 initialize_low_tracepoint (void)
 {
-  /* SVE not yet supported.  */
-  aarch64_linux_read_description (0);
+  /* SVE and pauth not yet supported.  */
+  aarch64_linux_read_description (0, false);
 }
diff --git a/gdb/gdbserver/linux-aarch64-low.c b/gdb/gdbserver/linux-aarch64-low.c
index 0b2946ea22..db329da4dc 100644
--- a/gdb/gdbserver/linux-aarch64-low.c
+++ b/gdb/gdbserver/linux-aarch64-low.c
@@ -501,7 +501,8 @@  aarch64_arch_setup (void)
   if (is_elf64)
     {
       uint64_t vq = aarch64_sve_get_vq (tid);
-      current_process ()->tdesc = aarch64_linux_read_description (vq);
+      /* pauth not yet supported.  */
+      current_process ()->tdesc = aarch64_linux_read_description (vq, false);
     }
   else
     current_process ()->tdesc = tdesc_arm_with_neon;
diff --git a/gdb/gdbserver/linux-aarch64-tdesc-selftest.c b/gdb/gdbserver/linux-aarch64-tdesc-selftest.c
index 1b2453aa30..bf24a27c59 100644
--- a/gdb/gdbserver/linux-aarch64-tdesc-selftest.c
+++ b/gdb/gdbserver/linux-aarch64-tdesc-selftest.c
@@ -29,7 +29,7 @@  namespace tdesc {
 static void
 aarch64_tdesc_test ()
 {
-  const target_desc *tdesc = aarch64_linux_read_description (0);
+  const target_desc *tdesc = aarch64_linux_read_description (0, false);
   SELF_CHECK (*tdesc == *tdesc_aarch64);
 }
 }
diff --git a/gdb/gdbserver/linux-aarch64-tdesc.c b/gdb/gdbserver/linux-aarch64-tdesc.c
index 6ab473ea51..6f9b4f1efc 100644
--- a/gdb/gdbserver/linux-aarch64-tdesc.c
+++ b/gdb/gdbserver/linux-aarch64-tdesc.c
@@ -24,22 +24,22 @@ 
 #include <inttypes.h>
 
 /* All possible aarch64 target descriptors.  */
-struct target_desc *tdesc_aarch64_list[AARCH64_MAX_SVE_VQ + 1];
+struct target_desc *tdesc_aarch64_list[AARCH64_MAX_SVE_VQ + 1][2/*pauth*/];
 
 /* Create the aarch64 target description.  */
 
 const target_desc *
-aarch64_linux_read_description (uint64_t vq)
+aarch64_linux_read_description (uint64_t vq, bool pauth_p)
 {
   if (vq > AARCH64_MAX_SVE_VQ)
     error (_("VQ is %" PRIu64 ", maximum supported value is %d"), vq,
 	   AARCH64_MAX_SVE_VQ);
 
-  struct target_desc *tdesc = tdesc_aarch64_list[vq];
+  struct target_desc *tdesc = tdesc_aarch64_list[vq][pauth_p];
 
   if (tdesc == NULL)
     {
-      tdesc = aarch64_create_target_description (vq);
+      tdesc = aarch64_create_target_description (vq, pauth_p);
 
       static const char *expedite_regs_aarch64[] = { "x29", "sp", "pc", NULL };
       static const char *expedite_regs_aarch64_sve[] = { "x29", "sp", "pc",
@@ -50,7 +50,7 @@  aarch64_linux_read_description (uint64_t vq)
       else
 	init_target_desc (tdesc, expedite_regs_aarch64_sve);
 
-      tdesc_aarch64_list[vq] = tdesc;
+      tdesc_aarch64_list[vq][pauth_p] = tdesc;
     }
 
   return tdesc;
diff --git a/gdb/gdbserver/linux-aarch64-tdesc.h b/gdb/gdbserver/linux-aarch64-tdesc.h
index 7ce8150663..06b3ec9b1e 100644
--- a/gdb/gdbserver/linux-aarch64-tdesc.h
+++ b/gdb/gdbserver/linux-aarch64-tdesc.h
@@ -20,7 +20,7 @@ 
 #ifndef GDBSERVER_LINUX_AARCH64_TDESC_H
 #define GDBSERVER_LINUX_AARCH64_TDESC_H
 
-const target_desc * aarch64_linux_read_description (uint64_t vq);
+const target_desc * aarch64_linux_read_description (uint64_t vq, bool pauth_p);
 
 #if GDB_SELF_TEST
 void initialize_low_tdesc ();