elf: Define note name macros
Subsystems (11)
v5 cover elf: Define note name macros
elf.h had a comment saying:
Quoted 5 lines
Notes used in
ET_CORE. Architectures export some of the arch register sets using the corresponding note types via thePTRACE_GETREGSETandPTRACE_SETREGSETrequests.
The note name for these types is "LINUX", exceptNT_PRFPREGthat is named "CORE".
However, NT_PRSTATUS is also named "CORE". It is also unclear what "these types" refers to.
To fix these problems, define a name for each note type. The added definitions are macros so the kernel and userspace can directly refer to them.
For userspace program developers
---------------------------------------------------
While the main purpose of new macros is documentation, they are also hoped to be useful for userspace programs. Please check patch "elf: Define note name macros" and if you have a suggestion to make it more convenient for you, please share.
I added the Binutils mailing list to the CC as it contains code to parse dumps. I'm also planning to share this series on LLVM Discourse.
---
Changes in v5:
- Noted that patch "elf: Define note name macros" allows removing duplicate definitions of note names.
- Reordered NT_GNU_PROPERTY_TYPE_0 to precede notes used in ET_CORE to show its not specific to ET_CORE.
- Link to v4: https://lore.kernel.org/r/[email protected]
Changes in v4:
- s/powwerpc/powerpc/
- s/NT_INIT/nt_init/g s/NT_SIZE/nt_size/g
- Removed parentheses that have little value.
- Fixed the code alignment in get_cpu_elf_notes_size().
- Link to v3: https://lore.kernel.org/r/[email protected]
Changes in v3:
- Added patch "s390/crash: Use note name macros".
- Changed to interleave note name and type macros.
- Described NN_ and NT_ macros.
- Link to v2: https://lore.kernel.org/r/[email protected]
Changes in v2:
- Added a macro definition for each note type instead of trying to describe in a comment.
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Akihiko Odaki (6):
elf: Define note name macros
binfmt_elf: Use note name macros
powerpc: Use note name macros
crash: Use note name macros
s390/crash: Use note name macros
crash: Remove KEXEC_CORE_NOTE_NAME
arch/powerpc/kernel/fadump.c | 2 +- arch/powerpc/platforms/powernv/opal-core.c | 8 +-- arch/s390/kernel/crash_dump.c | 62 ++++++++------------- fs/binfmt_elf.c | 21 ++++--- fs/binfmt_elf_fdpic.c | 8 +-- fs/proc/kcore.c | 12 ++-- include/linux/kexec.h | 2 - include/linux/vmcore_info.h | 3 +- include/uapi/linux/elf.h | 89 ++++++++++++++++++++++++++++-- kernel/crash_core.c | 2 +- 10 files changed, 134 insertions(+), 75 deletions(-)
---
base-commit: a32e14f8aef69b42826cf0998b068a43d486a9e9
change-id: 20241210-elf-b80ea3949c39
Best regards,
Signature · 1 line
Akihiko Odaki <[email protected]>
PATCH v5 1/6 elf: Define note name macros
elf.h had a comment saying:
Quoted 5 lines
Notes used in
ET_CORE. Architectures export some of the arch register sets using the corresponding note types via thePTRACE_GETREGSETandPTRACE_SETREGSETrequests.
The note name for these types is "LINUX", exceptNT_PRFPREGthat is named "CORE".
However, NT_PRSTATUS is also named "CORE". It is also unclear what "these types" refers to.
To fix these problems, define a name for each note type. The added definitions are macros so the kernel and userspace can directly refer to them to remove their duplicate definitions of note names.
--- include/uapi/linux/elf.h | 89 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 84 insertions(+), 5 deletions(-)
include/uapi/linux/elf.h +84 -5
@@ -368,101 +368,180 @@ typedef struct elf64_shdr {#define ELF_OSABI ELFOSABI_NONE#endif +/* Note definitions: NN_ defines names. NT_ defines types. */ + +#define NN_GNU_PROPERTY_TYPE_0 "GNU" +#define NT_GNU_PROPERTY_TYPE_0 5 +/* * Notes used in ET_CORE. Architectures export some of the arch register sets * using the corresponding note types via the PTRACE_GETREGSET and * PTRACE_SETREGSET requests. -* The note name for these types is "LINUX", except NT_PRFPREG that is named -* "CORE". */ +#define NN_PRSTATUS "CORE"#define NT_PRSTATUS 1 +#define NN_PRFPREG "CORE"#define NT_PRFPREG 2 +#define NN_PRPSINFO "CORE"#define NT_PRPSINFO 3 +#define NN_TASKSTRUCT "CORE"#define NT_TASKSTRUCT 4 +#define NN_AUXV "CORE"#define NT_AUXV 6/* * Note to userspace developers: size of NT_SIGINFO note may increase * in the future to accomodate more fields, don't assume it is fixed! */ +#define NN_SIGINFO "CORE"#define NT_SIGINFO 0x53494749 +#define NN_FILE "CORE"#define NT_FILE 0x46494c45 +#define NN_PRXFPREG "LINUX"#define NT_PRXFPREG 0x46e62b7f/* copied from gdb5.1/include/elf/common.h */ +#define NN_PPC_VMX "LINUX"#define NT_PPC_VMX 0x100/* PowerPC Altivec/VMX registers */ +#define NN_PPC_SPE "LINUX"#define NT_PPC_SPE 0x101/* PowerPC SPE/EVR registers */ +#define NN_PPC_VSX "LINUX"#define NT_PPC_VSX 0x102/* PowerPC VSX registers */ +#define NN_PPC_TAR "LINUX"#define NT_PPC_TAR 0x103/* Target Address Register */ +#define NN_PPC_PPR "LINUX"#define NT_PPC_PPR 0x104/* Program Priority Register */ +#define NN_PPC_DSCR "LINUX"#define NT_PPC_DSCR 0x105/* Data Stream Control Register */ +#define NN_PPC_EBB "LINUX"#define NT_PPC_EBB 0x106/* Event Based Branch Registers */ +#define NN_PPC_PMU "LINUX"#define NT_PPC_PMU 0x107/* Performance Monitor Registers */ +#define NN_PPC_TM_CGPR "LINUX"#define NT_PPC_TM_CGPR 0x108/* TM checkpointed GPR Registers */ +#define NN_PPC_TM_CFPR "LINUX"#define NT_PPC_TM_CFPR 0x109/* TM checkpointed FPR Registers */ +#define NN_PPC_TM_CVMX "LINUX"#define NT_PPC_TM_CVMX 0x10a/* TM checkpointed VMX Registers */ +#define NN_PPC_TM_CVSX "LINUX"#define NT_PPC_TM_CVSX 0x10b/* TM checkpointed VSX Registers */ +#define NN_PPC_TM_SPR "LINUX"#define NT_PPC_TM_SPR 0x10c/* TM Special Purpose Registers */ +#define NN_PPC_TM_CTAR "LINUX"#define NT_PPC_TM_CTAR 0x10d/* TM checkpointed Target Address Register */ +#define NN_PPC_TM_CPPR "LINUX"#define NT_PPC_TM_CPPR 0x10e/* TM checkpointed Program Priority Register */ +#define NN_PPC_TM_CDSCR "LINUX"#define NT_PPC_TM_CDSCR 0x10f/* TM checkpointed Data Stream Control Register */ +#define NN_PPC_PKEY "LINUX"#define NT_PPC_PKEY 0x110/* Memory Protection Keys registers */ +#define NN_PPC_DEXCR "LINUX"#define NT_PPC_DEXCR 0x111/* PowerPC DEXCR registers */ +#define NN_PPC_HASHKEYR "LINUX"#define NT_PPC_HASHKEYR 0x112/* PowerPC HASHKEYR register */ +#define NN_386_TLS "LINUX"#define NT_386_TLS 0x200/* i386 TLS slots (struct user_desc) */ +#define NN_386_IOPERM "LINUX"#define NT_386_IOPERM 0x201/* x86 io permission bitmap (1=deny) */ +#define NN_X86_XSTATE "LINUX"#define NT_X86_XSTATE 0x202/* x86 extended state using xsave */ /* Old binutils treats 0x203 as a CET state */ +#define NN_X86_SHSTK "LINUX"#define NT_X86_SHSTK 0x204/* x86 SHSTK state */ +#define NN_X86_XSAVE_LAYOUT "LINUX"#define NT_X86_XSAVE_LAYOUT 0x205/* XSAVE layout description */ +#define NN_S390_HIGH_GPRS "LINUX"#define NT_S390_HIGH_GPRS 0x300/* s390 upper register halves */ +#define NN_S390_TIMER "LINUX"#define NT_S390_TIMER 0x301/* s390 timer register */ +#define NN_S390_TODCMP "LINUX"#define NT_S390_TODCMP 0x302/* s390 TOD clock comparator register */ +#define NN_S390_TODPREG "LINUX"#define NT_S390_TODPREG 0x303/* s390 TOD programmable register */ +#define NN_S390_CTRS "LINUX"#define NT_S390_CTRS 0x304/* s390 control registers */ +#define NN_S390_PREFIX "LINUX"#define NT_S390_PREFIX 0x305/* s390 prefix register */ +#define NN_S390_LAST_BREAK "LINUX"#define NT_S390_LAST_BREAK 0x306/* s390 breaking event address */ +#define NN_S390_SYSTEM_CALL "LINUX"#define NT_S390_SYSTEM_CALL 0x307/* s390 system call restart data */ +#define NN_S390_TDB "LINUX"#define NT_S390_TDB 0x308/* s390 transaction diagnostic block */ +#define NN_S390_VXRS_LOW "LINUX"#define NT_S390_VXRS_LOW 0x309/* s390 vector registers 0-15 upper half */ +#define NN_S390_VXRS_HIGH "LINUX"#define NT_S390_VXRS_HIGH 0x30a/* s390 vector registers 16-31 */ +#define NN_S390_GS_CB "LINUX"#define NT_S390_GS_CB 0x30b/* s390 guarded storage registers */ +#define NN_S390_GS_BC "LINUX"#define NT_S390_GS_BC 0x30c/* s390 guarded storage broadcast control block */ +#define NN_S390_RI_CB "LINUX"#define NT_S390_RI_CB 0x30d/* s390 runtime instrumentation */ +#define NN_S390_PV_CPU_DATA "LINUX"#define NT_S390_PV_CPU_DATA 0x30e/* s390 protvirt cpu dump data */ +#define NN_ARM_VFP "LINUX"#define NT_ARM_VFP 0x400/* ARM VFP/NEON registers */ +#define NN_ARM_TLS "LINUX"#define NT_ARM_TLS 0x401/* ARM TLS register */ +#define NN_ARM_HW_BREAK "LINUX"#define NT_ARM_HW_BREAK 0x402/* ARM hardware breakpoint registers */ +#define NN_ARM_HW_WATCH "LINUX"#define NT_ARM_HW_WATCH 0x403/* ARM hardware watchpoint registers */ +#define NN_ARM_SYSTEM_CALL "LINUX"#define NT_ARM_SYSTEM_CALL 0x404/* ARM system call number */ +#define NN_ARM_SVE "LINUX"#define NT_ARM_SVE 0x405/* ARM Scalable Vector Extension registers */ +#define NN_ARM_PAC_MASK "LINUX"#define NT_ARM_PAC_MASK 0x406/* ARM pointer authentication code masks */ +#define NN_ARM_PACA_KEYS "LINUX"#define NT_ARM_PACA_KEYS 0x407/* ARM pointer authentication address keys */ +#define NN_ARM_PACG_KEYS "LINUX"#define NT_ARM_PACG_KEYS 0x408/* ARM pointer authentication generic key */ +#define NN_ARM_TAGGED_ADDR_CTRL "LINUX"#define NT_ARM_TAGGED_ADDR_CTRL 0x409/* arm64 tagged address control (prctl()) */ +#define NN_ARM_PAC_ENABLED_KEYS "LINUX"#define NT_ARM_PAC_ENABLED_KEYS 0x40a/* arm64 ptr auth enabled keys (prctl()) */ +#define NN_ARM_SSVE "LINUX"#define NT_ARM_SSVE 0x40b/* ARM Streaming SVE registers */ +#define NN_ARM_ZA "LINUX"#define NT_ARM_ZA 0x40c/* ARM SME ZA registers */ +#define NN_ARM_ZT "LINUX"#define NT_ARM_ZT 0x40d/* ARM SME ZT registers */ +#define NN_ARM_FPMR "LINUX"#define NT_ARM_FPMR 0x40e/* ARM floating point mode register */ +#define NN_ARM_POE "LINUX"#define NT_ARM_POE 0x40f/* ARM POE registers */ +#define NN_ARM_GCS "LINUX"#define NT_ARM_GCS 0x410/* ARM GCS state */ +#define NN_ARC_V2 "LINUX"#define NT_ARC_V2 0x600/* ARCv2 accumulator/extra registers */ +#define NN_VMCOREDD "LINUX"#define NT_VMCOREDD 0x700/* Vmcore Device Dump Note */ +#define NN_MIPS_DSP "LINUX"#define NT_MIPS_DSP 0x800/* MIPS DSP ASE registers */ +#define NN_MIPS_FP_MODE "LINUX"#define NT_MIPS_FP_MODE 0x801/* MIPS floating-point mode */ +#define NN_MIPS_MSA "LINUX"#define NT_MIPS_MSA 0x802/* MIPS SIMD registers */ +#define NN_RISCV_CSR "LINUX"#define NT_RISCV_CSR 0x900/* RISC-V Control and Status Registers */ +#define NN_RISCV_VECTOR "LINUX"#define NT_RISCV_VECTOR 0x901/* RISC-V vector registers */ +#define NN_RISCV_TAGGED_ADDR_CTRL "LINUX"#define NT_RISCV_TAGGED_ADDR_CTRL 0x902/* RISC-V tagged address control (prctl()) */ +#define NN_LOONGARCH_CPUCFG "LINUX"#define NT_LOONGARCH_CPUCFG 0xa00/* LoongArch CPU config registers */ +#define NN_LOONGARCH_CSR "LINUX"#define NT_LOONGARCH_CSR 0xa01/* LoongArch control and status registers */ +#define NN_LOONGARCH_LSX "LINUX"#define NT_LOONGARCH_LSX 0xa02/* LoongArch Loongson SIMD Extension registers */ +#define NN_LOONGARCH_LASX "LINUX"#define NT_LOONGARCH_LASX 0xa03/* LoongArch Loongson Advanced SIMD Extension registers */ +#define NN_LOONGARCH_LBT "LINUX"#define NT_LOONGARCH_LBT 0xa04/* LoongArch Loongson Binary Translation registers */ +#define NN_LOONGARCH_HW_BREAK "LINUX"#define NT_LOONGARCH_HW_BREAK 0xa05/* LoongArch hardware breakpoint registers */ +#define NN_LOONGARCH_HW_WATCH "LINUX"#define NT_LOONGARCH_HW_WATCH 0xa06/* LoongArch hardware watchpoint registers */ -/* Note types with note name "GNU" */ -#define NT_GNU_PROPERTY_TYPE_0 5 -/* Note header in a PT_NOTE section */ typedef struct elf32_note { Elf32_Word n_namesz; /* Name size */
Signature · 1 line
2.47.1
Hi,
Quoted 25 lines · Akihiko Odaki
elf.hhad a comment saying:Quoted 5 lines
Notes used in
ET_CORE. Architectures export some of the arch register sets using the corresponding note types via thePTRACE_GETREGSETandPTRACE_SETREGSETrequests.
The note name for these types is "LINUX", exceptNT_PRFPREGthat is named "CORE".However,
NT_PRSTATUSis also named "CORE". It is also unclear what "these types" refers to.To fix these problems, define a name for each note type. The added definitions are macros so the kernel and userspace can directly refer to them to remove their duplicate definitions of note names.
Signed-off-by Akihiko Odaki <[email protected]>Acked-by Baoquan He <[email protected]>--- include/uapi/linux/elf.h | 89 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 84 insertions(+), 5 deletions(-)include/uapi/linux/elf.h +0
-0
include/uapi/linux/elf.h typedef struct elf64_shdr { · line 375
Quoted 8 lines
include/uapi/linux/elf.h +5
-0@@ -368,101 +368,180 @@ typedef struct elf64_shdr {#define ELF_OSABI ELFOSABI_NONE#endif +/* Note definitions: NN_ defines names. NT_ defines types. */ + +#define NN_GNU_PROPERTY_TYPE_0 "GNU" +#define NT_GNU_PROPERTY_TYPE_0 5 +
I guess this also works as a neutral way of saying that NT_GNU_PROPERTY_TYPE_0 isn't _specifically_ for coredumps.
I would worry that moving this block is going to generate unwanted context noise with other patches that may be in flight and add new NT_ definitions.
But (a) changing the comments will cause that anyway, and
(b) if there are any new NT_ definitions in flight, we want people to notice the conflict and add the accompanying NN_ definition.
So, perhaps context noise is not such a bad thing in this instance.
[...]
include/uapi/linux/elf.h typedef struct elf64_shdr { · line 547
Quoted 9 lines
include/uapi/linux/elf.h +1
-3+#define NN_LOONGARCH_HW_WATCH "LINUX"#define NT_LOONGARCH_HW_WATCH 0xa06/* LoongArch hardware watchpoint registers */ -/* Note types with note name "GNU" */ -#define NT_GNU_PROPERTY_TYPE_0 5 -/* Note header in a PT_NOTE section */ typedef struct elf32_note { Elf32_Word n_namesz; /* Name size */
Cheers
---Dave
PATCH v5 2/6 binfmt_elf: Use note name macros
In reply to Akihiko OdakiUse note name macros to match with the userspace's expectation.
--- fs/binfmt_elf.c | 21 ++++++++++----------- fs/binfmt_elf_fdpic.c | 8 ++++---- 2 files changed, 14 insertions(+), 15 deletions(-)
fs/binfmt_elf.c +10 -11
@@ -762,8 +762,7 @@ static int parse_elf_property(const char *data, size_t *off, size_t datasz, }#define NOTE_DATA_SZ SZ_1K -#define GNU_PROPERTY_TYPE_0_NAME "GNU" -#define NOTE_NAME_SZ (sizeof(GNU_PROPERTY_TYPE_0_NAME)) +#define NOTE_NAME_SZ (sizeof(NN_GNU_PROPERTY_TYPE_0))static int parse_elf_properties (struct file *f,const struct elf_phdr *phdr,struct arch_elf_state *arch)
@@ -800,7 +799,7 @@ static int parse_elf_properties(struct file *f, const struct elf_phdr *phdr,if (note.nhdr.n_type !=NT_GNU_PROPERTY_TYPE_0 || note.nhdr.n_namesz !=NOTE_NAME_SZ ||strncmp (note.data +sizeof (note.nhdr), -GNU_PROPERTY_TYPE_0_NAME , n -sizeof (note.nhdr))) +NN_GNU_PROPERTY_TYPE_0 , n -sizeof (note.nhdr)))return -ENOEXEC ; off = round_up(sizeof(note.nhdr) + NOTE_NAME_SZ,
@@ -1603,14 +1602,14 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)do i +=2 ;while (auxv[i -2 ] !=AT_NULL ); -fill_note (note,"CORE" ,NT_AUXV , i *sizeof (elf_addr_t), auxv); +fill_note (note,NN_AUXV ,NT_AUXV , i *sizeof (elf_addr_t), auxv); }static void fill_siginfo_note (struct memelfnote *note,user_siginfo_t *csigdata,const kernel_siginfo_t *siginfo) {copy_siginfo_to_external (csigdata, siginfo); -fill_note (note,"CORE" ,NT_SIGINFO ,sizeof (*csigdata), csigdata); +fill_note (note,NN_SIGINFO ,NT_SIGINFO ,sizeof (*csigdata), csigdata); }/*
@@ -1706,7 +1705,7 @@ static int fill_files_note(struct memelfnote *note, struct coredump_params *cprm } size = name_curpos - (char *)data; -fill_note (note,"CORE" ,NT_FILE , size, data); +fill_note (note,NN_FILE ,NT_FILE , size, data);return 0 ; }
@@ -1767,7 +1766,7 @@ static int fill_thread_core_info(struct elf_thread_core_info *t,regset_get (t->task, &view->regsets[0 ],sizeof (t->prstatus.pr_reg), &t->prstatus.pr_reg); -fill_note (&t->notes[0 ],"CORE" ,NT_PRSTATUS , +fill_note (&t->notes[0 ],NN_PRSTATUS ,NT_PRSTATUS ,PRSTATUS_SIZE , &t->prstatus); info->size +=notesize (&t->notes[0 ]);
@@ -1801,7 +1800,7 @@ 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 ?"CORE" :"LINUX" , +fill_note (&t->notes[note_iter], is_fpreg ?NN_PRFPREG :"LINUX" , note_type, ret, data); info->size +=notesize (&t->notes[note_iter]);
@@ -1821,7 +1820,7 @@ static int fill_thread_core_info(struct elf_thread_core_info *t,fill_prstatus (&t->prstatus.common, p, signr);elf_core_copy_task_regs (p, &t->prstatus.pr_reg); -fill_note (&t->notes[0 ],"CORE" ,NT_PRSTATUS ,sizeof (t->prstatus), +fill_note (&t->notes[0 ],NN_PRSTATUS ,NT_PRSTATUS ,sizeof (t->prstatus), &(t->prstatus)); info->size +=notesize (&t->notes[0 ]);
@@ -1832,7 +1831,7 @@ static int fill_thread_core_info(struct elf_thread_core_info *t, } t->prstatus.pr_fpvalid =1 ; -fill_note (&t->notes[1 ],"CORE" ,NT_PRFPREG ,sizeof (*fpu), fpu); +fill_note (&t->notes[1 ],NN_PRFPREG ,NT_PRFPREG ,sizeof (*fpu), fpu); info->size +=notesize (&t->notes[1 ]);return 1 ;
@@ -1852,7 +1851,7 @@ static int fill_note_info(struct elfhdr *elf, int phdrs, psinfo =kmalloc (sizeof (*psinfo),GFP_KERNEL );if (!psinfo)return 0 ; -fill_note (&info->psinfo,"CORE" ,NT_PRPSINFO ,sizeof (*psinfo), psinfo); +fill_note (&info->psinfo,NN_PRPSINFO ,NT_PRPSINFO ,sizeof (*psinfo), psinfo);#ifdef CORE_DUMP_USE_REGSET view =task_user_regset_view (dump_task);
fs/binfmt_elf_fdpic.c +4 -4
@@ -1397,7 +1397,7 @@ static struct elf_thread_status *elf_dump_thread_status(long signr, struct task_regset_get (p, &view->regsets[0 ],sizeof (t->prstatus.pr_reg), &t->prstatus.pr_reg); -fill_note (&t->notes[0 ],"CORE" ,NT_PRSTATUS ,sizeof (t->prstatus), +fill_note (&t->notes[0 ],NN_PRSTATUS ,NT_PRSTATUS ,sizeof (t->prstatus), &t->prstatus); t->num_notes++; *sz +=notesize (&t->notes[0 ]);
@@ -1415,7 +1415,7 @@ static struct elf_thread_status *elf_dump_thread_status(long signr, struct task_ }if (t->prstatus.pr_fpvalid) { -fill_note (&t->notes[1 ],"CORE" ,NT_PRFPREG ,sizeof (t->fpu), +fill_note (&t->notes[1 ],NN_PRFPREG ,NT_PRFPREG ,sizeof (t->fpu), &t->fpu); t->num_notes++; *sz +=notesize (&t->notes[1 ]);
@@ -1530,7 +1530,7 @@ static int elf_fdpic_core_dump(struct coredump_params *cprm)*/ fill_psinfo (psinfo, current->group_leader, current->mm); -fill_note (&psinfo_note,"CORE" ,NT_PRPSINFO ,sizeof (*psinfo), psinfo); +fill_note (&psinfo_note,NN_PRPSINFO ,NT_PRPSINFO ,sizeof (*psinfo), psinfo); thread_status_size +=notesize (&psinfo_note); auxv = (elf_addr_t *) current->mm->saved_auxv;
@@ -1538,7 +1538,7 @@ static int elf_fdpic_core_dump(struct coredump_params *cprm)do i +=2 ;while (auxv[i -2 ] !=AT_NULL ); -fill_note (&auxv_note,"CORE" ,NT_AUXV , i *sizeof (elf_addr_t), auxv); +fill_note (&auxv_note,NN_AUXV ,NT_AUXV , i *sizeof (elf_addr_t), auxv); thread_status_size +=notesize (&auxv_note); offset =sizeof (*elf);/* ELF header */
Signature · 1 line
2.47.1
PATCH v5 3/6 powerpc: Use note name macros
In reply to Akihiko OdakiUse note name macros to match with the userspace's expectation.
--- arch/powerpc/kernel/fadump.c | 2 +- arch/powerpc/platforms/powernv/opal-core.c | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-)
arch/powerpc/kernel/fadump.c +1 -1
@@ -751,7 +751,7 @@ u32 *__init fadump_regs_to_elf_notes(u32 *buf, struct pt_regs *regs)* prstatus.pr_pid = ???? */ elf_core_copy_regs (&prstatus.pr_reg, regs); - buf =append_elf_note (buf,CRASH_CORE_NOTE_NAME ,NT_PRSTATUS , + buf =append_elf_note (buf,NN_PRSTATUS ,NT_PRSTATUS , &prstatus,sizeof (prstatus));return buf; }
arch/powerpc/platforms/powernv/opal-core.c +4 -4
@@ -149,7 +149,7 @@ static Elf64_Word *__init auxv_to_elf64_notes(Elf64_Word *buf,/* end of vector */ bufp[idx++] =cpu_to_be64 (AT_NULL ); - buf =append_elf64_note (buf,CRASH_CORE_NOTE_NAME ,NT_AUXV , + buf =append_elf64_note (buf,NN_AUXV ,NT_AUXV , oc_conf->auxv_buf,AUXV_DESC_SZ );return buf; }
@@ -252,7 +252,7 @@ static Elf64_Word * __init opalcore_append_cpu_notes(Elf64_Word *buf)* crashing CPU's prstatus. */ first_cpu_note = buf; - buf =append_elf64_note (buf,CRASH_CORE_NOTE_NAME ,NT_PRSTATUS , + buf =append_elf64_note (buf,NN_PRSTATUS ,NT_PRSTATUS , &prstatus,sizeof (prstatus));for (i =0 ; i < oc_conf->num_cpus; i++, bufp += size_per_thread) {
@@ -279,7 +279,7 @@ static Elf64_Word * __init opalcore_append_cpu_notes(Elf64_Word *buf)fill_prstatus (&prstatus, thread_pir, ®s);if (thread_pir != oc_conf->crashing_cpu) { - buf =append_elf64_note (buf,CRASH_CORE_NOTE_NAME , + buf =append_elf64_note (buf,NN_PRSTATUS ,NT_PRSTATUS , &prstatus,sizeof (prstatus)); }else {
@@ -287,7 +287,7 @@ static Elf64_Word * __init opalcore_append_cpu_notes(Elf64_Word *buf)* Add crashing CPU as the first NT_PRSTATUS note for * GDB to process the core file appropriately. */ -append_elf64_note (first_cpu_note,CRASH_CORE_NOTE_NAME , +append_elf64_note (first_cpu_note,NN_PRSTATUS ,NT_PRSTATUS , &prstatus,sizeof (prstatus)); }
Signature · 1 line
2.47.1
PATCH v5 4/6 crash: Use note name macros
In reply to Akihiko OdakiUse note name macros to match with the userspace's expectation.
--- fs/proc/kcore.c | 12 ++++++------ include/linux/vmcore_info.h | 2 +- kernel/crash_core.c | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-)
fs/proc/kcore.c +6 -6
@@ -34,8 +34,6 @@#include <asm/sections.h> #include "internal.h" -#define CORE_STR "CORE" -#ifndef ELF_CORE_EFLAGS #define ELF_CORE_EFLAGS 0#endif
@@ -119,7 +117,9 @@ static size_t get_kcore_size(int *nphdr, size_t *phdrs_len, size_t *notes_len, *phdrs_len = *nphdr *sizeof (struct elf_phdr ); *notes_len = (4 * sizeof(struct elf_note) + - 3 * ALIGN(sizeof(CORE_STR), 4) + + ALIGN(sizeof(NN_PRSTATUS), 4) + + ALIGN(sizeof(NN_PRPSINFO), 4) + + ALIGN(sizeof(NN_TASKSTRUCT), 4) + VMCOREINFO_NOTE_NAME_BYTES + ALIGN(sizeof(struct elf_prstatus), 4) + ALIGN(sizeof(struct elf_prpsinfo), 4) +
@@ -444,11 +444,11 @@ static ssize_t read_kcore_iter(struct kiocb *iocb, struct iov_iter *iter) goto out; } -append_kcore_note (notes, &i,CORE_STR ,NT_PRSTATUS , &prstatus, +append_kcore_note (notes, &i,NN_PRSTATUS ,NT_PRSTATUS , &prstatus,sizeof (prstatus)); -append_kcore_note (notes, &i,CORE_STR ,NT_PRPSINFO , &prpsinfo, +append_kcore_note (notes, &i,NN_PRPSINFO ,NT_PRPSINFO , &prpsinfo,sizeof (prpsinfo)); -append_kcore_note (notes, &i,CORE_STR ,NT_TASKSTRUCT , current, +append_kcore_note (notes, &i,NN_TASKSTRUCT ,NT_TASKSTRUCT , current, arch_task_struct_size);/* * vmcoreinfo_size is mostly constant after init time, but it
include/linux/vmcore_info.h +1 -1
@@ -8,7 +8,7 @@#define CRASH_CORE_NOTE_NAME "CORE"#define CRASH_CORE_NOTE_HEAD_BYTES ALIGN(sizeof(struct elf_note), 4) -#define CRASH_CORE_NOTE_NAME_BYTES ALIGN(sizeof(CRASH_CORE_NOTE_NAME), 4) +#define CRASH_CORE_NOTE_NAME_BYTES ALIGN(sizeof(NN_PRSTATUS), 4)#define CRASH_CORE_NOTE_DESC_BYTES ALIGN(sizeof(struct elf_prstatus), 4)/*
kernel/crash_core.c +1 -1
@@ -436,7 +436,7 @@ void crash_save_cpu(struct pt_regs *regs, int cpu)memset (&prstatus,0 ,sizeof (prstatus)); prstatus.common.pr_pid = current->pid;elf_core_copy_regs (&prstatus.pr_reg, regs); - buf =append_elf_note (buf,KEXEC_CORE_NOTE_NAME ,NT_PRSTATUS , + buf =append_elf_note (buf,NN_PRSTATUS ,NT_PRSTATUS , &prstatus,sizeof (prstatus));final_note (buf); }
Signature · 1 line
2.47.1
PATCH v5 5/6 s390/crash: Use note name macros
In reply to Akihiko OdakiUse note name macros to match with the userspace's expectation.
--- arch/s390/kernel/crash_dump.c | 62 ++++++++++++++++--------------------------- 1 file changed, 23 insertions(+), 39 deletions(-)
arch/s390/kernel/crash_dump.c +23 -39
@@ -248,15 +248,6 @@ bool is_kdump_kernel(void) }EXPORT_SYMBOL_GPL (is_kdump_kernel); -static const char *nt_name (Elf64_Word type) -{ -const char *name ="LINUX" ; - -if (type ==NT_PRPSINFO || type ==NT_PRSTATUS || type ==NT_PRFPREG ) - name =KEXEC_CORE_NOTE_NAME ; -return name; -} -/* * Initialize ELF note */
@@ -281,10 +272,8 @@ static void *nt_init_name(void *buf, Elf64_Word type, void *desc, int d_len,return PTR_ADD (buf, len); } -static inline void *nt_init (void *buf,Elf64_Word type,void *desc,int d_len) -{ -return nt_init_name (buf, type, desc, d_len,nt_name (type)); -} +#define nt_init (buf, type, desc) \ + nt_init_name(buf, NT_ ## type, &(desc), sizeof(desc), NN_ ## type)/* * Calculate the size of ELF note
@@ -300,10 +289,7 @@ static size_t nt_size_name(int d_len, const char *name)return size; } -static inline size_t nt_size (Elf64_Word type,int d_len) -{ -return nt_size_name (d_len,nt_name (type)); -} +#define nt_size (type, desc) nt_size_name(sizeof(desc), NN_ ## type)/* * Fill ELF notes for one CPU with save area registers
@@ -324,18 +310,16 @@ static void *fill_cpu_elf_notes(void *ptr, int cpu, struct save_area *sa)memcpy (&nt_fpregset.fpc, &sa->fpc,sizeof (sa->fpc));memcpy (&nt_fpregset.fprs, &sa->fprs,sizeof (sa->fprs));/* Create ELF notes for the CPU */ - ptr =nt_init (ptr,NT_PRSTATUS , &nt_prstatus,sizeof (nt_prstatus)); - ptr =nt_init (ptr,NT_PRFPREG , &nt_fpregset,sizeof (nt_fpregset)); - ptr =nt_init (ptr,NT_S390_TIMER , &sa->timer,sizeof (sa->timer)); - ptr =nt_init (ptr,NT_S390_TODCMP , &sa->todcmp,sizeof (sa->todcmp)); - ptr =nt_init (ptr,NT_S390_TODPREG , &sa->todpreg,sizeof (sa->todpreg)); - ptr =nt_init (ptr,NT_S390_CTRS , &sa->ctrs,sizeof (sa->ctrs)); - ptr =nt_init (ptr,NT_S390_PREFIX , &sa->prefix,sizeof (sa->prefix)); + ptr =nt_init (ptr,PRSTATUS , nt_prstatus); + ptr =nt_init (ptr,PRFPREG , nt_fpregset); + ptr =nt_init (ptr,S390_TIMER , sa->timer); + ptr =nt_init (ptr,S390_TODCMP , sa->todcmp); + ptr =nt_init (ptr,S390_TODPREG , sa->todpreg); + ptr =nt_init (ptr,S390_CTRS , sa->ctrs); + ptr =nt_init (ptr,S390_PREFIX , sa->prefix);if (cpu_has_vx ()) { - ptr =nt_init (ptr,NT_S390_VXRS_HIGH , - &sa->vxrs_high,sizeof (sa->vxrs_high)); - ptr =nt_init (ptr,NT_S390_VXRS_LOW , - &sa->vxrs_low,sizeof (sa->vxrs_low)); + ptr =nt_init (ptr,S390_VXRS_HIGH , sa->vxrs_high); + ptr =nt_init (ptr,S390_VXRS_LOW , sa->vxrs_low); }return ptr; }
@@ -348,16 +332,16 @@ static size_t get_cpu_elf_notes_size(void)struct save_area *sa =NULL ;size_t size; - size =nt_size (NT_PRSTATUS ,sizeof (struct elf_prstatus )); - size +=nt_size (NT_PRFPREG ,sizeof (elf_fpregset_t)); - size +=nt_size (NT_S390_TIMER ,sizeof (sa->timer)); - size +=nt_size (NT_S390_TODCMP ,sizeof (sa->todcmp)); - size +=nt_size (NT_S390_TODPREG ,sizeof (sa->todpreg)); - size +=nt_size (NT_S390_CTRS ,sizeof (sa->ctrs)); - size +=nt_size (NT_S390_PREFIX ,sizeof (sa->prefix)); + size = nt_size(PRSTATUS, struct elf_prstatus); + size +=nt_size (PRFPREG , elf_fpregset_t); + size +=nt_size (S390_TIMER , sa->timer); + size +=nt_size (S390_TODCMP , sa->todcmp); + size +=nt_size (S390_TODPREG , sa->todpreg); + size +=nt_size (S390_CTRS , sa->ctrs); + size +=nt_size (S390_PREFIX , sa->prefix);if (cpu_has_vx ()) { - size +=nt_size (NT_S390_VXRS_HIGH ,sizeof (sa->vxrs_high)); - size +=nt_size (NT_S390_VXRS_LOW ,sizeof (sa->vxrs_low)); + size +=nt_size (S390_VXRS_HIGH , sa->vxrs_high); + size +=nt_size (S390_VXRS_LOW , sa->vxrs_low); }return size;
@@ -373,7 +357,7 @@ static void *nt_prpsinfo(void *ptr)memset (&prpsinfo,0 ,sizeof (prpsinfo)); prpsinfo.pr_sname ='R' ;strcpy (prpsinfo.pr_fname,"vmlinux" ); -return nt_init (ptr,NT_PRPSINFO , &prpsinfo,sizeof (prpsinfo)); +return nt_init (ptr,PRPSINFO , prpsinfo); }/*
@@ -589,7 +573,7 @@ static size_t get_elfcorehdr_size(int phdr_count)/* PT_NOTES */ size +=sizeof (Elf64_Phdr);/* nt_prpsinfo */ - size +=nt_size (NT_PRPSINFO ,sizeof (struct elf_prpsinfo )); + size += nt_size(PRPSINFO, struct elf_prpsinfo);/* regsets */ size +=get_cpu_cnt () *get_cpu_elf_notes_size ();/* nt_vmcoreinfo */
Signature · 1 line
2.47.1
PATCH v5 6/6 crash: Remove KEXEC_CORE_NOTE_NAME
In reply to Akihiko OdakiKEXEC_CORE_NOTE_NAME is no longer used.
--- include/linux/kexec.h | 2 -- include/linux/vmcore_info.h | 1 - 2 files changed, 3 deletions(-)
include/linux/kexec.h +0 -2
@@ -68,8 +68,6 @@ extern note_buf_t __percpu *crash_notes;#define KEXEC_CRASH_MEM_ALIGN PAGE_SIZE#endif -#define KEXEC_CORE_NOTE_NAME CRASH_CORE_NOTE_NAME -/* * This structure is used to hold the arguments that are used when loading * kernel binaries.
include/linux/vmcore_info.h +0 -1
@@ -6,7 +6,6 @@#include <linux/elfcore.h> #include <linux/elf.h> -#define CRASH_CORE_NOTE_NAME "CORE"#define CRASH_CORE_NOTE_HEAD_BYTES ALIGN(sizeof(struct elf_note), 4)#define CRASH_CORE_NOTE_NAME_BYTES ALIGN(sizeof(NN_PRSTATUS), 4)#define CRASH_CORE_NOTE_DESC_BYTES ALIGN(sizeof(struct elf_prstatus), 4)
Signature · 1 line
2.47.1
Quoted 8 lines · Akihiko Odaki
elf.hhad a comment saying:Quoted 5 lines
Notes used in
ET_CORE. Architectures export some of the arch register sets using the corresponding note types via thePTRACE_GETREGSETandPTRACE_SETREGSETrequests.
The note name for these types is "LINUX", exceptNT_PRFPREGthat is named "CORE".[...]
I rebased this for changes introduced by commit 680e029fd62f ("proc/kcore: don't walk list on every read")
Applied to for-next/execve, thanks!
[1/6] elf: Define note name macros
https://git.kernel.org/kees/c/7da8e4ad4df0 [2/6] binfmt_elf: Use note name macros https://git.kernel.org/kees/c/2fc4947bbd91 [3/6] powerpc: Use note name macros https://git.kernel.org/kees/c/609c8b309156 [4/6] crash: Use note name macros https://git.kernel.org/kees/c/0de47f28ec84 [5/6] s390/crash: Use note name macros https://git.kernel.org/kees/c/d4a760fb77fd [6/6] crash: Remove KEXEC_CORE_NOTE_NAME https://git.kernel.org/kees/c/7e620b56d958
Take care,
Signature · 1 line
Kees Cook