Commit Graph

536 Commits

Author SHA1 Message Date
Jörg Thalheim
c62988a2a8 Merge pull request #312 from NixOS/github
Automatic release tarball upload
2021-08-28 12:32:59 +01:00
Jörg Thalheim
a5f569acfa github: update install-nix-action 2021-08-28 13:30:26 +02:00
Jörg Thalheim
12c790e25c publish tarballs with github workflow 2021-08-28 13:28:47 +02:00
Jörg Thalheim
7db9e2039a ci: remove obsolete option 2021-08-28 13:28:47 +02:00
Jörg Thalheim
3170add8a9 Merge pull request #309 from NixOS/ubsan
add undefined behavior sanitizer
2021-08-28 12:15:10 +01:00
Jörg Thalheim
385f6b1bff cleanup duplicate sanitizer flags 2021-08-28 06:25:40 +02:00
Jörg Thalheim
07dfd67eb1 Merge pull request #307 from Mic92/coverage
increase test coverage
2021-08-28 05:11:09 +01:00
Jörg Thalheim
c388c5d67a Merge pull request #306 from Mic92/aarch64
fix aarch64 build
2021-08-26 14:03:17 +01:00
Jörg Thalheim
6ecfae69f9 gitignore: add check binary 2021-08-26 07:23:36 +02:00
Jörg Thalheim
c8d3af95d4 add sanitizer build to CI 2021-08-26 07:23:36 +02:00
Jörg Thalheim
a9f5397ee1 add ubsan option 2021-08-26 07:09:35 +02:00
slekky
3113c73598 Typo (#308)
Clarifying sentence
2021-08-25 23:02:55 +01:00
Jörg Thalheim
51ecac17c2 add flag tests
let's start with the easy targets from coverage reports
2021-08-25 21:43:41 +00:00
Jörg Thalheim
893e2988c7 fix aarch64 build
also fix evaluation of nix develop on aarch64.

See https://hydra.nixos.org/eval/1698785#tabs-still-fail
for details.
2021-08-25 21:22:11 +00:00
Jörg Thalheim
38cb5c8e0d Merge pull request #304 from NixOS/nobits
Don't try to parse .dynamic section of type NOBITS + test
2021-08-23 20:12:47 +01:00
Jörg Thalheim
a4e4924fe1 Merge pull request #302 from NixOS/use-after-free
fix use-after-free in normalizeNoteSegments
2021-08-23 19:58:56 +01:00
Michal Sojka
64fe89b6b2 Don't try to parse .dynamic section of type NOBITS
Otherwise, patchelf segfaults when it encounters DT_NEEDED in the read
garbage. Corresponding backtrace is:

    #0  0x00007ffff7c275f7 in __strlen_avx2 () from /nix/store/cvr0kjg2q7z2wwhjblx6c73rv422k8cm-glibc-2.33-47/lib/libc.so.6
    #1  0x00007ffff7f2d448 in std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&) () from /nix/store/lg104nh0szci8slz5z6494m457jm5y3p-gcc-10.3.0-lib/lib/libstdc++.so.6
    #2  0x000000000040fe0f in ElfFile<Elf64_Ehdr, Elf64_Phdr, Elf64_Shdr, unsigned long, unsigned long, Elf64_Dyn, Elf64_Sym, Elf64_Verneed, unsigned short>::modifyRPath (this=0x7fffffffbaa0,
        op=ElfFile<Elf64_Ehdr, Elf64_Phdr, Elf64_Shdr, unsigned long, unsigned long, Elf64_Dyn, Elf64_Sym, Elf64_Verneed, unsigned short>::rpPrint, allowedRpathPrefixes=std::vector of length 0, capacity 0, newRPath="") at patchelf.cc:1351
    #3  0x00000000004061c3 in patchElf2<ElfFile<Elf64_Ehdr, Elf64_Phdr, Elf64_Shdr, unsigned long, unsigned long, Elf64_Dyn, Elf64_Sym, Elf64_Verneed, unsigned short> > (elfFile=..., fileContents=std::shared_ptr<std::vector<unsigned char, std::allocator<unsigned char> >> (use count 3, weak count 0) = {...},
        fileName="libsystemd.debug") at patchelf.cc:1805
    #4  0x0000000000404774 in patchElf () at patchelf.cc:1848
    #5  0x000000000040551c in mainWrapped (argc=3, argv=0x7fffffffc148) at patchelf.cc:2003
    #6  0x0000000000405913 in main (argc=3, argv=0x7fffffffc148) at patchelf.cc:2011

