Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Mon, 6 Jul 2015 22:00:41 +0300 (MSK)
From: Alexander Monakov <amonakov@...ras.ru>
To: musl@...ts.openwall.com
Subject: Re: Making a shared library that intercepts call to main work
 with musl compiled binary

On Mon, 6 Jul 2015, Rich Felker wrote:
> On Mon, Jul 06, 2015 at 01:00:52PM -0400, Riyad Parvez wrote:
> > Hi All,
> > 
> > I've shared library [1] which intercepts loading of a binary and does some
> > pre-processing with the command-line arguments via "LD_PRELOAD" technique.
> > The shared library works fine with glibc compiled binary i.e., it can
> > intercept the call to main and does some preprocessing. But it can't
> > intercept call to "main" in musl-compiled binary. I've compiled my binary
> > in static mode with musl "CC=/musl-gcc -static". How can I make the shared
> > library work with musl-compiled binary?
> > 
> > Thanks
> > Riyad
> > 
> > [1]: https://github.com/dslab-epfl/s2e/blob/master/guest/init_env/init_env.c
> 
> I haven't read this code in detail, so I don't have any advice on
> whether there are other problems, but the basic issue seems to be that
> you're static linking. The same would happen if you use glibc and
> static link. If you want the ability to use LD_PRELOAD you need to
> link dynamically.

Furthermore, even with dynamic linking you cannot interpose 'main' in the
executable via LD_PRELOAD.  Even more baffling is that the linked code
interposes __libc_start_main; I'm lost for words that it happens to work with
glibc.

I think a cleaner solution can be obtained by converting __s2e_init_env in the
linked code to a constructor that examines environment variables, and moving
the command line processing to an separate wrapper executable.

Alexander

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.