tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: dlopen interception on libasan



On 11/30/16 01:32, Christos Zoulas wrote:
Well, the problem in PR/51670 is that with -fsanitizer=address the
dlopen interception is broken. libasan.so provides its own dlopen()
and then tries to find the real dlopen using dlsym(RTLD_NEXT,
"dlopen"). That does not work for NetBSD because dlopen in libc is
just a stub (that perhaps should abort), and the real dlopen is in
ld.elf_so itself. Unfortunately we can't get to it anymore easily
because RTLD_DEFAULT, RTLD_SELF, RTLD_NEXT, NULL all return the
wrong dlopen().


Are you sure about RTLD_DEFAULT?

zoom$ cat foo.c
#include <dlfcn.h>

void *
foo_rtld_default(void)
{
        return dlsym(RTLD_DEFAULT, "dlopen");
}

void *
foo_rtld_next(void)
{
        return dlsym(RTLD_NEXT, "dlopen");
}
zoom$ cat main.c
#include <stdio.h>

void *foo_rtld_default();
void *foo_rtld_next();

int
main()
{
        printf("dlopen using default %p\n", foo_rtld_default());
        printf("dlopen using next    %p\n", foo_rtld_next());
}

zoom$ cc -fPIC -c foo.c -o foo.pico
zoom$ cc -shared -o libfoo.so foo.pico
zoom$ gcc main.c libfoo.so
zoom$ gcc main.c -R$(pwd) libfoo.so
zoom$ ./a.out
dlopen using default 0x7f7ff7c0623a
dlopen using next    0x7f7ff7068c90



That said, I wonder if RTLD_NEXT should work here...

RTLD_DEFAULT/_rtld_symlook_default does the right thing because of

    https://nxr.netbsd.org/xref/src/libexec/ld.elf_so/symbol.c#565

Maybe something similar should be added for RTLD_{SELF,NEXT} here:

    https://nxr.netbsd.org/xref/src/libexec/ld.elf_so/rtld.c#1125

Nick





Home | Main Index | Thread Index | Old Index