[PATCH 02/23] regset: Add explicit core note name in struct user_regset

Dave Martin posted 23 patches 3 months, 1 week ago
[PATCH 02/23] regset: Add explicit core note name in struct user_regset
Posted by Dave Martin 3 months, 1 week ago
There is currently hard-coded logic spread around the tree for
determining the note name for regset notes emitted in coredumps.

Now that the names are declared explicitly in <uapi/elf.h>, this can be
simplified.

In preparation for getting rid of the special-case logic, add an
explicit core_note_name field in struct user_regset for specifying the
note name explicitly.  To help avoid mistakes, a convenience macro
USER_REGSET_NOTE_TYPE() is provided to set .core_note_type and
.core_note_name based on the note type.

When dumping core, use the new field to set the note name, if the
regset specifies it.

Signed-off-by: Dave Martin <Dave.Martin@arm.com>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Kees Cook <kees@kernel.org>
Cc: Akihiko Odaki <akihiko.odaki@daynix.com>
---
 fs/binfmt_elf.c        |  8 ++++++--
 include/linux/regset.h | 10 ++++++++++
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
index a43363d593e5..f1069103ca24 100644
--- a/fs/binfmt_elf.c
+++ b/fs/binfmt_elf.c
@@ -1727,6 +1727,7 @@ static int fill_thread_core_info(struct elf_thread_core_info *t,
 	for (view_iter = 1; view_iter < view->n; ++view_iter) {
 		const struct user_regset *regset = &view->regsets[view_iter];
 		int note_type = regset->core_note_type;
+		const char *note_name = regset->core_note_name;
 		bool is_fpreg = note_type == NT_PRFPREG;
 		void *data;
 		int ret;
@@ -1747,8 +1748,11 @@ static int fill_thread_core_info(struct elf_thread_core_info *t,
 		if (is_fpreg)
 			SET_PR_FPVALID(&t->prstatus);
 
-		fill_note(&t->notes[note_iter], is_fpreg ? NN_PRFPREG : "LINUX",
-			  note_type, ret, data);
+		if (!note_name)
+			note_name = is_fpreg ? NN_PRFPREG : "LINUX";
+
+		fill_note(&t->notes[note_iter], note_name, note_type,
+			  ret, data);
 
 		info->size += notesize(&t->notes[note_iter]);
 		note_iter++;
diff --git a/include/linux/regset.h b/include/linux/regset.h
index 02417e934845..ad1ca6fe04f4 100644
--- a/include/linux/regset.h
+++ b/include/linux/regset.h
@@ -151,6 +151,7 @@ typedef int user_regset_writeback_fn(struct task_struct *target,
  * @align:		Required alignment, in bytes.
  * @bias:		Bias from natural indexing.
  * @core_note_type:	ELF note @n_type value used in core dumps.
+ * @core_note_name:	ELF note name to qualify the note type.
  * @regset_get:		Function to fetch values.
  * @set:		Function to store values.
  * @active:		Function to report if regset is active, or %NULL.
@@ -190,6 +191,10 @@ typedef int user_regset_writeback_fn(struct task_struct *target,
  *
  * If nonzero, @core_note_type gives the n_type field (NT_* value)
  * of the core file note in which this regset's data appears.
+ * @core_note_name specifies the note name.  The preferred way to
+ * specify these two fields is to use the @USER_REGSET_NOTE_TYPE()
+ * macro.
+ *
  * NT_PRSTATUS is a special case in that the regset data starts at
  * offsetof(struct elf_prstatus, pr_reg) into the note data; that is
  * part of the per-machine ELF formats userland knows about.  In
@@ -207,8 +212,13 @@ struct user_regset {
 	unsigned int 			align;
 	unsigned int 			bias;
 	unsigned int 			core_note_type;
+	const char			*core_note_name;
 };
 
+#define USER_REGSET_NOTE_TYPE(type) \
+	.core_note_type			= (NT_ ## type), \
+	.core_note_name			= (NN_ ## type)
+
 /**
  * struct user_regset_view - available regsets
  * @name:	Identifier, e.g. UTS_MACHINE string.
-- 
2.34.1
Re: [PATCH 02/23] regset: Add explicit core note name in struct user_regset
Posted by Alexander Gordeev 3 months ago
On Tue, Jul 01, 2025 at 02:55:55PM +0100, Dave Martin wrote:
> There is currently hard-coded logic spread around the tree for
> determining the note name for regset notes emitted in coredumps.
> 
> Now that the names are declared explicitly in <uapi/elf.h>, this can be
> simplified.
> 
> In preparation for getting rid of the special-case logic, add an
> explicit core_note_name field in struct user_regset for specifying the
> note name explicitly.  To help avoid mistakes, a convenience macro
> USER_REGSET_NOTE_TYPE() is provided to set .core_note_type and
> .core_note_name based on the note type.
> 
> When dumping core, use the new field to set the note name, if the
> regset specifies it.
> 
> Signed-off-by: Dave Martin <Dave.Martin@arm.com>
> Cc: Oleg Nesterov <oleg@redhat.com>
> Cc: Kees Cook <kees@kernel.org>
> Cc: Akihiko Odaki <akihiko.odaki@daynix.com>
> ---
>  fs/binfmt_elf.c        |  8 ++++++--
>  include/linux/regset.h | 10 ++++++++++
>  2 files changed, 16 insertions(+), 2 deletions(-)

Acked-by: Alexander Gordeev <agordeev@linux.ibm.com> # s390