diff options
author | Mark Wielaard <mark@klomp.org> | 2020-02-08 21:40:27 +0100 |
---|---|---|
committer | Mark Wielaard <mark@klomp.org> | 2020-02-18 13:20:18 +0100 |
commit | c4600ae002c8a8738035ec5f80e818171811c9d4 (patch) | |
tree | f93a4d24c4b06aad16b00c7e7d5696c132794f1b | |
parent | f4354082ba7c9d7d7c88b69a41db34f4f8a88ab5 (diff) | |
download | elfutils-c4600ae002c8a8738035ec5f80e818171811c9d4.tar.gz |
readelf, elflint: Handle PT_GNU_PROPERTY.
binutils 2.32 ld emits a new PT_GNU_PROPERTY segment that overlaps
with the PT_NOTE segment covering the .note.gnu.property section data.
https://sourceware.org/bugzilla/show_bug.cgi?id=25511
Signed-off-by: Mark Wielaard <mark@klomp.org>
-rw-r--r-- | libebl/ChangeLog | 5 | ||||
-rw-r--r-- | libebl/eblsegmenttypename.c | 6 | ||||
-rw-r--r-- | src/ChangeLog | 4 | ||||
-rw-r--r-- | src/elflint.c | 5 | ||||
-rw-r--r-- | tests/ChangeLog | 9 | ||||
-rw-r--r-- | tests/Makefile.am | 8 | ||||
-rwxr-xr-x | tests/run-pt_gnu_prop-tests.sh | 135 | ||||
-rwxr-xr-x | tests/testfile_pt_gnu_prop.bz2 | bin | 0 -> 1593 bytes | |||
-rwxr-xr-x | tests/testfile_pt_gnu_prop32.bz2 | bin | 0 -> 1777 bytes |
9 files changed, 169 insertions, 3 deletions
diff --git a/libebl/ChangeLog b/libebl/ChangeLog index 4da7eeeb..b3287310 100644 --- a/libebl/ChangeLog +++ b/libebl/ChangeLog @@ -1,3 +1,8 @@ +2020-02-08 Mark Wielaard <mark@klomp.org> + + * eblsegmenttypename.c (ebl_segment_type_name): Handle + PT_GNU_PROPERTY. + 2019-08-29 Mark Wielaard <mark@klomp.org> * Makefile.am (noinst_LIBRARIES): Add libebl.a. diff --git a/libebl/eblsegmenttypename.c b/libebl/eblsegmenttypename.c index 14eda76e..c6bdff8a 100644 --- a/libebl/eblsegmenttypename.c +++ b/libebl/eblsegmenttypename.c @@ -56,6 +56,10 @@ ebl_segment_type_name (Ebl *ebl, int segment, char *buf, size_t len) PTYPE (TLS) }; +#ifndef PT_GNU_PROPERTY +#define PT_GNU_PROPERTY (PT_LOOS + 0x474e553) +#endif + /* Is it one of the standard segment types? */ if (segment >= PT_NULL && segment < PT_NUM) res = ptypes[segment]; @@ -65,6 +69,8 @@ ebl_segment_type_name (Ebl *ebl, int segment, char *buf, size_t len) res = "GNU_STACK"; else if (segment == PT_GNU_RELRO) res = "GNU_RELRO"; + else if (segment == PT_GNU_PROPERTY) + res = "GNU_PROPERTY"; else if (segment == PT_SUNWBSS) res = "SUNWBSS"; else if (segment == PT_SUNWSTACK) diff --git a/src/ChangeLog b/src/ChangeLog index e351318b..e11fe79a 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,7 @@ +2020-02-08 Mark Wielaard <mark@klomp.org> + + * elflint.c (check_program_header): Handle PT_GNU_PROPERTY. + 2020-02-07 Mark Wielaard <mark@klomp.org> * elflint.c (check_symtab): Check st_info isn't too big. diff --git a/src/elflint.c b/src/elflint.c index 78d485e3..480d84ba 100644 --- a/src/elflint.c +++ b/src/elflint.c @@ -4487,8 +4487,13 @@ only executables, shared objects, and core files can have program headers\n")); continue; } +#ifndef PT_GNU_PROPERTY +#define PT_GNU_PROPERTY (PT_LOOS + 0x474e553) +#endif + if (phdr->p_type >= PT_NUM && phdr->p_type != PT_GNU_EH_FRAME && phdr->p_type != PT_GNU_STACK && phdr->p_type != PT_GNU_RELRO + && phdr->p_type != PT_GNU_PROPERTY /* Check for a known machine-specific type. */ && ebl_segment_type_name (ebl, phdr->p_type, NULL, 0) == NULL) ERROR (gettext ("\ diff --git a/tests/ChangeLog b/tests/ChangeLog index 84953adb..1f55a291 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,12 @@ +2020-02-08 Mark Wielaard <mark@klomp.org> + + * run-pt_gnu_prop-tests.sh: New test. + * testfile_pt_gnu_prop.bz2: New test file. + * testfile_pt_gnu_prop32.bz2: Likewise. + * Makefile.am (TESTS): Add run-pt_gnu_prop-tests.sh + (EXTRA_DISTS): Likewise. Add testfile_pt_gnu_prop.bz2 and + testfile_pt_gnu_prop32.bz2. + 2020-02-05 Frank Ch. Eigler <fche@redhat.com> * debuginfo-tars/*: New test files from Eli Schwartz of ArchLinux. diff --git a/tests/Makefile.am b/tests/Makefile.am index 19df44b6..1db1150d 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -167,7 +167,8 @@ TESTS = run-arextract.sh run-arsymtest.sh run-ar.sh newfile test-nlist \ run-readelf-discr.sh \ run-dwelf_elf_e_machine_string.sh \ run-elfclassify.sh run-elfclassify-self.sh \ - run-disasm-riscv64.sh + run-disasm-riscv64.sh \ + run-pt_gnu_prop-tests.sh if !BIARCH export ELFUTILS_DISABLE_BIARCH = 1 @@ -473,8 +474,9 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh run-ar.sh \ debuginfod-tars/hello-debug-1-1-x86_64.pkg.tar.bz2 \ debuginfod-tars/pacman-sources/PKGBUILD \ debuginfod-tars/pacman-sources/README.md \ - debuginfod-tars/pacman-sources/hello.c - + debuginfod-tars/pacman-sources/hello.c \ + run-pt_gnu_prop-tests.sh \ + testfile_pt_gnu_prop.bz2 testfile_pt_gnu_prop32.bz2 if USE_VALGRIND diff --git a/tests/run-pt_gnu_prop-tests.sh b/tests/run-pt_gnu_prop-tests.sh new file mode 100755 index 00000000..a9a8d912 --- /dev/null +++ b/tests/run-pt_gnu_prop-tests.sh @@ -0,0 +1,135 @@ +#! /bin/sh +# Copyright (C) 2020 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 + +# On Fedora 31 with GCC 9.2.1 and binutils 2.32-31 +# echo "int main () { }" | \ +# gcc -o testfile_pt_gnu_prop \ +# -Os -fstack-clash-protection -fcf-protection=full -xc - && \ +# eu-strip --remove-comment -R .gnu.build.attributes testfile_pt_gnu_prop +# +# echo "int main () { }" | \ +# gcc -m32 -o testfile_pt_gnu_prop \ +# -Os -fstack-clash-protection -fcf-protection=full -xc - && \ +# eu-strip --remove-comment -R .gnu.build.attributes testfile_pt_gnu_prop32 + +testfiles testfile_pt_gnu_prop testfile_pt_gnu_prop32 + +testrun_compare ${abs_top_builddir}/src/readelf -ln testfile_pt_gnu_prop32 <<\EOF +Program Headers: + Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align + PHDR 0x000034 0x08048034 0x08048034 0x000180 0x000180 R 0x4 + INTERP 0x0001b4 0x080481b4 0x080481b4 0x000013 0x000013 R 0x1 + [Requesting program interpreter: /lib/ld-linux.so.2] + LOAD 0x000000 0x08048000 0x08048000 0x000308 0x000308 R 0x1000 + LOAD 0x001000 0x08049000 0x08049000 0x000224 0x000224 R E 0x1000 + LOAD 0x002000 0x0804a000 0x0804a000 0x00015c 0x00015c R 0x1000 + LOAD 0x002f0c 0x0804bf0c 0x0804bf0c 0x000108 0x00010c RW 0x1000 + DYNAMIC 0x002f14 0x0804bf14 0x0804bf14 0x0000e8 0x0000e8 RW 0x4 + NOTE 0x0001c8 0x080481c8 0x080481c8 0x000060 0x000060 R 0x4 + GNU_PROPERTY 0x0001ec 0x080481ec 0x080481ec 0x00001c 0x00001c R 0x4 + GNU_EH_FRAME 0x00200c 0x0804a00c 0x0804a00c 0x00004c 0x00004c R 0x4 + GNU_STACK 0x000000 0x00000000 0x00000000 0x000000 0x000000 RW 0x10 + GNU_RELRO 0x002f0c 0x0804bf0c 0x0804bf0c 0x0000f4 0x0000f4 R 0x1 + + Section to Segment mapping: + Segment Sections... + 00 + 01 [RO: .interp] + 02 [RO: .interp .note.gnu.build-id .note.gnu.property .note.ABI-tag .gnu.hash .dynsym .dynstr .gnu.version .gnu.version_r .rel.dyn .rel.plt] + 03 [RO: .init .plt .plt.sec .text .fini] + 04 [RO: .rodata .eh_frame_hdr .eh_frame] + 05 [RELRO: .init_array .fini_array .dynamic .got] .got.plt .data .bss + 06 [RELRO: .dynamic] + 07 [RO: .note.gnu.build-id .note.gnu.property .note.ABI-tag] + 08 [RO: .note.gnu.property] + 09 [RO: .eh_frame_hdr] + 10 + 11 [RELRO: .init_array .fini_array .dynamic .got] + +Note section [ 2] '.note.gnu.build-id' of 36 bytes at offset 0x1c8: + Owner Data size Type + GNU 20 GNU_BUILD_ID + Build ID: 2fcce91f5c2532f78b00a9f5f565354d2f44bc19 + +Note section [ 3] '.note.gnu.property' of 28 bytes at offset 0x1ec: + Owner Data size Type + GNU 12 GNU_PROPERTY_TYPE_0 + X86 FEATURE_1_AND: 00000003 IBT SHSTK + +Note section [ 4] '.note.ABI-tag' of 32 bytes at offset 0x208: + Owner Data size Type + GNU 16 GNU_ABI_TAG + OS: Linux, ABI: 3.2.0 +EOF + +testrun ${abs_top_builddir}/src/elflint --gnu testfile_pt_gnu_prop32 + +testrun_compare ${abs_top_builddir}/src/readelf -ln testfile_pt_gnu_prop <<\EOF +Program Headers: + Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align + PHDR 0x000040 0x0000000000400040 0x0000000000400040 0x0002d8 0x0002d8 R 0x8 + INTERP 0x000318 0x0000000000400318 0x0000000000400318 0x00001c 0x00001c R 0x1 + [Requesting program interpreter: /lib64/ld-linux-x86-64.so.2] + LOAD 0x000000 0x0000000000400000 0x0000000000400000 0x000498 0x000498 R 0x1000 + LOAD 0x001000 0x0000000000401000 0x0000000000401000 0x0001a5 0x0001a5 R E 0x1000 + LOAD 0x002000 0x0000000000402000 0x0000000000402000 0x000100 0x000100 R 0x1000 + LOAD 0x002e50 0x0000000000403e50 0x0000000000403e50 0x0001cc 0x0001d0 RW 0x1000 + DYNAMIC 0x002e60 0x0000000000403e60 0x0000000000403e60 0x000190 0x000190 RW 0x8 + NOTE 0x000338 0x0000000000400338 0x0000000000400338 0x000020 0x000020 R 0x8 + NOTE 0x000358 0x0000000000400358 0x0000000000400358 0x000044 0x000044 R 0x4 + GNU_PROPERTY 0x000338 0x0000000000400338 0x0000000000400338 0x000020 0x000020 R 0x8 + GNU_EH_FRAME 0x002010 0x0000000000402010 0x0000000000402010 0x000034 0x000034 R 0x4 + GNU_STACK 0x000000 0x0000000000000000 0x0000000000000000 0x000000 0x000000 RW 0x10 + GNU_RELRO 0x002e50 0x0000000000403e50 0x0000000000403e50 0x0001b0 0x0001b0 R 0x1 + + Section to Segment mapping: + Segment Sections... + 00 + 01 [RO: .interp] + 02 [RO: .interp .note.gnu.property .note.gnu.build-id .note.ABI-tag .gnu.hash .dynsym .dynstr .gnu.version .gnu.version_r .rela.dyn] + 03 [RO: .init .text .fini] + 04 [RO: .rodata .eh_frame_hdr .eh_frame] + 05 [RELRO: .init_array .fini_array .dynamic .got] .got.plt .data .bss + 06 [RELRO: .dynamic] + 07 [RO: .note.gnu.property] + 08 [RO: .note.gnu.build-id .note.ABI-tag] + 09 [RO: .note.gnu.property] + 10 [RO: .eh_frame_hdr] + 11 + 12 [RELRO: .init_array .fini_array .dynamic .got] + +Note section [ 2] '.note.gnu.property' of 32 bytes at offset 0x338: + Owner Data size Type + GNU 16 GNU_PROPERTY_TYPE_0 + X86 FEATURE_1_AND: 00000003 IBT SHSTK + +Note section [ 3] '.note.gnu.build-id' of 36 bytes at offset 0x358: + Owner Data size Type + GNU 20 GNU_BUILD_ID + Build ID: 84fa4d40bad074bc82431575821902da624a5b22 + +Note section [ 4] '.note.ABI-tag' of 32 bytes at offset 0x37c: + Owner Data size Type + GNU 16 GNU_ABI_TAG + OS: Linux, ABI: 3.2.0 +EOF + +testrun ${abs_top_builddir}/src/elflint --gnu testfile_pt_gnu_prop + +exit 0 diff --git a/tests/testfile_pt_gnu_prop.bz2 b/tests/testfile_pt_gnu_prop.bz2 Binary files differnew file mode 100755 index 00000000..f030fb9c --- /dev/null +++ b/tests/testfile_pt_gnu_prop.bz2 diff --git a/tests/testfile_pt_gnu_prop32.bz2 b/tests/testfile_pt_gnu_prop32.bz2 Binary files differnew file mode 100755 index 00000000..6a7515a6 --- /dev/null +++ b/tests/testfile_pt_gnu_prop32.bz2 |