[2/3] aarch64: Add NT_ARM_PAC_* regset

Message ID 20240814085134.109500-3-kuan-ying.lee@canonical.com
State Committed
Delegated to: Mark Wielaard
Headers
Series aarch64: add some core note types name |

Commit Message

Kuan-Ying Lee Aug. 14, 2024, 8:51 a.m. UTC
  Add the NT_ARM_PAC_MASK and NT_ARM_PAC_ENABLED_KEYS for aarch64.
Recognize and print the new core item.

Signed-off-by: Kuan-Ying Lee <kuan-ying.lee@canonical.com>
---
 backends/aarch64_corenote.c  | 24 +++++++++++++++++++++++-
 libebl/eblcorenotetypename.c |  2 ++
 2 files changed, 25 insertions(+), 1 deletion(-)
  

Comments

Mark Wielaard Aug. 16, 2024, 11:36 p.m. UTC | #1
Hi,

On Wed, Aug 14, 2024 at 04:51:19PM +0800, Kuan-Ying Lee wrote:
> Add the NT_ARM_PAC_MASK and NT_ARM_PAC_ENABLED_KEYS for aarch64.
> Recognize and print the new core item.

For NT_ARM_PAC_MASK it looks like the user_pac_mask struct, so two 8
byte words. But for NT_ARM_PAC_ENABLED_KEYS I cannot find the
definition. This assumes it is just one 8 byte word. Is that correct?
Can it be more than one?

Thanks,

Mark

