patchelf
patchelf copied to clipboard
Assertion failed on x86_64 Jamestown binary: patchelf.cc:382: void checkPointer(
When I set the interpreter of the (non-public) Jamestown amd64 binary:
$ patchelf --set-interpreter /gnu/store/ahqgl4h89xqj695lgqvsaf6zh2nhy4pj-glibc-2.29/lib/ld-linux-x86-64.so.2 data/Jamestown-amd64
patchelf: patchelf.cc:382: void checkPointer(const FileContents&, void*, unsigned int): Assertion `q >= contents->data() && q + size <= contents->data() + contents->size()' failed.
It works on the x86 binary. I'm not sure what else to report beside this:
$ file Jamestown-amd64
Jamestown-amd64: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, stripped
This is the game: https://en.wikipedia.org/wiki/Jamestown_(video_game)
I'd kind ask to try with master, a bunch of things have been fixed.
In order for someone to be able to help we'd need a way to reproduce the issue.
Sorry, I get the same error (at patchelf.cc:384 this time).
Commit dadb65f97ec043c41faff35612f7672f40d12a77.
Could you attach the binary here?
I don't think it's legal to do this publicly. I can send it to you over email or whatever means you prefer.
Understood - it's going to be hard to reproduce and this issue without that.
If anyone wants to work on this, please contact me and I'll send them the binary in private.
I guess the output of readelf -lS /gnu/store/ahqgl4h89xqj695lgqvsaf6zh2nhy4pj-glibc-2.29/lib/ld-linux-x86-64.so.2 data/Jamestown-amd64 could give a hint about what is in the headers that is causing trouble.
Here you are:
$ readelf -lS /gnu/store/1y7g7kj3zxg2p90g692wybqh9b6gv7q2-glibc-2.31/lib/ld-linux-x86-64.so.2 Jamestown-amd64
File: /gnu/store/1y7g7kj3zxg2p90g692wybqh9b6gv7q2-glibc-2.31/lib/ld-linux-x86-64.so.2
There are 26 section headers, starting at offset 0x2e780:
Section Headers:
[Nr] Name Type Address Offset
Size EntSize Flags Link Info Align
[ 0] NULL 0000000000000000 00000000
0000000000000000 0000000000000000 0 0 0
[ 1] .hash HASH 0000000000000200 00000200
00000000000000d4 0000000000000004 A 3 0 8
[ 2] .gnu.hash GNU_HASH 00000000000002d8 000002d8
00000000000000f8 0000000000000000 A 3 0 8
[ 3] .dynsym DYNSYM 00000000000003d0 000003d0
0000000000000330 0000000000000018 A 4 1 8
[ 4] .dynstr STRTAB 0000000000000700 00000700
0000000000000224 0000000000000000 A 0 0 1
[ 5] .gnu.version VERSYM 0000000000000924 00000924
0000000000000044 0000000000000002 A 3 0 2
[ 6] .gnu.version_d VERDEF 0000000000000968 00000968
00000000000000a4 0000000000000000 A 4 5 8
[ 7] .rela.dyn RELA 0000000000000a10 00000a10
0000000000000420 0000000000000018 A 3 0 8
[ 8] .rela.plt RELA 0000000000000e30 00000e30
00000000000000a8 0000000000000018 AI 3 18 8
[ 9] .plt PROGBITS 0000000000001000 00001000
0000000000000080 0000000000000010 AX 0 0 16
[10] .plt.got PROGBITS 0000000000001080 00001080
0000000000000008 0000000000000008 AX 0 0 8
[11] .text PROGBITS 0000000000001090 00001090
000000000001e010 0000000000000000 AX 0 0 16
[12] .rodata PROGBITS 0000000000020000 00020000
0000000000004b7b 0000000000000000 A 0 0 32
[13] .eh_frame_hdr PROGBITS 0000000000024b7c 00024b7c
00000000000006fc 0000000000000000 A 0 0 4
[14] .eh_frame PROGBITS 0000000000025278 00025278
00000000000027a4 0000000000000000 A 0 0 8
[15] .data.rel.ro PROGBITS 0000000000029520 00028520
0000000000000944 0000000000000000 WA 0 0 32
[16] .dynamic DYNAMIC 0000000000029e68 00028e68
0000000000000170 0000000000000010 WA 4 0 8
[17] .got PROGBITS 0000000000029fd8 00028fd8
0000000000000010 0000000000000008 WA 0 0 8
[18] .got.plt PROGBITS 000000000002a000 00029000
0000000000000050 0000000000000008 WA 0 0 8
[19] .data PROGBITS 000000000002a060 00029060
0000000000000f98 0000000000000000 WA 0 0 32
[20] .bss NOBITS 000000000002b000 00029ff8
0000000000000170 0000000000000000 WA 0 0 32
[21] .comment PROGBITS 0000000000000000 00029ff8
0000000000000011 0000000000000001 MS 0 0 1
[22] .gnu_debuglink PROGBITS 0000000000000000 0002a00c
0000000000000018 0000000000000000 0 0 4
[23] .symtab SYMTAB 0000000000000000 0002a028
0000000000002d00 0000000000000018 24 447 8
[24] .strtab STRTAB 0000000000000000 0002cd28
000000000000197c 0000000000000000 0 0 1
[25] .shstrtab STRTAB 0000000000000000 0002e6a4
00000000000000d6 0000000000000000 0 0 1
Key to Flags:
W (write), A (alloc), X (execute), M (merge), S (strings), I (info),
L (link order), O (extra OS processing required), G (group), T (TLS),
C (compressed), x (unknown), o (OS specific), E (exclude),
l (large), p (processor specific)
Elf file type is DYN (Shared object file)
Entry point 0x1340
There are 8 program headers, starting at offset 64
Program Headers:
Type Offset VirtAddr PhysAddr
FileSiz MemSiz Flags Align
LOAD 0x0000000000000000 0x0000000000000000 0x0000000000000000
0x0000000000000ed8 0x0000000000000ed8 R 0x1000
LOAD 0x0000000000001000 0x0000000000001000 0x0000000000001000
0x000000000001e0a0 0x000000000001e0a0 R E 0x1000
LOAD 0x0000000000020000 0x0000000000020000 0x0000000000020000
0x0000000000007a1c 0x0000000000007a1c R 0x1000
LOAD 0x0000000000028520 0x0000000000029520 0x0000000000029520
0x0000000000001ad8 0x0000000000001c50 RW 0x1000
DYNAMIC 0x0000000000028e68 0x0000000000029e68 0x0000000000029e68
0x0000000000000170 0x0000000000000170 RW 0x8
GNU_EH_FRAME 0x0000000000024b7c 0x0000000000024b7c 0x0000000000024b7c
0x00000000000006fc 0x00000000000006fc R 0x4
GNU_STACK 0x0000000000000000 0x0000000000000000 0x0000000000000000
0x0000000000000000 0x0000000000000000 RW 0x10
GNU_RELRO 0x0000000000028520 0x0000000000029520 0x0000000000029520
0x0000000000000ae0 0x0000000000000ae0 R 0x1
Section to Segment mapping:
Segment Sections...
00 .hash .gnu.hash .dynsym .dynstr .gnu.version .gnu.version_d .rela.dyn .rela.plt
01 .plt .plt.got .text
02 .rodata .eh_frame_hdr .eh_frame
03 .data.rel.ro .dynamic .got .got.plt .data .bss
04 .dynamic
05 .eh_frame_hdr
06
07 .data.rel.ro .dynamic .got
File: Jamestown-amd64
There are 32 section headers, starting at offset 0x917ed8:
readelf: Error: Reading 103079215104 bytes extends past end of file for string table
Section Headers:
[Nr] Name Type Address Offset
Size EntSize Flags Link Info Align
readelf: Warning: [ 0]: Unexpected value (35) in info field.
[ 0] <no-strings> 00000238: <unkn 0000000000000000 100000000
0000000000000000 0040025400000000 xxx 0 35 8589934599
readelf: Warning: [ 1]: Unexpected value (49) in info field.
[ 1] <no-strings> 00000254: <unkn 0000000000000000 400000000
0000000000000000 0040027400000000 x 0 49 8589934599
readelf: Warning: [ 2]: Unexpected value (68) in info field.
[ 2] <no-strings> 00000274: <unkn 0000000000000000 400000000
0000000000000000 0040029800000000 xx 0 68 10468982774
readelf: Warning: [ 3]: Unexpected value (78) in info field.
[ 3] <no-strings> 00000298: <unkn 0000000500000000 800000000
0000000000000000 0042440000000000 xxxxxx 0 78 8589934603
readelf: Warning: [ 4]: Unexpected value (86) in info field.
readelf: Warning: Size of section 4 is larger than the entire file!
[ 4] <no-strings> 00024400: <unkn 0000000600000000 800000001
0000001800000000 004867e800000000 xxxxxxxxx 0 86 8589934595
readelf: Warning: [ 5]: Unexpected value (94) in info field.
[ 5] <no-strings> 000867e8: <unkn 0000000000000000 100000000
0000000000000000 00596bd400000000 xxxxxxxxxx 0 94 10468982783
readelf: Warning: [ 6]: Unexpected value (107) in info field.
readelf: Warning: Size of section 6 is larger than the entire file!
[ 6] <no-strings> 00196bd4: <unkn 0000000500000000 200000000
0000000200000000 0059eed800000000 xxxxxxxxx 0 107 10468982782
readelf: Warning: [ 7]: Unexpected value (122) in info field.
[ 7] <no-strings> 0019eed8: <unkn 0000000600000000 800000006
0000000000000000 0059f01800000000 xx 0 122 8589934596
readelf: Warning: [ 8]: Unexpected value (132) in info field.
readelf: Warning: Size of section 8 is larger than the entire file!
[ 8] <no-strings> 0019f018: <unkn 0000000500000000 800000000
0000001800000000 0059f22800000000 xx 0 132 8589934596
readelf: Warning: [ 9]: Unexpected value (142) in info field.
readelf: Warning: Size of section 9 is larger than the entire file!
[ 9] <no-strings> 0019f228: <unkn 0000000500000000 80000000c
0000001800000000 005a111800000000 xxxxxxxx 0 142 25769803777
readelf: Warning: [10]: Unexpected value (137) in info field.
[10] <no-strings> 001a1118: <unkn 0000000000000000 400000000
0000000000000000 005a113000000000 xx 0 137 25769803777
readelf: Warning: [11]: Unexpected value (148) in info field.
readelf: Warning: Size of section 11 is larger than the entire file!
[11] <no-strings> 001a1130: <unkn 0000000000000000 1000000000
0000001000000000 005a25e000000000 xxxxx 0 148 25769803777
readelf: Warning: [12]: Unexpected value (154) in info field.
[12] <no-strings> 001a25e0: <unkn 0000000000000000 1000000000
0000000000000000 00bafb9800000000 xxxxxxxxxxx 0 154 25769803777
readelf: Warning: [13]: Unexpected value (160) in info field.
[13] <no-strings> 007afb98: <unkn 0000000000000000 400000000
0000000000000000 00bafbc000000000 xxx 0 160 8589934593
readelf: Warning: [14]: Unexpected value (168) in info field.
[14] <no-strings> 007afbc0: <unkn 0000000000000000 2000000000
0000000000000000 00bf0adc00000000 xxxxxxxx 0 168 8589934593
readelf: Warning: [15]: Unexpected value (182) in info field.
[15] <no-strings> 007f0adc: <unkn 0000000000000000 400000000
0000000000000000 00c082a800000000 xxxxxxxxxxx 0 182 8589934593
readelf: Warning: [16]: Unexpected value (192) in info field.
[16] <no-strings> 008082a8: <unkn 0000000000000000 800000000
0000000000000000 00c89af400000000 xxxxxx 0 192 8589934593
readelf: Warning: [17]: Unexpected value (210) in info field.
[17] <no-strings> 00889af4: <unkn 0000000000000000 400000000
0000000000000000 00f159f800000000 xxxxxxxx 0 210 12884901902
readelf: Warning: [18]: Unexpected value (222) in info field.
[18] <no-strings> 009159f8: <unkn 0000000000000000 800000000
0000000000000000 00f15d7800000000 xxx 0 222 12884901889
readelf: Warning: [19]: Unexpected value (229) in info field.
[19] <no-strings> 00915d78: <unkn 0000000000000000 800000000
0000000000000000 00f15d8800000000 x 0 229 12884901889
readelf: Warning: [20]: Unexpected value (236) in info field.
[20] <no-strings> 00915d88: <unkn 0000000000000000 800000000
0000000000000000 00f15d9800000000 x 0 236 12884901889
readelf: Warning: [21]: Unexpected value (241) in info field.
[21] <no-strings> 00915d98: <unkn 0000000000000000 800000000
0000000000000000 00f15da000000000 x 0 241 12884901894
readelf: Warning: [22]: Unexpected value (250) in info field.
readelf: Warning: Size of section 22 is larger than the entire file!
[22] <no-strings> 00915da0: <unkn 0000000600000000 800000000
0000001000000000 00f15fe000000000 xx 0 250 12884901889
readelf: Warning: [23]: Unexpected value (255) in info field.
readelf: Warning: Size of section 23 is larger than the entire file!
[23] <no-strings> 00915fe0: <unkn 0000000000000000 800000000
0000000800000000 00f15fe800000000 x 0 255 12884901889
readelf: Warning: [24]: Unexpected value (264) in info field.
readelf: Warning: Size of section 24 is larger than the entire file!
[24] <no-strings> 00915fe8: <unkn 0000000000000000 800000000
0000000800000000 00f16a6000000000 xxxxx 0 264 12884901889
readelf: Warning: [25]: Unexpected value (270) in info field.
[25] <no-strings> 00916a60: <unkn 0000000000000000 2000000000
0000000000000000 00f17d8000000000 xxxx 0 270 12884901896
readelf: Warning: [26]: Unexpected value (275) in info field.
[26] <no-strings> 00917d64: <unkn 0000000000000000 2000000000
0000000000000000 0000000000000000 xxxxx 0 275 206158430209
readelf: Warning: [27]: Unexpected value (17) in info field.
readelf: Warning: Size of section 27 is larger than the entire file!
[27] <no-strings> 00917d64: <unkn 0000000000000000 100000000
0000000100000000 0000000000000000 xxx 0 17 3
readelf: Warning: [28]: Unexpected value (1) in info field.
[28] <no-strings> 00917db8: <unkn 0000000000000000 100000000
0000000000000000 0000000000000000 xxxx 0 1 2
readelf: Warning: [29]: Unexpected value (9) in info field.
readelf: Warning: Size of section 29 is larger than the entire file!
[29] <no-strings> 009186d8: <unkn 0000001f00000000 800000ac4
0000001800000000 0000000000000000 xxxxxxxx 0 9 3
[30] <no-strings> 0098ad08: <unkn 0000000000000000 100000000
0000000000000000 0000000000000000 xxxxxxxxxxxx 0 0 0
[31] <no-strings> NULL 0000000000000000 00000000
0040025400020003 0040027400030003 WAxxxxxx 0 0 0
Key to Flags:
W (write), A (alloc), X (execute), M (merge), S (strings), I (info),
L (link order), O (extra OS processing required), G (group), T (TLS),
C (compressed), x (unknown), o (OS specific), E (exclude),
l (large), p (processor specific)
Elf file type is EXEC (Executable file)
Entry point 0x5a55d8
There are 9 program headers, starting at offset 64
Program Headers:
Type Offset VirtAddr PhysAddr
FileSiz MemSiz Flags Align
PHDR 0x0000000000000040 0x0000000000400040 0x0000000000400040
0x00000000000001f8 0x00000000000001f8 R E 0x8
INTERP 0x0000000000000238 0x0000000000400238 0x0000000000400238
0x000000000000001c 0x000000000000001c R 0x1
[Requesting program interpreter: /lib64/ld-linux-x86-64.so.2]
LOAD 0x0000000000000000 0x0000000000400000 0x0000000000400000
0x0000000000914c80 0x0000000000914c80 R E 0x200000
LOAD 0x00000000009159f8 0x0000000000f159f8 0x0000000000f159f8
0x000000000000236c 0x000000000000ebd0 RW 0x200000
DYNAMIC 0x0000000000915da0 0x0000000000f15da0 0x0000000000f15da0
0x0000000000000240 0x0000000000000240 RW 0x8
readelf: Error: no .dynamic section in the dynamic segment
NOTE 0x0000000000000254 0x0000000000400254 0x0000000000400254
0x0000000000000044 0x0000000000000044 R 0x4
GNU_EH_FRAME 0x00000000007f0adc 0x0000000000bf0adc 0x0000000000bf0adc
0x00000000000177cc 0x00000000000177cc R 0x4
GNU_STACK 0x0000000000000000 0x0000000000000000 0x0000000000000000
0x0000000000000000 0x0000000000000000 RW 0x8
GNU_RELRO 0x00000000009159f8 0x0000000000f159f8 0x0000000000f159f8
0x0000000000000608 0x0000000000000608 R 0x1
Even readelf has problems opening the latter file. Can you please also run readelf -h on it, it looks like there is something strange in the ELF header that misdirects the tools. Is that some sort of universal fat binary or so?
$ readelf -h Jamestown-amd64
ELF Header:
Magic: 7f 45 4c 46 02 01 01 03 00 00 00 00 00 00 00 00
Class: ELF64
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - GNU
ABI Version: 0
Type: EXEC (Executable file)
Machine: Advanced Micro Devices X86-64
Version: 0x1
Entry point address: 0x5a55d8
Start of program headers: 64 (bytes into file)
Start of section headers: 9535192 (bytes into file)
Flags: 0x0
Size of this header: 64 (bytes)
Size of program headers: 56 (bytes)
Number of program headers: 9
Size of section headers: 64 (bytes)
Number of section headers: 32
Section header string table index: 29
readelf: Error: Reading 103079215104 bytes extends past end of file for string table
readelf: Error: no .dynamic section in the dynamic segment
Is that some sort of universal fat binary or so?
I don't know what a universal fat binary is. Can you guide me here?
It's a video game distributed by Humble Bundle.
Whatever actually is in the section header table confuses also readelf, so I guess it's somehow broken. Maybe someone has an idea when we can look at the actual table data. All numbers are taken from the above output:
dd if=Jamestown-amd64 skip=9535192 bs=1 count=$((64*32)) | hexdump -C