2

I need a C library which lets me exec() a statically linked binary, without invoking the execve() system call. The reason why the system call wouldn't work is that the binary file is not executable, and it's not possible to make it executable on that system. For dynamically linked binaries, running /lib/ld-linux.so.2 progname does the trick, but that segfaults on my statically linked binary.

I've found ul_exec 1.1 on http://archive.cert.uni-stuttgart.de/bugtraq/2004/01/msg00002.html , but that seems to segfault for its own Hello, World binary on my system.

One option would be to make a copy of the binary, make the copy executable, and call execve(). I'm looking for a solution which doesn't need such a copy (because of performance reasons).

pts
  • 80,836
  • 20
  • 110
  • 183
  • 1
    could you explain why it's not possible to make it executable? without more knowledge it's hard to answer. – jcomeau_ictx Nov 20 '10 at 23:21
  • 1
    It's irrelevant why it is not possible to make the file executable. In this question I'm looking for a library which can run a statically linked ELF binary without calling `execve()` -- no matter if the binary file can be made executable. I'm not interested in alternative solutions for the higher level problem. – pts Nov 21 '10 at 00:58

3 Answers3

4

I've updated The Grugq's userland exec to work with modern x86 Linuxes. I wrote an x86_64 userland exec from scratch.

1

then how about a usermode filesystem (using python-fuse for example) that maps the execute bit to any file specified? would that be too much of a performance hit?

jcomeau_ictx
  • 37,688
  • 6
  • 92
  • 107
  • Yes, that should be faster than copying the file. But my original question remains unanswered: I need a library that emulates execve() with open() + ELF header parsing + mmap(). – pts Nov 21 '10 at 00:55
-1

There is a good short wiki article with some not-completely-production-ready implementations: http://plash.beasts.org/wiki/UserModeExec

pts
  • 80,836
  • 20
  • 110
  • 183
  • 1
    link is broken. archive.org doesn't archive it. This is why StackOverflow wants people to post self-contained answers .. Seriously! – bazz Oct 15 '14 at 01:02