Return-Path: <ghudson@MIT.EDU>
Received: from fort-point-station.mit.edu by po11.mit.edu (8.9.2/4.7) id AAA00145; Thu, 29 Nov 2001 00:29:05 -0500 (EST)
Received: from egyptian-gods.MIT.EDU (EGYPTIAN-GODS.MIT.EDU [18.101.0.162])
	by fort-point-station.mit.edu (8.9.2/8.9.2) with ESMTP id AAA23968;
	Thu, 29 Nov 2001 00:29:01 -0500 (EST)
Received: (from ghudson@localhost) by egyptian-gods.MIT.EDU (8.9.3)
	id AAA24744; Thu, 29 Nov 2001 00:28:59 -0500
Subject: Re: ldpreload questions
From: Greg Hudson <ghudson@MIT.EDU>
To: karlm@mit.edu
Cc: sipb@mit.edu
In-Reply-To: <200111290458.XAA05042@no-knife.mit.edu>
References: <200111290458.XAA05042@no-knife.mit.edu>
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
X-Mailer: Evolution/0.99.0 (Preview Release)
Date: 29 Nov 2001 00:28:59 -0500
Message-Id: <1007011739.14196.7.camel@egyptian-gods>
Mime-Version: 1.0

On Wed, 2001-11-28 at 23:58, karlm@MIT.EDU wrote:
> My hope is to write an application that can fork and exec an arbitrary
> program, hook socket(), connect(), send(), and recv() in order to
> seamlessly tunnel the childs network connections over a secure channel
> that perturbs network latency enough to prevent packet latencies from
> leaking information.

An interesting idea.  I hope it pans out.

> 	Can anyone point me towards some source code that properly
> uses ldpreload and exec?  Have any of you used ldpreload in your own
> code?  Are there better alternatives for hooking networking functions
> in an arbitrary executable?

Using LD_PRELOAD per se is pretty easy; you just create a shared object
which defines the symbols you want (connect, send, etc.).  The hard part
is making calls to the underlying functions which you've overridden.  To
do that, you'll have to make calls to the dynamic linker library.

The best reference I know of is xalf, which is available from
ftp.gnome.org:pub/GNOME/stable/sources/xalf.  Look specifically in the
libxalflaunch directory; it does the kind of overriding you're talking
about for Solaris and Linux.  There's an Athena-hacked version in
/mit/source/third/xalf which has also been ported to IRIX.

Note that LD_PRELOAD (as well as the dlopen/dlsym magic you have to use
to get at the underlying symbols) is ELF-specific, so things like really
old Linux binaries probably won't work with your wrapper.  Hopefully
that's not important for your purposes.