NOBIT sections are included in the section headers table but occupy no
actual space in the file. .dynamic sections of this types are created,
for example, by `strip --only-keep-debug`.

I'm not sure whether calling error() would be more appropriate than
ignoring this situation with debug/return. I chose ignoring it,
because error() caused autoPatchelfHook to fail with my package. Also
the rest of modifyRPath method simply calls debug/return in similar
situations.
2021-08-23 20:57:47 +02:00
Jörg Thalheim
a71334dc2e add failing test for .dynamic == NOBITS 2021-08-23 20:57:47 +02:00
Jörg Thalheim
bf62fda4ec fix use-after-free in normalizeNoteSegments 2021-08-21 09:43:23 +02:00
Jörg Thalheim
83864998bd Merge pull request #300 from NixOS/eintr
handle EINTR correctly on write
2021-08-19 14:06:01 +01:00
Eelco Dolstra
d6c7c90742 Merge pull request #301 from NixOS/strcpy
use memcpy instead of strcpy to set rpath
2021-08-18 09:28:52 +02:00
Jörg Thalheim
671f0cff51 fix use-after-free in normalizeNoteSegments 2021-08-18 09:11:27 +02:00
Jörg Thalheim
3fc63c945c use memcpy instead of strcpy to set rpath
Since we already no the size, this is faster.
2021-08-18 08:29:14 +02:00
Jörg Thalheim
51626341b6 correct EINTR handling in writeFile 2021-08-18 08:16:49 +02:00
Jörg Thalheim
10cd631cce fixup PACKAGE_STRING macro
it was introduced in b9dcf5b705
but contained a stray \
2021-08-18 08:16:26 +02:00
Jörg Thalheim
0121f5ebad Merge pull request #180 from iv-m/mips-fixes
Fixes for MIPS binaries
2021-08-11 16:00:49 +01:00
Ivan A. Melnikov
bf73d6ea39 Adjust PT_MIPS_ABIFLAGS segment if present
When loading the executable on MIPS, the dynamic loader looks for MIPS
ABI flags using PT_MIPS_ABIFLAGS header. The flags themselves are stored
in the .MIPS.abiflags section, so the header must be updated when the
section is moved.

Here we also import PT_MIPS_ABIFLAGS definition from glibc commit
0bd956720c457ff054325b48f26ac7c91cb060e8.

Closes: #82
Signed-off-by: Ivan A. Melnikov <iv@altlinux.org>
2021-08-11 17:50:04 +04:00
Ivan A. Melnikov
b240bb8dcf Adjust DT_MIPS_RLD_MAP_REL dynamic section entry if present
`patchelf --set-rpath` corrupted executables on mips32el: the dynamic
liker crushed with Segmentation fault when loading any executable with
RPATH added that way.

The problem was around the MIPS-specific mechanism of setting up the
debug map pointer. When DT_MIPS_RLD_MAP_REL entry in the dynamic section
is present, it holds the relative address of __RLD_MAP -- an offset
relative to this dynamic section entry. Dynamic linker puts the
pointer to the `r_debug` structure there.

When patchelf updates the executable RPATH, it moves the .dynamic
section both in the binary and in memory, while __RLD_MAP is not moved
in memory, since it belongs to special .rld_map section that has type
PROGBITS. So, the offset stored in DT_MIPS_RLD_MAP_REL entry is not
valid anymore and should be updated.

This commit adds the necessary update.

