Live data from Hacker News

Elf Hello World

cirosantilli.com

21–30 of 32 posts

Re: Elf Hello World

#21
post #3

This tutorial should be read alongside his Address Relocation answer from Stack Overflow: http://stackoverflow.com/questions/12122446/how-does-c-linki... And then you might want to skim through An Evil Copy: How the Loader Betrays You : https://www.microsoft.com/en-us/research/publication/evil-co...

That new CoRev paper is interesting. I haven't had time to read it in detail but it sounds like an intriguing case for compiler/linker buffs.

Slightly OT, there was a very fun ActionScript exploit published by Mark Dowd of IBM in 2008. I'm reminded of it because it's about memory protection vulnerabilities.

"Application-Specific Attacks: Leveraging the ActionScript Virtual Machine"

https://www.cs.utexas.edu/~shmat/courses/cs6431/dowd.pdf

Re: Elf Hello World

#22
post #13

My favourite page on ELF executables of all time: http://www.muppetlabs.com/~breadbox/software/tiny/teensy.htm... , "A Whirlwind Tutorial on Creating Really Teensy ELF Executables for Linux (or, 'Size Is Everything')"

An interesting read, thanks a lot!

Re: Elf Hello World

#23

Earlier quoted context omitted.

Thanks for the article! I'm really enjoying learning this stuff. One thing that came up which doesn't appear very clear is why `ld` continues to set the entrypoint for executables at 0x08048000 when that seems like such an arbitrary number held over from a version of Unix made decades ago. Wouldn't it be better to just get rid of that and start programs at 0x00000001? (leaving 0x0 open for NUL).

Definitely not. In rough order of importance: 1. Space for NULL should be big enough for at least a medium-sized structure, otherwise (*NULL)->field = blah will overwrite your code. 2. Because of (1), Linux (for example) doesn't even allow processes to map the first page or so of memory. 3. On many platforms the PC needs to be aligned to a word boundary.

I see. I've obviously got a lot more to learn. Thanks :)

One more question, though: how much space should be safe to leave for NULL? Is 128MB enough? Why not only as much as required?

I suppose it doesn't really matter anyway since the entry point location is virtual at this point anyway.

Re: Elf Hello World

#25
post #13

My favourite page on ELF executables of all time: http://www.muppetlabs.com/~breadbox/software/tiny/teensy.htm... , "A Whirlwind Tutorial on Creating Really Teensy ELF Executables for Linux (or, 'Size Is Everything')"

That one is awesome and inspired me to write http://www.hanshq.net/making-executables.html

Re: Elf Hello World

#27
post #13

My favourite page on ELF executables of all time: http://www.muppetlabs.com/~breadbox/software/tiny/teensy.htm... , "A Whirlwind Tutorial on Creating Really Teensy ELF Executables for Linux (or, 'Size Is Everything')"

ELF is pretty generally applicable to all NIX and NIX-like platforms, so I often refer to the Solaris Libraries and Linkers guide which has a lot of generally useful information and guidance:

https://docs.oracle.com/cd/E53394_01/html/E54813/glcfv.html#...

Re: Elf Hello World

#29

Fantastic article. I noticed a couple of TODO's around, though. Does this hint at a second installment? :)

If I need it for work at some point :-) Not in forseeable future :-( But you can send PRs or fork it: https://github.com/cirosantilli/cirosantilli.github.io/blob/...

Re: Elf Hello World

#30

Earlier quoted context omitted.

Definitely not. In rough order of importance: 1. Space for NULL should be big enough for at least a medium-sized structure, otherwise (*NULL)->field = blah will overwrite your code. 2. Because of (1), Linux (for example) doesn't even allow processes to map the first page or so of memory. 3. On many platforms the PC needs to be aligned to a word boundary.

I see. I've obviously got a lot more to learn. Thanks :) One more question, though: how much space should be safe to leave for NULL? Is 128MB enough? Why not only as much as required? I suppose it doesn't really matter anyway since the entry point location is virtual at this point anyway.

It's impossible to know how much exactly is required. (While structures are fixed size, arrays indices are not.)

Linux allows you to configure the limit at /proc/sys/vm/mmap_min_addr.

Post reply on HN