* LD_PRELOAD an anonymous file?
@ 2002-08-20 15:20 kkonaka
[not found] ` <20020910105526.GA734@cam.ac.uk>
0 siblings, 1 reply; 2+ messages in thread
From: kkonaka @ 2002-08-20 15:20 UTC (permalink / raw)
To: linux-c-programming
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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: LD_PRELOAD an anonymous file?
[not found] ` <20020910105526.GA734@cam.ac.uk>
@ 2002-09-13 14:55 ` kkonaka
0 siblings, 0 replies; 2+ messages in thread
From: kkonaka @ 2002-09-13 14:55 UTC (permalink / raw)
To: sos22; +Cc: linux-c-programming
hi - thanks much!
> A (very brief) test suggested that the links in /proc/<parent pid>/fd
> should still work. e.g. if file descriptor 3 points to what used to
> be intercept.so, so will /proc/<parent pid>/fd/3.
brilliant! I've tried myself -- works fine :)
(my program actually does exec() without doing fork(),
so /proc/self/fd/<fd> was just fine. also:
/dev/fd/<fd> worked equally okay on all of solaris2,
linux, netbsd :) )
> In principle, it could probably be done with ptrace() and the rest
> of the debugging API, but it wouldn't be much fun.
hmm., never thought about that direction - I'll think about it.
thanks again!!
kenji :)
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2002-09-13 14:55 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-08-20 15:20 LD_PRELOAD an anonymous file? kkonaka
[not found] ` <20020910105526.GA734@cam.ac.uk>
2002-09-13 14:55 ` kkonaka
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).