diff options
| author | Mark Wielaard <[email protected]> | 2018-10-15 23:35:47 +0200 |
|---|---|---|
| committer | Mark Wielaard <[email protected]> | 2018-10-29 00:57:57 +0100 |
| commit | 5199e15870e05e5b0b9f98c20fc9b5427aa6dd6a (patch) | |
| tree | 300abbc40ba85162eabf061393f9f5c0cff9b9b2 /tests | |
| parent | b75ff1bbd060404565fa28d72441a9b02f331bae (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 <[email protected]>
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/ChangeLog | 9 | ||||
| -rw-r--r-- | tests/Makefile.am | 3 | ||||
| -rwxr-xr-x | tests/run-readelf-n.sh | 55 | ||||
| -rwxr-xr-x | tests/testfile-gnu-property-note.bz2 | bin | 0 -> 1146 bytes | |||
| -rw-r--r-- | tests/testfile-gnu-property-note.o.bz2 | bin | 0 -> 482 bytes |
5 files changed, 67 insertions, 0 deletions
diff --git a/tests/ChangeLog b/tests/ChangeLog index 751a0810..d5a06563 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,12 @@ +2018-10-18 Mark Wielaard <[email protected]> + + * run-readelf-n.sh: New test. + * testfile-gnu-property-note.bz2: New testfile. + * testfile-gnu-property-note.o.bz2: Likewise. + * Makefile.am (TESTS): Add run-readelf-n.sh. + (EXTRA_DIST): Likewise and testfile-gnu-property-note.bz2, + testfile-gnu-property-note.o.bz2. + 2018-10-12 Mark Wielaard <[email protected]> * run-readelf-zdebug.sh: Adjust flags output. diff --git a/tests/Makefile.am b/tests/Makefile.am index 15b429b7..a2a381ac 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -106,6 +106,7 @@ TESTS = run-arextract.sh run-arsymtest.sh run-ar.sh newfile test-nlist \ run-readelf-test4.sh run-readelf-twofiles.sh \ run-readelf-macro.sh run-readelf-loc.sh run-readelf-ranges.sh \ run-readelf-aranges.sh run-readelf-line.sh run-readelf-z.sh \ + run-readelf-n.sh \ run-native-test.sh run-bug1-test.sh \ run-debuglink.sh run-debugaltlink.sh run-buildid.sh \ dwfl-bug-addr-overflow run-addrname-test.sh \ @@ -272,6 +273,8 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh run-ar.sh \ testfile-dwzstr.bz2 testfile-dwzstr.multi.bz2 \ run-readelf-addr.sh run-readelf-str.sh \ run-readelf-types.sh \ + run-readelf-n.sh \ + testfile-gnu-property-note.bz2 testfile-gnu-property-note.o.bz2 \ run-allfcts-multi.sh \ test-offset-loop.bz2 test-offset-loop.alt.bz2 \ run-prelink-addr-test.sh \ diff --git a/tests/run-readelf-n.sh b/tests/run-readelf-n.sh new file mode 100755 index 00000000..3ae7cf02 --- /dev/null +++ b/tests/run-readelf-n.sh @@ -0,0 +1,55 @@ +# Copyright (C) 2018 Red Hat, Inc. +# This file is part of elfutils. +# +# This file is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# elfutils is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +. $srcdir/test-subr.sh + +# - testfile-gnu-property-note.c +# int +# main () +# { +# return 0; +# } +# +# gcc -fcf-protection -c testfile-gnu-property-note.c +# gcc -o testfile-gnu-property-note testfile-gnu-property-note.o +# eu-strip --strip-sections testfile-gnu-property-note + +testfiles testfile-gnu-property-note.o testfile-gnu-property-note + +# Test reading notes through sections +testrun_compare ${abs_top_builddir}/src/readelf -n testfile-gnu-property-note.o << EOF + +Note section [ 6] '.note.gnu.property' of 32 bytes at offset 0x80: + Owner Data size Type + GNU 16 GNU_PROPERTY_TYPE_0 + X86 FEATURE_1_AND: 00000003 IBT SHSTK +EOF + +# Test reading notes through segments +testrun_compare ${abs_top_builddir}/src/readelf -n testfile-gnu-property-note << EOF + +Note segment of 32 bytes at offset 0x300: + Owner Data size Type + GNU 16 GNU_PROPERTY_TYPE_0 + X86 FEATURE_1_AND: 00000003 IBT SHSTK + +Note segment of 68 bytes at offset 0x320: + Owner Data size Type + GNU 16 VERSION + OS: Linux, ABI: 3.2.0 + GNU 20 GNU_BUILD_ID + Build ID: 83cb2229fabd2065d1361f5b46424cd75270f94b +EOF diff --git a/tests/testfile-gnu-property-note.bz2 b/tests/testfile-gnu-property-note.bz2 Binary files differnew file mode 100755 index 00000000..c03bd9bb --- /dev/null +++ b/tests/testfile-gnu-property-note.bz2 diff --git a/tests/testfile-gnu-property-note.o.bz2 b/tests/testfile-gnu-property-note.o.bz2 Binary files differnew file mode 100644 index 00000000..5147c64f --- /dev/null +++ b/tests/testfile-gnu-property-note.o.bz2 |