> Signed-off-by: Kuan-Ying Lee <kuan-ying.lee@canonical.com>
> ---
>  backends/aarch64_corenote.c  | 24 +++++++++++++++++++++++-
>  libebl/eblcorenotetypename.c |  2 ++
>  2 files changed, 25 insertions(+), 1 deletion(-)
> 
> diff --git a/backends/aarch64_corenote.c b/backends/aarch64_corenote.c
> index bd0a4a725411..35c8e8012c7b 100644
> --- a/backends/aarch64_corenote.c
> +++ b/backends/aarch64_corenote.c
> @@ -115,6 +115,26 @@ static const Ebl_Core_Item aarch64_mte_items [] =
>      }
>    };
>  
> +static const Ebl_Core_Item aarch64_pac_enabled_items [] =
> +  {
> +    {
> +      .name = "enabled_keys", .type = ELF_T_XWORD, .format = 'x',
> +      .offset = 0, .group = "register"
> +    }
> +  };
> +
> +static const Ebl_Core_Item aarch64_pac_mask_items [] =
> +  {
> +    {
> +      .name = "pauth_dmask", .type = ELF_T_XWORD, .format = 'x',
> +      .offset = 0, .group = "register"
> +    },
> +    {
> +      .name = "pauth_cmask", .type = ELF_T_XWORD, .format = 'x',
> +      .offset = 8, .group = "register"
> +    }
> +  };
> +
>  #define AARCH64_HWBP_REG(KIND, N)					\
>      {									\
>        .name = "DBG" KIND "VR" #N "_EL1", .type = ELF_T_XWORD, .format = 'x', \
> @@ -176,6 +196,8 @@ AARCH64_BP_WP_GROUP ("W", aarch64_hw_wp_items);
>    EXTRA_ITEMS (NT_ARM_HW_BREAK, 264, aarch64_hw_bp_items)		\
>    EXTRA_ITEMS (NT_ARM_HW_WATCH, 264, aarch64_hw_wp_items)		\
>    EXTRA_ITEMS (NT_ARM_SYSTEM_CALL, 4, aarch64_syscall_items) \
> -  EXTRA_ITEMS (NT_ARM_TAGGED_ADDR_CTRL, 8, aarch64_mte_items)
> +  EXTRA_ITEMS (NT_ARM_TAGGED_ADDR_CTRL, 8, aarch64_mte_items) \
> +  EXTRA_ITEMS (NT_ARM_PAC_ENABLED_KEYS, 8, aarch64_pac_enabled_items) \
> +  EXTRA_ITEMS (NT_ARM_PAC_MASK, 16, aarch64_pac_mask_items)
>  
>  #include "linux-core-note.c"
> diff --git a/libebl/eblcorenotetypename.c b/libebl/eblcorenotetypename.c
> index 49331bdf76e8..3e2f8daa0fd5 100644
> --- a/libebl/eblcorenotetypename.c
> +++ b/libebl/eblcorenotetypename.c
> @@ -93,6 +93,8 @@ ebl_core_note_type_name (Ebl *ebl, uint32_t type, char *buf, size_t len)
>  	    KNOWNSTYPE (ARM_HW_WATCH);
>  	    KNOWNSTYPE (ARM_SYSTEM_CALL);
>  	    KNOWNSTYPE (ARM_TAGGED_ADDR_CTRL);
> +	    KNOWNSTYPE (ARM_PAC_ENABLED_KEYS);
> +	    KNOWNSTYPE (ARM_PAC_MASK);
>  	    KNOWNSTYPE (SIGINFO);
>  	    KNOWNSTYPE (FILE);
>  #undef KNOWNSTYPE
> -- 
> 2.43.0
>
  
Kuan-Ying Lee Aug. 19, 2024, 9:43 a.m. UTC | #2
On Sat, Aug 17, 2024 at 01:36:33AM +0200, Mark Wielaard wrote:
> Hi,
> 
> On Wed, Aug 14, 2024 at 04:51:19PM +0800, Kuan-Ying Lee wrote:
> > Add the NT_ARM_PAC_MASK and NT_ARM_PAC_ENABLED_KEYS for aarch64.
> > Recognize and print the new core item.
> 
> For NT_ARM_PAC_MASK it looks like the user_pac_mask struct, so two 8
> byte words. But for NT_ARM_PAC_ENABLED_KEYS I cannot find the
> definition. This assumes it is just one 8 byte word. Is that correct?
> Can it be more than one?
> 

Hi Mark,

Thanks for your review.

I believe it should be exactly one 8-byte word in size.
I based this on the following code[1]:

 |	[REGSET_PAC_ENABLED_KEYS] = {
 |		.core_note_type = NT_ARM_PAC_ENABLED_KEYS,
 |		.n = 1,
 |		.size = sizeof(long),
 |		.align = sizeof(long),
 |		.regset_get = pac_enabled_keys_get,
 |		.set = pac_enabled_keys_set,

The size is sizeof(long), and n is 1.
It seems that there is only 1 8-byte word for arm64.

[1] https://elixir.bootlin.com/linux/v6.10.5/source/arch/arm64/kernel/ptrace.c#L1595

Thanks,
Kuan-Ying Lee

> Thanks,
> 
> Mark
> 
> > Signed-off-by: Kuan-Ying Lee <kuan-ying.lee@canonical.com>
> > ---
> >  backends/aarch64_corenote.c  | 24 +++++++++++++++++++++++-
> >  libebl/eblcorenotetypename.c |  2 ++
> >  2 files changed, 25 insertions(+), 1 deletion(-)
> > 
> > diff --git a/backends/aarch64_corenote.c b/backends/aarch64_corenote.c
> > index bd0a4a725411..35c8e8012c7b 100644
> > --- a/backends/aarch64_corenote.c
> > +++ b/backends/aarch64_corenote.c
> > @@ -115,6 +115,26 @@ static const Ebl_Core_Item aarch64_mte_items [] =
> >      }
> >    };
> >  
> > +static const Ebl_Core_Item aarch64_pac_enabled_items [] =
> > +  {
> > +    {
> > +      .name = "enabled_keys", .type = ELF_T_XWORD, .format = 'x',
> > +      .offset = 0, .group = "register"
> > +    }
> > +  };
> > +
> > +static const Ebl_Core_Item aarch64_pac_mask_items [] =
> > +  {
> > +    {
> > +      .name = "pauth_dmask", .type = ELF_T_XWORD, .format = 'x',
> > +      .offset = 0, .group = "register"
> > +    },
> > +    {
> > +      .name = "pauth_cmask", .type = ELF_T_XWORD, .format = 'x',
> > +      .offset = 8, .group = "register"
> > +    }
> > +  };
> > +
> >  #define AARCH64_HWBP_REG(KIND, N)					\
> >      {									\
> >        .name = "DBG" KIND "VR" #N "_EL1", .type = ELF_T_XWORD, .format = 'x', \
> > @@ -176,6 +196,8 @@ AARCH64_BP_WP_GROUP ("W", aarch64_hw_wp_items);
> >    EXTRA_ITEMS (NT_ARM_HW_BREAK, 264, aarch64_hw_bp_items)		\
> >    EXTRA_ITEMS (NT_ARM_HW_WATCH, 264, aarch64_hw_wp_items)		\
> >    EXTRA_ITEMS (NT_ARM_SYSTEM_CALL, 4, aarch64_syscall_items) \
> > -  EXTRA_ITEMS (NT_ARM_TAGGED_ADDR_CTRL, 8, aarch64_mte_items)
> > +  EXTRA_ITEMS (NT_ARM_TAGGED_ADDR_CTRL, 8, aarch64_mte_items) \
> > +  EXTRA_ITEMS (NT_ARM_PAC_ENABLED_KEYS, 8, aarch64_pac_enabled_items) \
> > +  EXTRA_ITEMS (NT_ARM_PAC_MASK, 16, aarch64_pac_mask_items)
> >  
> >  #include "linux-core-note.c"
> > diff --git a/libebl/eblcorenotetypename.c b/libebl/eblcorenotetypename.c
> > index 49331bdf76e8..3e2f8daa0fd5 100644
> > --- a/libebl/eblcorenotetypename.c
> > +++ b/libebl/eblcorenotetypename.c
> > @@ -93,6 +93,8 @@ ebl_core_note_type_name (Ebl *ebl, uint32_t type, char *buf, size_t len)
> >  	    KNOWNSTYPE (ARM_HW_WATCH);
> >  	    KNOWNSTYPE (ARM_SYSTEM_CALL);
> >  	    KNOWNSTYPE (ARM_TAGGED_ADDR_CTRL);
> > +	    KNOWNSTYPE (ARM_PAC_ENABLED_KEYS);
> > +	    KNOWNSTYPE (ARM_PAC_MASK);
> >  	    KNOWNSTYPE (SIGINFO);
> >  	    KNOWNSTYPE (FILE);
> >  #undef KNOWNSTYPE
> > -- 
> > 2.43.0
> >
  
Mark Wielaard Aug. 30, 2024, 2:29 p.m. UTC | #3
Hi Kuan-Ying,

On Mon, 2024-08-19 at 17:43 +0800, Kuan-Ying Lee wrote:
> On Sat, Aug 17, 2024 at 01:36:33AM +0200, Mark Wielaard wrote:
> > On Wed, Aug 14, 2024 at 04:51:19PM +0800, Kuan-Ying Lee wrote:
> > > Add the NT_ARM_PAC_MASK and NT_ARM_PAC_ENABLED_KEYS for aarch64.
> > > Recognize and print the new core item.
> > 
> > For NT_ARM_PAC_MASK it looks like the user_pac_mask struct, so two 8
> > byte words. But for NT_ARM_PAC_ENABLED_KEYS I cannot find the
> > definition. This assumes it is just one 8 byte word. Is that correct?
> > Can it be more than one?
> > 
> 
> I believe it should be exactly one 8-byte word in size.
> I based this on the following code[1]:
> 
>  |	[REGSET_PAC_ENABLED_KEYS] = {
>  |		.core_note_type = NT_ARM_PAC_ENABLED_KEYS,
>  |		.n = 1,
>  |		.size = sizeof(long),
>  |		.align = sizeof(long),
>  |		.regset_get = pac_enabled_keys_get,
>  |		.set = pac_enabled_keys_set,
> 
> The size is sizeof(long), and n is 1.
> It seems that there is only 1 8-byte word for arm64.
> 
> [1] https://elixir.bootlin.com/linux/v6.10.5/source/arch/arm64/kernel/ptrace.c#L1595

Thanks, so your code looks correct.

I rebased it on top of the PAC unwinding patches (which already
contained an definition of the pac_mask, but didn't add it to the known
types yet) and pushed it.

Thanks,

Mark
  

Patch

diff --git a/backends/aarch64_corenote.c b/backends/aarch64_corenote.c
index bd0a4a725411..35c8e8012c7b 100644
--- a/backends/aarch64_corenote.c
+++ b/backends/aarch64_corenote.c
@@ -115,6 +115,26 @@  static const Ebl_Core_Item aarch64_mte_items [] =
     }
   };
 
