makedumpfile, elf: distinguish ELF note types by ELF note names
Subsystems (2)
cover makedumpfile, elf: distinguish ELF note types by ELF note names
In ELF, the same integers for two note type represent different meanings if the names they belong to are different. However, get_pt_note_info() doesn't distinguish note types by name space, due to which, for example, any new note type in "VMCOREINFO" name space is wrongly interpretted as NT_PRSTATUS or the unique note type in "VMCOREINFO" name space.
This patch series makes get_pt_note_info() distinguish ELF note types by ELF note names along with cleanups related to this change.
For reference:
Note Section
http://www.sco.com/developers/gabi/latest/ch5.pheader.html#note_section
type
This word gives the interpretation of the descriptor. Each originator controls its own types; multiple interpretations of a single type value may exist. Thus, a program must recognize both the name and the type to recognize a descriptor. Types currently must be non-negative. The ABI does not define what descriptors mean.
---
HATAYAMA Daisuke (3):
elf: distinguish ELF note types by ELF note name space
elf: swap checking order of VMCOREINFO and VMCOREINFO_XEN elf, sadump: move KEXEC macros from sadump_info.c to elf_info.h
elf_info.c | 83 ++++++++++++++++++++++++++++++++++++++------------------- elf_info.h | 3 ++ sadump_info.c | 4 +-- 3 files changed, 59 insertions(+), 31 deletions(-)
Signature · 7 lines
Thanks. HATAYAMA, Daisuke _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
PATCH 1/3 elf, sadump: move KEXEC macros from sadump_info.c to elf_info.h
Move KEXEC_CORE_NOTE_NAME and KEXEC_CORE_NOTE_NAME_BYTES in elf_info.h to export them in elf_info.c. Later patch refers to them when reading PT_NOTE program header entries.
During this change, round-up operations are dropped to make it uniform to other macros such as VMCOREINFO_NOTE_NAME that is similarly exported from elf_info.h.
Instead, the roundup-operations dropped are moved into KEXEC_NOTE_BYTES.
---
elf_info.h | 3 +++ sadump_info.c | 4 +--- 2 files changed, 4 insertions(+), 3 deletions(-)
elf_info.h +3 -0
@@ -19,6 +19,9 @@#include <elf.h> #include <sys/types.h> +#define KEXEC_CORE_NOTE_NAME "CORE" +#define KEXEC_CORE_NOTE_NAME_BYTES sizeof(KEXEC_CORE_NOTE_NAME) +#define ERASEINFO_NOTE_NAME "ERASEINFO"#define ERASEINFO_NOTE_NAME_BYTES (sizeof(ERASEINFO_NOTE_NAME))
sadump_info.c +1 -3
@@ -37,12 +37,10 @@#endif -#define KEXEC_CORE_NOTE_NAME "CORE" -#define KEXEC_CORE_NOTE_NAME_BYTES roundup(sizeof(KEXEC_CORE_NOTE_NAME), 4)#define KEXEC_CORE_NOTE_DESC_BYTES roundup(sizeof(struct elf_prstatus), 4)#define KEXEC_NOTE_BYTES ((KEXEC_NOTE_HEAD_BYTES * 2) + \ - KEXEC_CORE_NOTE_NAME_BYTES + \ + roundup(KEXEC_CORE_NOTE_NAME_BYTES, 4) + \ KEXEC_CORE_NOTE_DESC_BYTES )#define for_each_online_cpu (cpu) \
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
PATCH 2/3 elf: swap checking order of VMCOREINFO and VMCOREINFO_XEN
In reply to HATAYAMA DaisukeCurrently, get_pt_note_info() checks ELF note in "VMCOREINFO_XEN" name first and then in "VMCOREINFO" name to avoid the case where "VMCOREINFO_XEN" is wrongly interpreted as "VMCOREINFO". However, characters checked by strncmp() includes null character. The case concerned about there can never happen. This patch swaps checking order of VMCOREINFO and VMCOREINFO_XEN, which is natural in the sense that the direction from general one to specific one is natural.
---
elf_info.c | 13 ++++--------- 1 files changed, 4 insertions(+), 9 deletions(-)
elf_info.c +4 -9
@@ -323,22 +323,17 @@ get_pt_note_info(void) offset_desc = offset +offset_note_desc (note); size_desc =note_descsz (note); +if (!strncmp (VMCOREINFO_NOTE_NAME , buf, +VMCOREINFO_NOTE_NAME_BYTES )) { +set_vmcoreinfo (offset_desc, size_desc);/* * Check whether /proc/vmcore contains vmcoreinfo, * and get both the offset and the size. -* -* NOTE: The owner name of xen should be checked at first, -* because its name is "VMCOREINFO_XEN" and the one -* of linux is "VMCOREINFO". */ -if (!strncmp (VMCOREINFO_XEN_NOTE_NAME , buf, + }else if (!strncmp (VMCOREINFO_XEN_NOTE_NAME , buf,VMCOREINFO_XEN_NOTE_NAME_BYTES )) { offset_vmcoreinfo_xen = offset_desc; size_vmcoreinfo_xen = size_desc; - }else if (!strncmp (VMCOREINFO_NOTE_NAME , buf, -VMCOREINFO_NOTE_NAME_BYTES )) { -set_vmcoreinfo (offset_desc, size_desc); -/* * Check whether /proc/vmcore contains xen's note. */
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
PATCH 3/3 elf: distinguish ELF note types by ELF note name space
In reply to HATAYAMA DaisukeIn ELF, the same integers for two note type represent different meanings if the names they belong to are different. However, get_pt_note_info() doesn't distinguish note types by name space, due to which, for example, any new note type in "VMCOREINFO" name space is wrongly interpretted as NT_PRSTATUS or the unique note type in "VMCOREINFO" name space. This patch checks first ELF note names explicitly and then ELF note types.
---
elf_info.c | 76 +++++++++++++++++++++++++++++++++++++++++++----------------- 1 files changed, 54 insertions(+), 22 deletions(-)
elf_info.c +54 -22
@@ -254,6 +254,23 @@ note_type(void *note) }static int +note_namesz (void *note) +{ +int size; +Elf64_Nhdr *note64; +Elf32_Nhdr *note32; + +if (is_elf64_memory ()) { + note64 = (Elf64_Nhdr *)note; + size = note64->n_namesz; + }else { + note32 = (Elf32_Nhdr *)note; + size = note32->n_namesz; + } +return size; +} + +static int note_descsz (void *note) {int size;
@@ -290,7 +307,7 @@ offset_note_desc(void *note)static int get_pt_note_info (void ) { -int n_type, size_desc; +int n_type, size_name, size_desc;off_t offset, offset_desc;char buf[VMCOREINFO_XEN_NOTE_NAME_BYTES ];char note[MAX_SIZE_NHDR ];
@@ -308,40 +325,51 @@ get_pt_note_info(void) name_memory, strerror(errno));return FALSE; } + + n_type =note_type (note); + size_name =note_namesz (note); + size_desc =note_descsz (note); + offset_desc = offset +offset_note_desc (note); + +if (!size_name || size_name >=sizeof (buf)) + goto next_note; +if (read (fd_memory, &buf,sizeof (buf)) !=sizeof (buf)) {ERRMSG ("Can't read the dump memory(%s). %s\n" , name_memory,strerror (errno));return FALSE; } - n_type =note_type (note); -if (n_type ==NT_PRSTATUS ) { - nr_cpus++; - offset +=offset_next_note (note); -continue ; - } - offset_desc = offset +offset_note_desc (note); - size_desc =note_descsz (note); +if (!strncmp (KEXEC_CORE_NOTE_NAME , buf, +KEXEC_CORE_NOTE_NAME_BYTES )) { +if (n_type ==NT_PRSTATUS ) { + nr_cpus++; + } -if (!strncmp (VMCOREINFO_NOTE_NAME , buf, -VMCOREINFO_NOTE_NAME_BYTES )) { -set_vmcoreinfo (offset_desc, size_desc); + }else if (!strncmp (VMCOREINFO_NOTE_NAME , buf, +VMCOREINFO_NOTE_NAME_BYTES )) { +if (n_type ==0 ) { +set_vmcoreinfo (offset_desc, size_desc); + }/* * Check whether /proc/vmcore contains vmcoreinfo, * and get both the offset and the size. */ }else if (!strncmp (VMCOREINFO_XEN_NOTE_NAME , buf, -VMCOREINFO_XEN_NOTE_NAME_BYTES )) { - offset_vmcoreinfo_xen = offset_desc; - size_vmcoreinfo_xen = size_desc; +VMCOREINFO_XEN_NOTE_NAME_BYTES )) { +if (n_type ==0 ) { + offset_vmcoreinfo_xen = offset_desc; + size_vmcoreinfo_xen = size_desc; + }/* * Check whether /proc/vmcore contains xen's note. */ - }else if (n_type ==XEN_ELFNOTE_CRASH_INFO ) { - flags_memory |=MEMORY_XEN ; - offset_xen_crash_info = offset_desc; - size_xen_crash_info = size_desc; - + }else if (!strncmp ("Xen" , buf,4 )) { +if (n_type ==XEN_ELFNOTE_CRASH_INFO ) { + flags_memory |=MEMORY_XEN ; + offset_xen_crash_info = offset_desc; + size_xen_crash_info = size_desc; + }/* * Check whether a source dumpfile contains eraseinfo. * /proc/vmcore does not contain eraseinfo, because eraseinfo
@@ -349,9 +377,13 @@ get_pt_note_info(void)* create /proc/vmcore. */ }else if (!strncmp (ERASEINFO_NOTE_NAME , buf, -ERASEINFO_NOTE_NAME_BYTES )) { -set_eraseinfo (offset_desc, size_desc); +ERASEINFO_NOTE_NAME_BYTES )) { +if (n_type ==0 ) { +set_eraseinfo (offset_desc, size_desc); + } } + + next_note: offset +=offset_next_note (note); }if (is_xen_memory ())
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Hello HATAYAMA-san,
Quoted 9 lines · On Mon, 04 Mar 2013 13:18:24 +0900 HATAYAMA Daisuke…
In ELF, the same integers for two note type represent different meanings if the names they belong to are different. However,
get_pt_note_info()doesn't distinguish note types by name space, due to which, for example, any new note type in "VMCOREINFO" name space is wrongly interpretted asNT_PRSTATUSor the unique note type in "VMCOREINFO" name space.This patch series makes
get_pt_note_info()distinguish ELF note types by ELF note names along with cleanups related to this change.
Reviewed and applied.
Thanks
Atsushi Kumagai.
Quoted 23 lines
For reference:
Note Section
http://www.sco.com/developers/gabi/latest/ch5.pheader.html#note_sectiontype
This word gives the interpretation of the descriptor. Each originator controls its own types; multiple interpretations of a single type value may exist. Thus, a program must recognize both the name and the type to recognize a descriptor. Types currently must be non-negative. The ABI does not define what descriptors mean.
---
HATAYAMA Daisuke (3):
elf: distinguish ELF note types by ELF note name space
elf: swap checking order of VMCOREINFO andVMCOREINFO_XENelf, sadump: move KEXEC macros fromsadump_info.ctoelf_info.h
Quoted 14 lines
elf_info.c | 83 ++++++++++++++++++++++++++++++++++++++------------------- elf_info.h | 3 ++ sadump_info.c | 4 +-- 3 files changed, 59 insertions(+), 31 deletions(-)Signature · 7 lines
Thanks. HATAYAMA, Daisuke _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec