summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMark Wielaard <mark@klomp.org>2018-10-15 23:35:47 +0200
committerMark Wielaard <mark@klomp.org>2018-10-29 00:57:57 +0100
commit5199e15870e05e5b0b9f98c20fc9b5427aa6dd6a (patch)
tree300abbc40ba85162eabf061393f9f5c0cff9b9b2 /src
parentb75ff1bbd060404565fa28d72441a9b02f331bae (diff)
Recognize and parse GNU Property notes.
GNU Property notes are different from normal notes because they use variable alignment/padding of their fields. They are 8 byte aligned, but use 4 byte fields. The name is aligned at 4 bytes and padded so that, the desc is aligned at 8 bytes. The whole note is padded to 8 bytes again. For normal notes all fields are both 4 bytes wide and 4 bytes aligned. To recognize these new kind of ELF Notes a new Elf_Type is introduced, ELF_T_NHDR8. This type is used in the xlate functions to determine how to align and pad the various fields. Since the fields themselves can now have different alignments we will have to keep track of the current alignement and use either NOTE_ALIGN4 or NOTE_ALIGN8 to determine the padding. To set the correct Elf_Type on the Elf_Data we use either the section sh_addralign or the segment p_align values. Assuming 8 means the section or segment contains the new style notes, otherwise normal notes. When we cannot determine the "alignment" directly, like when parsing special kernel sys files, we check the name "GNU" and type "GNU_PROPERTY_TYPE_0" fields. ebl_object_note now parses the new NT_GNU_PROPERTY_TYPE_0 and can extract the GNU_PROPERTY_STACK_SIZE, GNU_PROPERTY_NO_COPY_ON_PROTECTED and GNU_PROPERTY_X86_FEATURE_1_AND types GNU_PROPERTY_X86_FEATURE_1_IBT and GNU_PROPERTY_X86_FEATURE_1_SHSTK. Tests are added for extracting the note from sections or segments as set by gcc -fcf-protection. Signed-off-by: Mark Wielaard <mark@klomp.org>
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog7
-rw-r--r--src/elflint.c4
-rw-r--r--src/readelf.c3
3 files changed, 12 insertions, 2 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 5061cc11..758534de 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,10 @@
+2018-10-18 Mark Wielaard <mark@klomp.org>
+
+ * elflint.c (check_note_data): Recognize NT_GNU_PROPERTY_TYPE_0.
+ (check_note): Use p_align to pass either ELF_T_NHDR or ELF_T_NHDR8 to
+ elf_getdata_rawchunk.
+ * readelf (handle_notes): Likewise.
+
2018-10-24 Mark Wielaard <mark@klomp.org>
* addr2line.c (print_addrsym): Use elf_getshdrstrndx instead of
diff --git a/src/elflint.c b/src/elflint.c
index 3d445954..fa3af4c5 100644
--- a/src/elflint.c
+++ b/src/elflint.c
@@ -4331,6 +4331,7 @@ section [%2d] '%s': unknown core file note type %" PRIu32
case NT_GNU_HWCAP:
case NT_GNU_BUILD_ID:
case NT_GNU_GOLD_VERSION:
+ case NT_GNU_PROPERTY_TYPE_0:
break;
case 0:
@@ -4376,7 +4377,8 @@ phdr[%d]: no note entries defined for the type of file\n"),
GElf_Off notes_size = 0;
Elf_Data *data = elf_getdata_rawchunk (ebl->elf,
phdr->p_offset, phdr->p_filesz,
- ELF_T_NHDR);
+ (phdr->p_align == 8
+ ? ELF_T_NHDR8 : ELF_T_NHDR));
if (data != NULL && data->d_buf != NULL)
notes_size = check_note_data (ebl, ehdr, data, 0, cnt, phdr->p_offset);
diff --git a/src/readelf.c b/src/readelf.c
index 72ae04ec..ccd07eb7 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -12300,7 +12300,8 @@ handle_notes (Ebl *ebl, GElf_Ehdr *ehdr)
handle_notes_data (ebl, ehdr, phdr->p_offset,
elf_getdata_rawchunk (ebl->elf,
phdr->p_offset, phdr->p_filesz,
- ELF_T_NHDR));
+ (phdr->p_align == 8
+ ? ELF_T_NHDR8 : ELF_T_NHDR)));
}
}