+static const Ebl_Core_Item aarch64_pac_enabled_items [] =
+  {
+    {
+      .name = "enabled_keys", .type = ELF_T_XWORD, .format = 'x',
+      .offset = 0, .group = "register"
+    }
+  };
+
+static const Ebl_Core_Item aarch64_pac_mask_items [] =
+  {
+    {
+      .name = "pauth_dmask", .type = ELF_T_XWORD, .format = 'x',
+      .offset = 0, .group = "register"
+    },
+    {
+      .name = "pauth_cmask", .type = ELF_T_XWORD, .format = 'x',
+      .offset = 8, .group = "register"
+    }
+  };
+
 #define AARCH64_HWBP_REG(KIND, N)					\
     {									\
       .name = "DBG" KIND "VR" #N "_EL1", .type = ELF_T_XWORD, .format = 'x', \
@@ -176,6 +196,8 @@  AARCH64_BP_WP_GROUP ("W", aarch64_hw_wp_items);
   EXTRA_ITEMS (NT_ARM_HW_BREAK, 264, aarch64_hw_bp_items)		\
   EXTRA_ITEMS (NT_ARM_HW_WATCH, 264, aarch64_hw_wp_items)		\
   EXTRA_ITEMS (NT_ARM_SYSTEM_CALL, 4, aarch64_syscall_items) \
-  EXTRA_ITEMS (NT_ARM_TAGGED_ADDR_CTRL, 8, aarch64_mte_items)
+  EXTRA_ITEMS (NT_ARM_TAGGED_ADDR_CTRL, 8, aarch64_mte_items) \
+  EXTRA_ITEMS (NT_ARM_PAC_ENABLED_KEYS, 8, aarch64_pac_enabled_items) \
+  EXTRA_ITEMS (NT_ARM_PAC_MASK, 16, aarch64_pac_mask_items)
 
 #include "linux-core-note.c"
diff --git a/libebl/eblcorenotetypename.c b/libebl/eblcorenotetypename.c
index 49331bdf76e8..3e2f8daa0fd5 100644
--- a/libebl/eblcorenotetypename.c
+++ b/libebl/eblcorenotetypename.c
@@ -93,6 +93,8 @@  ebl_core_note_type_name (Ebl *ebl, uint32_t type, char *buf, size_t len)
 	    KNOWNSTYPE (ARM_HW_WATCH);
 	    KNOWNSTYPE (ARM_SYSTEM_CALL);
 	    KNOWNSTYPE (ARM_TAGGED_ADDR_CTRL);
+	    KNOWNSTYPE (ARM_PAC_ENABLED_KEYS);
+	    KNOWNSTYPE (ARM_PAC_MASK);
 	    KNOWNSTYPE (SIGINFO);
 	    KNOWNSTYPE (FILE);
 #undef KNOWNSTYPE