From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/8109 Path: news.gmane.org!not-for-mail From: Riyad Parvez Newsgroups: gmane.linux.lib.musl.general Subject: Making a shared library that intercepts call to main work with musl compiled binary Date: Mon, 6 Jul 2015 13:00:52 -0400 Message-ID: Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=001a113d56e67ce6fa051a37dbcf X-Trace: ger.gmane.org 1436203876 29570 80.91.229.3 (6 Jul 2015 17:31:16 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 6 Jul 2015 17:31:16 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-8122-gllmg-musl=m.gmane.org@lists.openwall.com Mon Jul 06 19:31:12 2015 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1ZCAET-0007Fy-Ns for gllmg-musl@m.gmane.org; Mon, 06 Jul 2015 19:31:05 +0200 Original-Received: (qmail 27840 invoked by uid 550); 6 Jul 2015 17:31:02 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 5656 invoked from network); 6 Jul 2015 17:01:50 -0000 X-Received: by 10.202.91.212 with SMTP id p203mr45989218oib.108.1436202091470; Mon, 06 Jul 2015 10:01:31 -0700 (PDT) X-UUID: 034a3047-67b9-443f-8a65-13bd057348b5 X-Miltered: at mailchk-m01 with ID 559AB46B.003 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Virus-Scanned: clamav-milter 0.98.6 at mailchk-m01 X-Virus-Status: Clean X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.4.3 (mailchk-m01.uwaterloo.ca [129.97.128.141]); Mon, 06 Jul 2015 13:01:33 -0400 (EDT) X-Spam-Status: No, score=-7.0 required=5.0 tests=ALL_TRUSTED,HTML_MESSAGE autolearn=disabled version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mailchk-r03.uwaterloo.ca Xref: news.gmane.org gmane.linux.lib.musl.general:8109 Archived-At: --001a113d56e67ce6fa051a37dbcf Content-Type: text/plain; charset=UTF-8 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 --001a113d56e67ce6fa051a37dbcf Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Hi All,

I've shared library [= 1] which intercepts loading of a binary and does some pre-processing with t= he command-line arguments via "LD_PRELOAD" technique. The shared = library works fine with glibc compiled binary i.e., it can intercept the ca= ll to main and does some preprocessing. But it can't intercept call to = "main" in musl-compiled binary. I've compiled my binary in st= atic mode with musl "CC=3D/musl-gcc -static". How can I make the = shared library work with musl-compiled binary?

Thanks
Riyad


--001a113d56e67ce6fa051a37dbcf-- From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/8110 Path: news.gmane.org!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: Making a shared library that intercepts call to main work with musl compiled binary Date: Mon, 6 Jul 2015 13:32:59 -0400 Message-ID: <20150706173259.GX1173@brightrain.aerifal.cx> References: Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1436203997 31891 80.91.229.3 (6 Jul 2015 17:33:17 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 6 Jul 2015 17:33:17 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-8123-gllmg-musl=m.gmane.org@lists.openwall.com Mon Jul 06 19:33:16 2015 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1ZCAGa-00009l-4Q for gllmg-musl@m.gmane.org; Mon, 06 Jul 2015 19:33:16 +0200 Original-Received: (qmail 30029 invoked by uid 550); 6 Jul 2015 17:33:13 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 30008 invoked from network); 6 Jul 2015 17:33:12 -0000 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Original-Sender: Rich Felker Xref: news.gmane.org gmane.linux.lib.musl.general:8110 Archived-At: 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. Rich From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/8111 Path: news.gmane.org!not-for-mail From: Alexander Monakov Newsgroups: gmane.linux.lib.musl.general Subject: Re: Making a shared library that intercepts call to main work with musl compiled binary Date: Mon, 6 Jul 2015 22:00:41 +0300 (MSK) Message-ID: References: <20150706173259.GX1173@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Trace: ger.gmane.org 1436209256 2554 80.91.229.3 (6 Jul 2015 19:00:56 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 6 Jul 2015 19:00:56 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-8124-gllmg-musl=m.gmane.org@lists.openwall.com Mon Jul 06 21:00:54 2015 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1ZCBdO-0001QU-Kl for gllmg-musl@m.gmane.org; Mon, 06 Jul 2015 21:00:54 +0200 Original-Received: (qmail 22212 invoked by uid 550); 6 Jul 2015 19:00:53 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 22194 invoked from network); 6 Jul 2015 19:00:52 -0000 In-Reply-To: <20150706173259.GX1173@brightrain.aerifal.cx> User-Agent: Alpine 2.11 (LNX 23 2013-08-11) Xref: news.gmane.org gmane.linux.lib.musl.general:8111 Archived-At: 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 From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/8112 Path: news.gmane.org!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: Making a shared library that intercepts call to main work with musl compiled binary Date: Mon, 6 Jul 2015 15:06:51 -0400 Message-ID: <20150706190651.GY1173@brightrain.aerifal.cx> References: <20150706173259.GX1173@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1436209629 9479 80.91.229.3 (6 Jul 2015 19:07:09 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 6 Jul 2015 19:07:09 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-8125-gllmg-musl=m.gmane.org@lists.openwall.com Mon Jul 06 21:07:07 2015 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1ZCBjP-00055I-Fi for gllmg-musl@m.gmane.org; Mon, 06 Jul 2015 21:07:07 +0200 Original-Received: (qmail 30124 invoked by uid 550); 6 Jul 2015 19:07:06 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 30106 invoked from network); 6 Jul 2015 19:07:05 -0000 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Original-Sender: Rich Felker Xref: news.gmane.org gmane.linux.lib.musl.general:8112 Archived-At: On Mon, Jul 06, 2015 at 10:00:41PM +0300, Alexander Monakov wrote: > 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. Presumably it interposes __libc_start_main because it can't interpose main. As far as I can tell the only reason it does this is to inject fake argv. I'm skeptical as to whether it works correctly. > 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. Certainly. Rich From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/8113 Path: news.gmane.org!not-for-mail From: Alexander Monakov Newsgroups: gmane.linux.lib.musl.general Subject: Re: Making a shared library that intercepts call to main work with musl compiled binary Date: Mon, 6 Jul 2015 23:34:49 +0300 (MSK) Message-ID: References: <20150706173259.GX1173@brightrain.aerifal.cx> <20150706190651.GY1173@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Trace: ger.gmane.org 1436214907 6972 80.91.229.3 (6 Jul 2015 20:35:07 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 6 Jul 2015 20:35:07 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-8126-gllmg-musl=m.gmane.org@lists.openwall.com Mon Jul 06 22:35:06 2015 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1ZCD6U-0007EV-1I for gllmg-musl@m.gmane.org; Mon, 06 Jul 2015 22:35:02 +0200 Original-Received: (qmail 28230 invoked by uid 550); 6 Jul 2015 20:35:00 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 28212 invoked from network); 6 Jul 2015 20:35:00 -0000 In-Reply-To: <20150706190651.GY1173@brightrain.aerifal.cx> User-Agent: Alpine 2.11 (LNX 23 2013-08-11) Xref: news.gmane.org gmane.linux.lib.musl.general:8113 Archived-At: > > 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. > > Presumably it interposes __libc_start_main because it can't interpose > main. As far as I can tell the only reason it does this is to inject > fake argv. I'm skeptical as to whether it works correctly. I was wrong about interposition on __libc_start_main being somehow surprising -- I missed that it's called from the main executable's startup routine, not from the dynamic linker (thanks to Rich for explaining that on IRC!). So as a result I expect that original code should usually work in practice. Alexander