This is the mail archive of the
glibc-bugs@sourceware.org
mailing list for the glibc project.
[Bug nptl/18853] New: dynamically loading libpthread renders locked mutexes unusable
- From: "amonakov at gmail dot com" <sourceware-bugzilla at sourceware dot org>
- To: glibc-bugs at sourceware dot org
- Date: Wed, 19 Aug 2015 10:22:25 +0000
- Subject: [Bug nptl/18853] New: dynamically loading libpthread renders locked mutexes unusable
- Auto-submitted: auto-generated
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.