RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 1304106 - dlopen deadlocks during thread cancellation
Summary: dlopen deadlocks during thread cancellation
Keywords:
Status: CLOSED WONTFIX
Alias: None
Product: Red Hat Enterprise Linux 6
Classification: Red Hat
Component: glibc
Version: 6.9
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: rc
: ---
Assignee: glibc team
QA Contact: qe-baseos-tools-bugs
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2016-02-02 22:10 UTC by Anit Lulla
Modified: 2017-08-29 20:27 UTC (History)
5 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2017-08-29 20:27:21 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)
C++ source code that reproduces the bug (1.70 KB, text/plain)
2016-02-02 22:10 UTC, Anit Lulla
no flags Details


Links
System ID Private Priority Status Summary Last Updated
Sourceware 22034 0 None None None 2017-08-29 20:27:21 UTC

Description Anit Lulla 2016-02-02 22:10:19 UTC
Created attachment 1120575 [details]
C++ source code that reproduces the bug

Description of problem:
dlopen() deadlocks when a prior dlopen() call is cancelled via pthread_cancel()

Version-Release number of selected component (if applicable):
All versions

How reproducible:
Always (see reproducer, which is attached)

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

using namespace std;

// to reproduce (copy contents to dl_deadlock.cpp)
//
// $ g++ -D FOO_SHARE_LIB -shared -o libfoo.so -fPIC dl_deadlock.cpp
// $ g++ -g dl_deadlock.cpp -ldl -lpthread
// $ ./a.out

#ifdef FOO_SHARE_LIB
class Foo
{
  public:
  Foo() {
    cout << "construct foo" << endl;
    usleep(500000);
    cout << "done construct foo" << endl;
  }
};
Foo g_foo;

#else

extern "C" void *thrfxn_init(void *arg)
{ usleep(500000); return NULL; }

extern "C" void *thrfxn(void *arg)
{
  cout << "before dlopen" << endl;
  void *h = dlopen("./libfoo.so",  RTLD_GLOBAL | RTLD_NOW);
  cout << "after dlopen" << endl;
  if (h);
    dlclose(h);
}

int main()
{
  pthread_t thr;

  // need to call cancel so pthread_cancel_init is called,
  // which calls into libdl (needed since first pthread_cancel waits on dlopen)
  pthread_create(&thr, NULL, thrfxn_init, NULL);
  pthread_cancel(thr);
  pthread_join(thr, NULL);
  
  cout << "before thread create" << endl;
  pthread_create(&thr, NULL, thrfxn, NULL);
  cout << "after thread create" << endl;

  // sleep 5ms
  usleep(5000);

  // cancel thread that is waiting in dlopen
  cout << "before cancel" << endl;
  pthread_cancel(thr);
  cout << "after cancel" << endl;

  // this dlopen will now deadlock
  void *h = dlopen("/lib64/libc.so.6", RTLD_GLOBAL | RTLD_NOW);
  if (h)
    dlclose(h);

  //find_symbol("PA_REPORT_CALC_DISPATCH", PA_REPORT_CALC_DISPATCH);
  //FDSA_FQL_SERVICE, CREATE_FDSA_FQL_SERVICE;

  cout << "before join" << endl;
  pthread_join(thr, NULL);
  cout << "after join" << endl;

  return 0;
}

#endif

Steps to Reproduce:
1. g++ -D FOO_SHARE_LIB -shared -o libfoo.so -fPIC dl_deadlock.cpp
2. g++ -g dl_deadlock.cpp -ldl -lpthread
3. ./a.out

Actual results:
before thread create
after thread create
before dlopen
construct foo
before cancel
after cancel
-- deadlock --

Expected results:
before thread create
after thread create
before dlopen
construct foo
before cancel
after cancel
done construct foo
after dlopen
before join
-- program completion --

Additional info:

Comment 3 Carlos O'Donell 2016-11-22 17:11:56 UTC
I'm moving this to rhel-6.10 for review. We aren't going to look at this for rhel-6.9. There are several cases which we have fixed where the error paths out of dlopen failed to successfully rollback the changes for intermediate loads, but it's likely we haven't done this for all the cases possible. It would be interesting if this reproduces in upstream master.

Comment 5 Carlos O'Donell 2017-08-29 20:27:21 UTC
Constructors are foreign function calls which happen while the dynamic loader is loading the shared library, as such, there are some things which don't work during this particular stage of loading. In this case the foreign function has triggered deferred cancellation and has left the internal dynamic loader locks taken. One fix would be to push a cleanup function in dlopen which releases the locks if the foreign functions call a cancellation point. Unfortunately this kind of fix is invasive for RHEL6, and upstream still doesn't pass this test.

I've opened upstream bug 22034 for this to be tracked upstream.


Note You need to log in before you can comment on or make changes to this bug.