LD_PRELOAD work in progress

Martin Pitt martin.pitt at ubuntu.com
Wed Feb 25 06:19:49 UTC 2015

Steve Langasek [2015-02-24 15:50 -0800]:
> Now, I guess for this case you only need to intercept those calls which take
> a filename as an argument, in order to remap to a different name.  It's
> *possible* that LD_PRELOAD interposition is supported for all libc calls
> that take a filename.  But you'll probably need to verify this carefully
> before going down this road.

fakechroot (in particular, libfakechroot) does pretty much that, and
it works reasonably well. I do the same in umockdev for faking /sys
and /dev (and a few others, like syscalls).

However, you have to be very careful to really catch all the gazillion
variants like lstat64(), __open_64_2() and similar. Also, this
requires that the application actually uses libc; I've seen a few
cases where applications do a syscall directly, and as Steve already
said there is no way to intercept that with a preload lib.

This probably also sucks quite a bit performance wise; that isn't an
issue with tests (fakechroot/umockdev), but might be an issue with
actual products.

The LD_PRELOAD approach breaks with set[ug]id programs, as they prune
that environment (for obvious reasons).

Martin Pitt                        | http://www.piware.de
Ubuntu Developer (www.ubuntu.com)  | Debian Developer  (www.debian.org)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <https://lists.ubuntu.com/archives/snappy-devel/attachments/20150225/7b4a3a44/attachment.pgp>

More information about the snappy-devel mailing list