mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Dave Martin <Dave.Martin@arm.com>
To: linux-kernel@vger.kernel.org
Cc: Oleg Nesterov <oleg@redhat.com>, Kees Cook <kees@kernel.org>,
	Akihiko Odaki <akihiko.odaki@daynix.com>
Subject: [PATCH 02/23] regset: Add explicit core note name in struct user_regset
Date: Tue,  1 Jul 2025 14:55:55 +0100	[thread overview]
Message-ID: <20250701135616.29630-3-Dave.Martin@arm.com> (raw)
In-Reply-To: <20250701135616.29630-1-Dave.Martin@arm.com>

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


  parent reply	other threads:[~2025-07-01 13:56 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-01 13:55 [PATCH 00/23] binfmt_elf,arch/*: Use elf.h for coredump note names Dave Martin
2025-07-01 13:55 ` [PATCH 01/23] regset: Fix kerneldoc for struct regset_get() in user_regset Dave Martin
2025-07-01 13:55 ` Dave Martin [this message]
2025-07-09 11:57   ` [PATCH 02/23] regset: Add explicit core note name in struct user_regset Alexander Gordeev
2025-07-01 13:55 ` [PATCH 03/23] binfmt_elf: Dump non-arch notes with strictly matching name and type Dave Martin
2025-07-01 13:55 ` [PATCH 04/23] ARC: ptrace: Use USER_REGSET_NOTE_TYPE() to specify regset note names Dave Martin
2025-07-01 13:55 ` [PATCH 05/23] ARM: " Dave Martin
2025-07-01 13:55 ` [PATCH 06/23] arm64: " Dave Martin
2025-07-01 13:56 ` [PATCH 07/23] csky: " Dave Martin
2025-07-01 13:56 ` [PATCH 08/23] hexagon: " Dave Martin
2025-07-01 13:56 ` [PATCH 09/23] LoongArch: " Dave Martin
2025-07-01 13:56 ` [PATCH 10/23] m68k: " Dave Martin
2025-07-06  9:25   ` Geert Uytterhoeven
2025-07-07 10:54     ` Dave Martin
2025-07-01 13:56 ` [PATCH 11/23] MIPS: " Dave Martin
2025-07-01 13:56 ` [PATCH 12/23] nios2: " Dave Martin
2025-07-01 13:56 ` [PATCH 13/23] openrisc: " Dave Martin
2025-07-01 13:56 ` [PATCH 14/23] parisc: " Dave Martin
2025-07-01 13:56 ` [PATCH 15/23] powerpc/ptrace: " Dave Martin
2025-07-01 13:56 ` [PATCH 16/23] riscv: ptrace: " Dave Martin
2025-07-01 13:56 ` [PATCH 17/23] s390/ptrace: " Dave Martin
2025-07-09 11:58   ` Alexander Gordeev
2025-07-01 13:56 ` [PATCH 18/23] sh: ptrace: " Dave Martin
2025-07-01 13:56 ` [PATCH 19/23] sparc: " Dave Martin
2025-07-01 13:56 ` [PATCH 20/23] x86/ptrace: " Dave Martin
2025-07-01 13:56 ` [PATCH 21/23] um: ptrace: " Dave Martin
2025-07-04 11:58   ` Johannes Berg
2025-07-04 16:46     ` Dave Martin
2025-07-01 13:56 ` [PATCH 22/23] xtensa: " Dave Martin
2025-07-01 13:56 ` [PATCH 23/23] binfmt_elf: Warn on missing or suspicious " Dave Martin
2025-07-05 15:14   ` Kees Cook
2025-07-07 11:03     ` Dave Martin
2025-07-09  5:05 ` [PATCH 00/23] binfmt_elf,arch/*: Use elf.h for coredump " Akihiko Odaki
2025-07-15  5:37 ` Kees Cook
2025-07-15 10:32   ` Dave Martin
2025-08-10 21:12 ` patchwork-bot+linux-riscv

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=20250701135616.29630-3-Dave.Martin@arm.com \
    --to=dave.martin@arm.com \
    --cc=akihiko.odaki@daynix.com \
    --cc=kees@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=oleg@redhat.com \
    /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: link
Be 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

all inboxes | Powered by JetHome®