]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
readelf, elflint: Handle PT_GNU_PROPERTY.
authorMark Wielaard <mark@klomp.org>
Sat, 8 Feb 2020 20:40:27 +0000 (21:40 +0100)
committerMark Wielaard <mark@klomp.org>
Tue, 18 Feb 2020 12:20:18 +0000 (13:20 +0100)
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>
libebl/ChangeLog
libebl/eblsegmenttypename.c
src/ChangeLog
src/elflint.c
tests/ChangeLog
tests/Makefile.am
tests/run-pt_gnu_prop-tests.sh [new file with mode: 0755]
tests/testfile_pt_gnu_prop.bz2 [new file with mode: 0755]
tests/testfile_pt_gnu_prop32.bz2 [new file with mode: 0755]

index 4da7eeebedefd62291fab3d847b9d00902562c05..b328731043c39c1c71197a80b23c68321baf4fc5 100644 (file)
@@ -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.
index 14eda76e16c715f21318c19c2c95eb266b5a6e7e..c6bdff8a5b661bb46f3a6d9af937b9d4cc046c11 100644 (file)
@@ -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)
index e351318bf9d8a19e2fa8af57c3a65aab0f8e3760..e11fe79a53d8c0e5708eb6a2059502cb10910a1f 100644 (file)
@@ -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.
index 78d485e32d431a151f5633419bbfc2fa78bb6b80..480d84ba9dc4e099241730cf5145fd616e1e7113 100644 (file)
@@ -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 ("\
index 84953adb279883568551bff4fc8cae90827e7744..1f55a2914a346e052f96257ded8d99da593dc591 100644 (file)
@@ -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.
index 19df44b6e78314203540ec234f573a70ed2b9c4a..1db1150df5a2bb737417343c08956e82161a4e2f 100644 (file)
@@ -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 (executable)
index 0000000..a9a8d91
--- /dev/null
@@ -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
new file mode 100755 (executable)
index 0000000..f030fb9
Binary files /dev/null and b/tests/testfile_pt_gnu_prop.bz2 differ
diff --git a/tests/testfile_pt_gnu_prop32.bz2 b/tests/testfile_pt_gnu_prop32.bz2
new file mode 100755 (executable)
index 0000000..6a7515a
Binary files /dev/null and b/tests/testfile_pt_gnu_prop32.bz2 differ