This is the mail archive of the glibc-bugs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug nptl/18853] New: dynamically loading libpthread renders locked mutexes unusable


https://sourceware.org/bugzilla/show_bug.cgi?id=18853

            Bug ID: 18853
           Summary: dynamically loading libpthread renders locked mutexes
                    unusable
           Product: glibc
           Version: unspecified
            Status: NEW
          Severity: normal
          Priority: P2
         Component: nptl
          Assignee: unassigned at sourceware dot org
          Reporter: amonakov at gmail dot com
                CC: drepper.fsp at gmail dot com
  Target Milestone: ---

In Glibc, libc.so contains a few "stub" implementations of pthread functions,
such as pthread_mutex_lock.  The implementation does not modify the mutex
object, but once libpthread.so is dynamically loaded, the stub implementations
start invoking the "real" implementations.  As a result, using the same mutex
across a dlopen call that brings libpthread.so in scope is impossible:
unlocking the mutex will corrupt it, and locking it (from another thread) can
succeed even though it's still locked.

To demonstrate, this testcase correctly hangs when compiled with -ldl
-lpthread, and incorrectly does not hang when compiled with just -ldl:

#include <dlfcn.h>
#include <pthread.h>

static pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER;

static void* work(void *unused)
{
        pthread_mutex_lock(&m);
        return 0;
}

int main()
{
        pthread_mutex_lock(&m);
        void *pthlib = dlopen("libpthread.so.0", RTLD_NOW | RTLD_GLOBAL);
        //pthread_mutex_unlock(&m);
        __typeof__(pthread_create) *pcp = dlsym(pthlib, "pthread_create");
        __typeof__(pthread_join) *pjp = dlsym(pthlib, "pthread_join");
        pthread_t thread;
        pcp(&thread, 0, work, 0);
        pjp(thread, 0);
        return 0;
}

-- 
You are receiving this mail because:
You are on the CC list for the bug.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]