Skip to content

Improve arguments to dlopen() #6445

@zwoop

Description

@zwoop

While debugging a name space collision (header_rewrite has a SimpleTokenzier, and so does the tscore), and talking to @bryancall and @randall, it seems like we ought to do something like this:

diff --git a/proxy/Plugin.cc b/proxy/Plugin.cc
index 79b3b0864..4706aad05 100644
--- a/proxy/Plugin.cc
+++ b/proxy/Plugin.cc
@@ -73,7 +73,7 @@ PluginRegInfo::~PluginRegInfo()
 bool
 plugin_dso_load(const char *path, void *&handle, void *&init, std::string &error)
 {
-  handle = dlopen(path, RTLD_NOW);
+  handle = dlopen(path, RTLD_NOW | RTLD_DEEPBIND | RTLD_LOCAL);
   init   = nullptr;
   if (!handle) {
     error.assign("unable to load '").append(path).append("': ").append(dlerror());
diff --git a/proxy/http/remap/PluginDso.cc b/proxy/http/remap/PluginDso.cc
index 7bd4dcf71..780752fc0 100644
--- a/proxy/http/remap/PluginDso.cc
+++ b/proxy/http/remap/PluginDso.cc
@@ -88,7 +88,7 @@ PluginDso::load(std::string &error)
       PluginDebug(_tag, "plugin '%s' mоdification time %ld", _configPath.c_str(), _mtime);
 
       /* Now attemt to load the plugin DSO */
-      if ((_dlh = dlopen(_runtimePath.c_str(), RTLD_NOW)) == nullptr) {
+      if ((_dlh = dlopen(_runtimePath.c_str(), RTLD_NOW | RTLD_DEEPBIND | RTLD_LOCAL)) == nullptr) {
 #if defined(freebsd) || defined(openbsd)
         char *err = (char *)dlerror();
 #else

However, if I do this, then other badness happens, and I'm not sure if it's an issue in some of our plugins, or libstdc++ or what. The ASAN will trigger a new vs free error, like this:

    #0 0x7faccb04d508 in __interceptor_free (/lib64/libasan.so.4+0xde508)
    #1 0x7facc04e024b in __gnu_cxx::new_allocator<char>::deallocate(char*, unsigned long) /opt/rh/devtoolset-7/root/usr/include/c++/7/ext/new_allocator.h:125
    #2 0x7facc04df7f3 in std::string::_Rep::_M_destroy(std::allocator<char> const&) /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/basic_string.tcc:899
    #3 0x7facc04debeb in std::string::_Rep::_M_dispose(std::allocator<char> const&) /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/basic_string.h:3251
    #4 0x7facc04de514 in std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string() /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/basic_string.h:3621
    #5 0x7facc04f867a in RulesConfig::parse_config(std::string const&, TSHttpHookID) header_rewrite/header_rewrite.cc:188
    #6 0x7facc04f9188 in TSPluginInit header_rewrite/header_rewrite.cc:341
    #7 0xc5680d in single_plugin_init /usr/local/src/trafficserver/proxy/Plugin.cc:152
    #8 0xc57cf4 in plugin_init(bool) /usr/local/src/trafficserver/proxy/Plugin.cc:322
    #9 0x6e7cd9 in main traffic_server/traffic_server.cc:2058
    #10 0x7facc8528504 in __libc_start_main (/lib64/libc.so.6+0x22504)
    #11 0x6497d8  (/opt/ats/bin/traffic_server+0x6497d8)

0x606000051d40 is located 0 bytes inside of 54-byte region [0x606000051d40,0x606000051d76)
allocated by thread T0 here:
    #0 0x7faccb04f1a8 in operator new(unsigned long) (/lib64/libasan.so.4+0xe01a8)
    #1 0x65bd14 in __gnu_cxx::new_allocator<char>::allocate(unsigned long, void const*) /opt/rh/devtoolset-7/root/usr/include/c++/7/ext/new_allocator.h:111
    #2 0x658495 in std::string::_Rep::_S_create(unsigned long, unsigned long, std::allocator<char> const&) /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/basic_string.tcc:1057
    #3 0x658215 in std::string::_Rep::_M_clone(std::allocator<char> const&, unsigned long) /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/basic_string.tcc:1078
    #4 0x679bc6 in std::string::reserve(unsigned long) /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/basic_string.tcc:960
    #5 0x67993f in std::string::append(char const*, unsigned long) /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/basic_string.tcc:758
    #6 0x7facc8e62643 in std::basic_istream<char, std::char_traits<char> >& std::getline<char, std::char_traits<char>, std::allocator<char> >(std::basic_istream<char, std::char_traits<char> >&, std::basic_string<char, std::char_traits<char>, std::allocator<char> >&, char) (/lib64/libstdc++.so.6+0x76643)

I tried to see which string this might be referring to, but as you can see, the allocation doesn't show anything in the ATS code, and the "free" happens in _interceptor_free(), via some STL code, so maybe the explicit RTLD_DEEPBIND interacts poorly here with something else?

This is with an ASAN build of course.

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions