From c4600ae002c8a8738035ec5f80e818171811c9d4 Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Sat, 8 Feb 2020 21:40:27 +0100 Subject: [PATCH] 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 --- libebl/ChangeLog | 5 ++ libebl/eblsegmenttypename.c | 6 ++ src/ChangeLog | 4 + src/elflint.c | 5 ++ tests/ChangeLog | 9 +++ tests/Makefile.am | 8 +- tests/run-pt_gnu_prop-tests.sh | 135 +++++++++++++++++++++++++++++++ tests/testfile_pt_gnu_prop.bz2 | Bin 0 -> 1593 bytes tests/testfile_pt_gnu_prop32.bz2 | Bin 0 -> 1777 bytes 9 files changed, 169 insertions(+), 3 deletions(-) create mode 100755 tests/run-pt_gnu_prop-tests.sh create mode 100755 tests/testfile_pt_gnu_prop.bz2 create mode 100755 tests/testfile_pt_gnu_prop32.bz2 diff --git a/libebl/ChangeLog b/libebl/ChangeLog index 4da7eeebe..b32873104 100644 --- a/libebl/ChangeLog +++ b/libebl/ChangeLog @@ -1,3 +1,8 @@ +2020-02-08 Mark Wielaard + + * eblsegmenttypename.c (ebl_segment_type_name): Handle + PT_GNU_PROPERTY. + 2019-08-29 Mark Wielaard * Makefile.am (noinst_LIBRARIES): Add libebl.a. diff --git a/libebl/eblsegmenttypename.c b/libebl/eblsegmenttypename.c index 14eda76e1..c6bdff8a5 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 e351318bf..e11fe79a5 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,7 @@ +2020-02-08 Mark Wielaard + + * elflint.c (check_program_header): Handle PT_GNU_PROPERTY. + 2020-02-07 Mark Wielaard * elflint.c (check_symtab): Check st_info isn't too big. diff --git a/src/elflint.c b/src/elflint.c index 78d485e32..480d84ba9 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 84953adb2..1f55a2914 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,12 @@ +2020-02-08 Mark Wielaard + + * 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 * debuginfo-tars/*: New test files from Eli Schwartz of ArchLinux. diff --git a/tests/Makefile.am b/tests/Makefile.am index 19df44b6e..1db1150df 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 000000000..a9a8d912f --- /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 . + +. $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 index 0000000000000000000000000000000000000000..f030fb9cc3950243e4393102a7644682a8bb5eb1 GIT binary patch literal 1593 zc-jFu2FCe9T4*^jL0KkKS@emkhX4iw|NsC0|9{-;_iO+6f6xEt|8)O9*g$3>#8>^q zWm?w%|6kAq{$dRQNwyZItQwjGOr}$MCX*U!9;fJ$rkOn;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bz2 b/tests/testfile_pt_gnu_prop32.bz2 new file mode 100755 index 0000000000000000000000000000000000000000..6a7515a6b34f87984602a680be289af559faa624 GIT binary patch literal 1777 zc-jH+1`hc`T4*^jL0KkKS;j3G3jhT`|NsC0{{7#7_iO+E|Ih#L-+cf6bP7bWZ*>3V zcw|2A@BPpPwF|(hNlmGmnW15(h(a_Z+6sQBr8lZJ(rploLqjzNn^Qw&G-Mh!pn680 zpwmaF8UQrjnx=*(k5Kh8Jw~6Y217tSBVwM28kr+a5H!@nVl^~oNCA zrh`BL0000q&>8`d000^TKn)N88U}%rKn($*iKa}3fEoY*&=?TWiIXN12r>ge(?*R9 zOpJig216hO00x1eWY7aZXkuxTA)p3;05k>!G-71Qgu)Df&@|DbLlYw)Gy#yv07#I6 ziRqG_r-d~257jhe0Mpa}(X{|*&;SEZC=D_J>IRwtqiSdXGynhtKn8LwA2oY19yDoj$c-Vz%%qZ<8p-ZJ>%0}b!oR6Yr4yn@ zE&V(WE>$3yq+`)k07V3X0RTyWxTYi8NT8Z# zZQQ3}nmHHd+GNlWf|{SPQA~{F*PDroYyjKw6;x?AW|d9T2_!Ovvt46ZcAyYDHB;(! z5)!T#b7;IXt&>t}+>fT$c1sLGzfyYNw6m7 z(GIc6g;v2P7nq1+VMel=B+F`KD3qijux%?ES*~nYY=(^1D_AxP#-`PcC}<|gW=jza z0ZpJGmm(3I;ezPe0}`kJMq5G_6B1KsxY7(}vndEaRG5Fie#O^F~XV`ADg1TbtitVdqZdMrzya$yiA-8$m6bt7)VVF-iX zvBJB2%$`4^naYw!v%Gmyhp?e#U18+5p_19*%$B4f1WDrOzgO44vbT<2(R2vP-d{DL z7?#S2C>GLObM}}9C^l~H5unz+$+oZ}8-uKZ)(c!k-q)4J)3+i~re@=~ECfte2kd)^ z5kX9F%X5rGG#>R4t48Sxh%3Y(t^q_!3YJBi^;V?aA;==&8YcSHKyz(Prqwaw1e!*z zqSVqF33U)eoFFu9Al(KnV8uy5c?}nn6xwBNXEa}z8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