From mboxrd@z Thu Jan 1 00:00:00 1970 From: kkonaka@mac.com Subject: LD_PRELOAD an anonymous file? Date: Tue, 20 Aug 2002 11:20:46 -0400 Sender: linux-c-programming-owner@vger.kernel.org Message-ID: Mime-Version: 1.0 (generated by SEMI 1.14.3 - "Ushinoya") Return-path: List-Id: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: linux-c-programming@vger.kernel.org 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 | #include | #include | 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 | #include | 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