Required ELF segments
Johannes Bauer
dfnsonfsduifb@gmx.de
Sat May 9 20:20:05 GMT 2020
Hi list,
I'm trying to broaden my knowledge of internal workings of the loader
and ELF binaries and get myself in a spot where I can manipulate ELF
files. I've created a small tool that can parse/read ELF binaries and
that tool then tries to put them back together (unmodified for now). In
my understanding, sections are entirely optional for running an ELF, so
I'm not bothering with them right now and just put the segments in the
target file.
However, I have several points that I do not understand yet or that
confuse me:
1. Why is the segment table itself a segment? That seems redundant,
since it's already refernced from the ELF header. Is it required as a
segment at all? Does it need to point to the same file offset as the
segment table that's referenced by the ELF header? What is the purpose
of this?
2. Why is the whole ELF file mapped as a segment at all? If my
understanding is correct, then there should be only the need to map a
single segment which could be RWX and another one for the interpreter
reference. Security concerns aside (no-execute and read/write of RO
data), what's the minimum number of segments required to be able to
properly execute under Linux?
3. How can you debug the loader? My new ELF binary segfaults even before
it is run and I have no clue on how to effectively debug this. I've
tried to just copy /bin/true on a x86_64 binary. If you're curious,
here's my butchered binary:
curl https://pastebin.com/raw/jFL34wFA | openssl base64 -d | gunzip
>true_segfault
Thanks in advance for your patience,
All the best,
Johannes
More information about the Binutils
mailing list