In the corner case when DT_MIPS_RLD_MAP_REL is present, but
.rld_map section is not, the dynamic loader writes the debug
pointer to some arbitrary bytes in memory. To avoid crushes
on otherwise "working" binaries, we set offset to zero
so that the dynamic loader would just overwrite the dynamic
section.

Here we also import DT_MIPS_RLD_MAP_REL definition in elf.h form
glibc commit a2057c984e4314c3740f04cf54e36c824e4c8f32.

Refs: #82
Signed-off-by: Ivan A. Melnikov <iv@altlinux.org>
2021-08-11 17:49:41 +04:00
Jörg Thalheim
374c92ad4e Merge pull request #299 from NixOS/package-string
define default PACKAGE_STRING
2021-08-10 19:53:16 +01:00
Jörg Thalheim
b9dcf5b705 define default PACKAGE_STRING
This allows to build patchelf without build system.
Fixes https://github.com/NixOS/patchelf/pull/114 and https://github.com/NixOS/patchelf/issues/102
2021-08-10 20:48:56 +02:00
Eelco Dolstra
6965ad38df Merge pull request #298 from NixOS/cleanups
Cleanups
2021-08-10 15:21:12 +02:00
Jörg Thalheim
2982586b7c release: autoreconfHook
This is needed when building in `nix develop`
and it is also useful to rebuild autotools
when building a package.
2021-08-10 14:36:25 +02:00
Jörg Thalheim
989d0ba4dd gitignore: add all test binaries 2021-08-10 14:36:25 +02:00
Jörg Thalheim
9e364e5fca tests/contiguous-note-sections: rename for consistency 2021-08-10 14:36:25 +02:00
Jörg Thalheim
59d529fe3c Merge pull request #297 from Mic92/nixpkgs-bump
bump nixpkgs to 21.05
2021-08-10 12:58:40 +01:00
Jörg Thalheim
818710e576 fix typo in pr template 2021-08-10 13:57:18 +02:00
Jörg Thalheim
b2e28ea898 bump nixpkgs to 21.05 2021-08-10 13:56:11 +02:00
Jörg Thalheim
2f88e6f312 Merge pull request #296 from Mic92/gnu-hash
fix binaries without .gnu.hash section
2021-08-10 11:57:19 +01:00
Domen Kožar
943f8242b3 Merge pull request #295 from ius/elf-section-type
tests/contiguous_note_sections.s: use alternate section type prefix
2021-08-10 09:34:39 +02:00
Jörg Thalheim
57fe1d3835 fix binaries without .gnu.hash section 2021-08-10 07:54:50 +02:00
Joerie de Gram
094022f06c tests/contiguous_note_sections.s: use alternate section type prefix
fixes #294
2021-08-09 19:16:47 +02:00
Domen Kožar
5d6f086b3d Merge pull request #241 from pablogsal/multiple
Handle libraries with more than one .shstrtab section
2021-08-05 18:02:09 +02:00
Domen Kožar
eed0a903c5 Merge branch 'master' into multiple 2021-08-05 17:59:01 +02:00
Eelco Dolstra
a949ff2331 Bump version 0.13 2021-08-05 14:39:43 +02:00
Domen Kožar
dab44118d7 Merge pull request #246 from xavierabellan/add-rpath
Added option --add-rpath
2021-08-05 12:10:59 +02:00
Domen Kožar
4ee62cbd52 Merge pull request #269 from telent/endianness-fix-for-shrink-rpath
convert endian when checking library machine type
2021-08-05 12:03:48 +02:00
Domen Kožar
4e1b46a334 fix tests DIST 2021-08-05 12:03:39 +02:00
Domen Kožar
a71fa6b341 Merge pull request #290 from ius/endianness-fix
tests: add e_machine endianness test (#269)
2021-08-05 11:56:04 +02:00
Domen Kožar
f823fa3143 Merge branch 'master' into endianness-fix 2021-08-05 11:55:53 +02:00
Domen Kožar
add92c1fe7 Merge pull request #235 from emlix/cleanups
minor improvements
2021-08-04 15:45:27 +02:00