Bug 25114 - RFE: Provide dlopen API(s) that allows caller to identify resolution scope (required by ASAN).
Summary: RFE: Provide dlopen API(s) that allows caller to identify resolution scope (r...
Status: NEW
Alias: None
Product: glibc
Classification: Unclassified
Component: dynamic-link (show other bugs)
Version: 2.31
: P2 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
: 28008 (view as bug list)
Depends on:
Blocks:
 
Reported: 2019-10-18 21:14 UTC by Carlos O'Donell
Modified: 2022-02-28 19:53 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:
fweimer: security-


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Carlos O'Donell 2019-10-18 21:14:06 UTC
The ASAN interposer for dlopen cannot accurately interpose dlopen because when it itself calls dlopen the dynamic loader considers ASAN to be the caller and the scope resolution for loading the library starts there. Instead what you want is for ASAN to be able to call dlopen but with the search scope of the library it is interposing, which may not even be known. Either way, we need some new kind of API here.

The following example shows the situation:

#include <dlfcn.h>
#include <iostream>
int main()
{
    void *handle = dlopen("libb.so", RTLD_NOW);
    if (handle == NULL) {
        std::cout << "Failed to load libb.so" << std::endl;
    }
}

#mkdir lib
#g++ --sanitize=address -Wl,-rpath='$ORIGIN/lib' -Wl,--enable-new-dtags -ldl -o main main.cpp
#cd lib; 

Create libb.so: 
int foo()
{
  return 1;
}

g++ -fPIC -shared b.C -o libb.so

Actual results:

strace ./main 2>&1 | grep libb.so
open("/opt/rh/devtoolset-6/root/usr/lib/../lib64/tls/libb.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
:
<snipped>
:
open("/usr/lib64/libb.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
write(1, "Failed to load libb.so\n", 23Failed to load libb.so

Expected results:

strace ./main 2>&1 | grep libb.so

open("/opt/rh/devtoolset-6/root/usr/lib64/tls/libb.so", O_RDONLY) = -1 ENOENT (No such file or directory)

open("/root/cc/lib/libb.so", O_RDONLY)  = 3
Comment 1 Florian Weimer 2022-02-28 19:53:52 UTC
*** Bug 28008 has been marked as a duplicate of this bug. ***