From: ohaya on
Hi,

I am trying to build a "library interposer" working on Solaris.

The original problem that I'm trying to solve is that I have a shared
library (a ".SO" file), for which I don't have the source, that is
missing an function. Functions in this shared lib get called by another
program, and that program (the "server") is failing because it says that
that one function is missing from the shared lib, so I've been trying,
at least temporarily, to workaround the situation while I try to get the
person who created the original shared lib to fix it.

I have the header file for the shared library, so I know what the
prototypes for all of the functions are supposed to look like, and I
originally had been looking into possibly writing a wrapper for the
original shared lib (the one that is missing one function, "cleanup"),
and I ran across the concept of a "library interposer" and "LD_PRELOAD",
which, I think, looked like exactly what I needed.

So, I wrote a small shared lib, with just the missing function in it
(luckily it doesn't return anything, so my shared lib is pretty simple):

#include <stdio.h>
#include <stdlib.h>
void cleanup() {
printf ("HELLO FROM Jim's INTERPOSER
*******************************\n");
}

Here's the compile command line:

cc -o interposer.so -G -Kpic interposer.c

I then did:

# LD_PRELOAD=/path/inteposer.so;export LD_PRELOAD
# server

However, after all of that, it looks like, for some reason, my
interposer SO is not "taking". The way that I know this is because:

1) The server program is still telling me that the "cleanup" function is
missing from the shared library, and
2) I don't see the output from the "cleanup" function in my interposer.

Am I missing something here? Possibly, I'm misunderstanding how the
concept of a library interposer is suppose to work?

If anyone can suggest what the problem might be, or clarify my
understanding of interposers, I'd really appreciate it.

Thanks,
Jim
From: ohaya on


ohaya wrote:
>
> Hi,
>
> I am trying to build a "library interposer" working on Solaris.
>
> The original problem that I'm trying to solve is that I have a shared
> library (a ".SO" file), for which I don't have the source, that is
> missing an function. Functions in this shared lib get called by another
> program, and that program (the "server") is failing because it says that
> that one function is missing from the shared lib, so I've been trying,
> at least temporarily, to workaround the situation while I try to get the
> person who created the original shared lib to fix it.
>
> I have the header file for the shared library, so I know what the
> prototypes for all of the functions are supposed to look like, and I
> originally had been looking into possibly writing a wrapper for the
> original shared lib (the one that is missing one function, "cleanup"),
> and I ran across the concept of a "library interposer" and "LD_PRELOAD",
> which, I think, looked like exactly what I needed.
>
> So, I wrote a small shared lib, with just the missing function in it
> (luckily it doesn't return anything, so my shared lib is pretty simple):
>
> #include <stdio.h>
> #include <stdlib.h>
> void cleanup() {
> printf ("HELLO FROM Jim's INTERPOSER
> *******************************\n");
> }
>
> Here's the compile command line:
>
> cc -o interposer.so -G -Kpic interposer.c
>
> I then did:
>
> # LD_PRELOAD=/path/inteposer.so;export LD_PRELOAD
> # server
>
> However, after all of that, it looks like, for some reason, my
> interposer SO is not "taking". The way that I know this is because:
>
> 1) The server program is still telling me that the "cleanup" function is
> missing from the shared library, and
> 2) I don't see the output from the "cleanup" function in my interposer.
>
> Am I missing something here? Possibly, I'm misunderstanding how the
> concept of a library interposer is suppose to work?
>
> If anyone can suggest what the problem might be, or clarify my
> understanding of interposers, I'd really appreciate it.
>
> Thanks,
> Jim


Hi,

I just noticed that if I do an "nm -g interposer.so" after I've set
LD_PRELOAD, I am getting a fatal error:

ld.so.1: fatal Wrong ELF type

Could this be why the LD_PRELOAD and my interposer aren't working?

If so, am I doing wrong wrong in the compile command line?

Thanks,
Jim
From: Casper H.S. Dik on
ohaya <ohaya(a)cox.net> writes:


>I just noticed that if I do an "nm -g interposer.so" after I've set
>LD_PRELOAD, I am getting a fatal error:

>ld.so.1: fatal Wrong ELF type

That's because nm runs in 64 bit mode and dies when confronted with
a 32 bit interposer; set the environment LD_PRELOAD_32 instead.

Is the server set-uid by any chance?

Casper
--
Expressed in this posting are my opinions. They are in no way related
to opinions held by my employer, Sun Microsystems.
Statements on Sun products included here are not gospel and may
be fiction rather than truth.
From: ohaya on
>
> Is the server set-uid by any chance?


Casper,

I just checked, using:

find / -type f -perm -4000 -exec ls -l \{\} \; | tee /tmp/setuid.log

and, yes, the "server" program did show up in that list.

Why did you ask?


Also, I'm still wondering if my understanding of interposers and
LD_PRELOAD is accurate. Can interposers ADD to the set of functions in
a shared library, or can they only be used to replace/overload functions
that already exist in a shared library?

For example, suppose in the original shared lib, there are functions a,
b, and c. Can an interposer and LD_PRELOAD be used to make it look like
the shared lib had functions a, b, c [from the original shared lib] and
d and e [from the interposer shared lib]?

Thanks,
Jim
From: ohaya on


"Casper H.S. Dik" wrote:
>
> ohaya <ohaya(a)cox.net> writes:
>
> >I just noticed that if I do an "nm -g interposer.so" after I've set
> >LD_PRELOAD, I am getting a fatal error:
>
> >ld.so.1: fatal Wrong ELF type
>
> That's because nm runs in 64 bit mode and dies when confronted with
> a 32 bit interposer; set the environment LD_PRELOAD_32 instead.
>


Hi,

I forgot to answer the above.

I tried setting LD_PRELOAD_32. When I do that, the "nm" works on both
the original and my interposer shared libs.

However, the server is still not "seeing" the function that is in my
interposer (and not in the original shared lib. Should the server be
able to see the new function (in the interposer shared lib)?

Jim