Repository navigation
Description
I'm running patchelf --set-rpath on the executable from a stock apt package, influxdb version 1.5.3, and it puts the executable into a broken state: it segfaults on startup.
Running it in gdb, I discovered that ld-linux.so is trying to write to a location in the .dynamic section (specifically the DEBUG entry in that section), which is located at 0x400300. The memory exists and was mapped in by ld-linux.so and is perfectly readable.
The problem seems to be that the memory was mapped as read-only (using mmap with the argument PROT_READ|PROT_EXEC, as shown by strace). Now, the reason for that seems to be that the ELF program headers have a LOAD segment that encompasses the .dynamic section (and a lot else), and that segment is marked "read and execute" (but not write). The original binary (and indeed, the transformed one) have another LOAD segment that starts where the .dynamic section starts, and which is read-write. So, I believe that patchelf chose to relocate the .dynamic section from inside a read-write LOAD segment into a read-only one, which would seem to be invalid.
I don't know the algorithms of patchelf well enough to attempt a fix.
Attached are the relevant readelf outputs from before and after the change. You can see that the original has in its sections:
[16] .dynamic DYNAMIC 00000000012bf000 00ebf000
0000000000000130 0000000000000010 WA 10 0 8
and then in its segments:
LOAD 0x0000000000000000 0x0000000000400000 0x0000000000400000
0x0000000000814d60 0x0000000000814d60 R E 1000
LOAD 0x0000000000ebf000 0x00000000012bf000 0x00000000012bf000
0x000000000005b620 0x0000000000081538 RW 1000
But the patched one has in its sections
[ 1] .dynamic DYNAMIC 0000000000400270 00000270
0000000000000140 0000000000000010 WA 2 0 8
and then in its segments
LOAD 0x0000000000000000 0x0000000000400000 0x0000000000400000
0x0000000000814d60 0x0000000000814d60 R E 1000
LOAD 0x0000000000ebf000 0x00000000012bf000 0x00000000012bf000
0x000000000005b620 0x0000000000081538 RW 1000
influxd-rpath.readelf.txt
influxd.readelf.txt
Please help!
Activity
am813nt commentedon Aug 2, 2018
@ezquat Can you please give more info about the binary: where to get it, OS, what desired rpath should be etc?
ezquat commentedon Aug 2, 2018
Yes, the binary is
influxdfrom the influxdb Ubuntu package (version 1.5.3): https://packages.ubuntu.com/xenial/influxdbA crucial fact is that influxdb is written in Go, and the Go linker has produced some other unusual ELF layouts.
In my case, my desired rpath was, I think,
$ORIGIN/../lib. It's possible that that matters inasfar as its length might force patchelf to relocate sections. If you have any trouble reproing, let me know, I'll see if I can bring back any more details. Thanks!ezquat commentedon Aug 2, 2018
I think this is a duplicate of #146.
mwhudson commentedon Aug 5, 2018
Yes, this looks like exactly the same bug I reported.
domenkozar commentedon Jun 9, 2020
Duplicate of #146
godot: fix export-bin-runs with prebuilt templates
[ABLD-525] Point Bazel-built FIPS Go binaries to the embedded OpenSSL (…