Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAMmqxguXGa2cswmRgVLnX=-4CvA8uRzRmfgXjNdTp73CrBXvrQ@mail.gmail.com>
Date: Tue, 11 Jan 2022 12:50:33 +0100
From: Ilia K <ki.stfu@...il.com>
To: musl@...ts.openwall.com
Subject: Cannot dlopen() an already loaded shared library by its SONAME name

Hi!

It turns out that `dlopen()` in musl cannot find the already loaded shared
library using the library soname from the dynamic section, unlike glibc.
Here is a simple demo app:
```
# cat main.c
#include <dlfcn.h>
#include <stdio.h>

#define SOMELIB_DIR  "/root/dlopen_file_name_test/somelib/"
#define SOMELIB_NAME "libsomelib.so"

int main() {
    void* library_handle = dlopen(SOMELIB_DIR SOMELIB_NAME, RTLD_LAZY |
RTLD_LOCAL);
    printf("dlopen first load: %p\n", library_handle);

    {
        void* library_handle2 = dlopen(SOMELIB_DIR SOMELIB_NAME, RTLD_LAZY
| RTLD_LOCAL | RTLD_NOLOAD);
        printf("dlopen by file path: %p\n", library_handle2);
        if (library_handle2) dlclose(library_handle2);
    }

    {
        void* library_handle3 = dlopen(SOMELIB_NAME, RTLD_LAZY |
RTLD_LOCAL);  // RTLD_NOLOAD doesn't work either
        printf("dlopen by file name: %p %s\n", library_handle3,
library_handle3 ? NULL : dlerror());
        if (library_handle3) dlclose(library_handle3);
    }

    if (library_handle) dlclose(library_handle);
    return 0;
}
# cat somelib.c
int somelib_func() { return 0; }
# cat Makefile
all:
        mkdir -p somelib
        gcc -shared somelib.c -Wl,-soname,libsomelib.so -o
somelib/libsomelib.so
        gcc main.c -o main -ldl
```

Compile & run:
```
# make
mkdir -p somelib
gcc -shared somelib.c -Wl,-soname,libsomelib.so -o somelib/libsomelib.so
gcc main.c -o main -ldl
# ./main
dlopen first load: 0x7f06a28a4ca0
dlopen by file path: 0x7f06a28a4ca0
dlopen by file name: 0 Error loading shared library libsomelib.so: No such
file or directory
```

Do you have any plans to support it?

-- 
- Ilia

Content of type "text/html" skipped

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.