linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: kkonaka@mac.com
To: linux-c-programming@vger.kernel.org
Subject: LD_PRELOAD an anonymous file?
Date: Tue, 20 Aug 2002 11:20:46 -0400	[thread overview]
Message-ID: <sqbznvhd0a9.wl@nue.mac.com> (raw)

hi, 

Q: - is there any way to do the same thing as
``LD_PRELOAD=file'', but using only a nameless file?

that is - I have a program like this:

  | /*launcher.c:*/
  | #include <unistd.h>
  | #include <stdlib.h>
  | #include <stdio.h>
  | main()
  | {
  |   int fd;
  |   char *av[] = { "file", "/etc/motd", 0, };
  |   putenv("LD_PRELOAD=./intercept.so"); /* I may want to unlink() this name */
  |   execv("/usr/bin/file", av); /* launch some target program to be influenced */
  |   perror("execv");
  | }

  | /*intercept.c*/
  | #include <dlfcn.h>
  | #include <stdio.h>
  | int open(const char *p, int mod)
  | {
  |   int fd;
  |   void *h = dlopen("/lib/libc.so.6", RTLD_LAZY);
  |   int (*f)() = dlsym(h, "open");
  |   dlclose(h);
  |   printf("open: %s\n", p);
  |   fflush(stdout);
  |   fd = (*f)(p, mod);
  |   return fd;
  | }

  | /*makefile*/
  | intercept.so: intercept.c
  | 	gcc -c intercept.c
  | 	ld -G -shared -o intercept.so intercept.o -l dl
  | 
  | launcher: launcher.c
  | 	gcc -o launcher launcher.c

this works fine. and calls to open() does go into the
stub defined in intercept.c

now what I want to do now is:

1) within the "laucher" program, dynamically generate
   equivalent data(=program) that was supposed to go into
   file intercept.so .

2) keep this generated data to be (somewhat) invisible
   even in the face of program crash.  (I might be
   generating (somewhat) sensitive data for this).

3) to do 2), I'm thinking about either
    A) once store the data into file under the name 
       "intercept.so" anyway, but immediately unlink(2) this,
       retaining only the filedescriptor to refer to the file. 
       (but if the file no longer has a name how can I
       interact with the dynamic linker?)
    B) otherwise if there's some private && transient
       (more or less) name space in some file system
       eg., /proc/self/... (?) this may be equally okay
       compared to A).
    C) by any chance - is there any funky way of 
       doing this without using filesystem at all?
       (eg., use only VM,... or use some dynamic linker
       interface I was not aware of)

regards,
kenji

             reply	other threads:[~2002-08-20 15:20 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-08-20 15:20 kkonaka [this message]
     [not found] ` <20020910105526.GA734@cam.ac.uk>
2002-09-13 14:55   ` LD_PRELOAD an anonymous file? kkonaka

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sqbznvhd0a9.wl@nue.mac.com \
    --to=kkonaka@mac.com \
    --cc=linux-c-programming@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).