Bug 523694

Summary: getaddrinfo causes segfault if multithreaded
Product: Red Hat Enterprise Linux 5 Reporter: Need Real Name <heuler>
Component: glibcAssignee: Andreas Schwab <schwab>
Status: CLOSED NOTABUG QA Contact: BaseOS QE <qe-baseos-auto>
Severity: high Docs Contact:
Priority: low    
Version: 5.4   
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2009-09-22 13:15:10 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Need Real Name 2009-09-16 13:16:11 UTC
Description of problem:

The getaddrinfo() function causes a internal segmentation fault if the binary is linked static and the system has more than one core (e.g. dualcore, quadcore). This behavior is not expected the function is described to be thread safe!

How reproducible:


Steps to Reproduce:
1. Need a system with multiple cores, it does not crash on single core system
2. Compile the following code
----- dnstest.cpp ----
#include <stdio.h>
#include <netdb.h>
#include <pthread.h>
#include <unistd.h>

void *test(void *)
{
        struct addrinfo *res = NULL;
        fprintf(stderr, "x=");
        int ret = getaddrinfo("localhost", NULL, NULL, &res);
        fprintf(stderr, "%d ", ret);
        return NULL;
}

int main()
{
        for (int i = 0; i < 512; i++)
        {
                pthread_t thr;
                pthread_create(&thr, NULL, test, NULL);
        }
        sleep(5);
        return 0;
}
----- dnstest.cpp ----

g++ -o dnstest -g -static dnstest.cpp -lpthread

3. Let it run
./dnstest
x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=Segmentation fault (core dumped)

If the "-static" is not used it works fine. But we need a static binary and this should work also if linked statically. There is nothing mentioned that static linking won't work.

Expected results:
The program should print some lines with "x=0" and then end after 5 seconds.

Comment 1 Need Real Name 2009-09-16 13:17:19 UTC
This happens on RedHat 5.3 or Fedora Core 11 or also older systems.

Comment 2 Andreas Schwab 2009-09-22 13:15:10 UTC
If you want a thread safe nss service you must link dynamically against libpthread, otherwise the dynamically loaded nss service modules cannot find the pthread functions.  Alternatively, you need to statically link against the nss modules.