Bug 680887 - multi-threaded pam_chauthtok() test program segfaults
Summary: multi-threaded pam_chauthtok() test program segfaults
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 6
Classification: Red Hat
Component: libselinux
Version: 6.1
Hardware: All
OS: Linux
medium
medium
Target Milestone: rc
: ---
Assignee: Miroslav Grepl
QA Contact: Milos Malik
URL:
Whiteboard:
Depends On:
Blocks: 682670
TreeView+ depends on / blocked
 
Reported: 2011-02-28 11:14 UTC by Miroslav Vadkerti
Modified: 2015-09-28 02:10 UTC (History)
6 users (show)

Fixed In Version: libselinux-2.0.94-5.el6
Doc Type: Bug Fix
Doc Text:
An update to libselinux caused a segmentation fault to appear in the multi-threaded pam_chauthtok() test program. If a shared library attempted to call pthread_key_create, the associated destructors were registered with that library. The segmentation fault occurred when pthread_key_delete() was called, if that library was dereferenced with dlclose() before the destructors were removed with pthread_key_delete(). This issue has now been corrected. Note that this issue was discovered and corrected during development, and was not seen in production systems in the field.
Clone Of:
Environment:
Last Closed: 2011-05-19 14:18:43 UTC
Target Upstream Version:


Attachments (Terms of Use)
Reproducer for bug 469857 (4.23 KB, text/x-c++src)
2011-02-28 11:14 UTC, Miroslav Vadkerti
no flags Details
Proposed patch 1 (1.82 KB, patch)
2011-03-01 22:34 UTC, Eamon Walsh
no flags Details | Diff


Links
System ID Private Priority Status Summary Last Updated
Red Hat Product Errata RHBA-2011:0751 0 normal SHIPPED_LIVE libselinux bug fix update 2011-05-18 18:08:59 UTC

Description Miroslav Vadkerti 2011-02-28 11:14:40 UTC
Created attachment 481351 [details]
Reproducer for bug 469857

Description of problem:
The attached reproducer from bug 469857 segfaults:

# ./MTPamTest pamtest test
Changing password from main thread
pam_start SUCCESSFUL
pam_chauthtok SUCCESSFUL
pam_end SUCCESSFUL

Changing password from child thread
pthread_create SUCCESSFUL
pam_start SUCCESSFUL
pam_chauthtok SUCCESSFUL
pam_end SUCCESSFUL
Segmentation fault (core dumped)

The traceback shows this info:
[snip]
pam_end SUCCESSFUL
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7ffff7b75700 (LWP 26408)]
0x00000032ee613810 in ?? ()
(gdb) backtrace
#0  0x00000032ee613810 in ?? ()
#1  0x00000032eda07879 in __nptl_deallocate_tsd (arg=0x7ffff7b75700) at pthread_create.c:154
#2  start_thread (arg=0x7ffff7b75700) at pthread_create.c:308
#3  0x00000032ecee5dcd in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:115

Version-Release number of selected component (if applicable):
pam-1.1.1-8.el6.x86_64
glibc-2.12-1.19.el6.x86_64
libstdc++-4.4.5-6.el6.x86_64

How reproducible:
100% (tested on 5 machines)

Steps to Reproduce:
1. useradd pamtest
2. g++ -pthread -lpam MTPamTest.cpp -o MTPamTest
3. ./MTPamTest pamtest test
  
Actual results:
Segfault

Expected results:
No segfault

Additional info:
I can reproduce this also with EL6 packages:
pam-1.1.1-4.el6.x86_64
glibc-2.12-1.7.el6.x86_64
libstdc++-4.4.4-13.el6.x86_64

So this seems to be not a regression

Comment 2 Jakub Jelinek 2011-02-28 11:50:37 UTC
__nptl_deallocate_tsd is calling destructors registered with pthread_key_create.
The crash is apparently when it tries to call one of such handlers.
My guess would be that some shared library is calling pthread_key_create and registering some destructor in that shared library, but forgotting to pthread_key_delete in library destructors.  Therefore, if you dlopen the library, get a key created, then dlclose the library and then some thread is about to exit, it will try to call a function in an already dlclosed library.

Comment 3 Tomas Mraz 2011-02-28 14:06:37 UTC
This is regression in libselinux-2.0.94-3.el6. It does not segfault with libselinux-2.0.94-2.el6.

Comment 5 Miroslav Grepl 2011-02-28 18:32:58 UTC
It needed to come with the following 

* Fri Feb 04 2011 Miroslav Grepl <mgrepl> - 2.0.94-3
- Thread local storage fixes from Eamon Walsh
Resolves: #658571

which resolves the #658571 bug.

Comment 6 Eamon Walsh 2011-03-01 22:34:41 UTC
Created attachment 481728 [details]
Proposed patch 1

First cut of fix.

Comment 7 Miroslav Grepl 2011-03-04 15:04:14 UTC
Mirek,
could you test pkgs which I added on

http://scratch.englab.brq.redhat.com/mgrepl/RHEL6/

Looks like it does not work.

Comment 8 Miroslav Vadkerti 2011-03-05 11:49:57 UTC
Are these other test packages than I tried yesterday? I don't see the segfault happening anymore :)

Comment 9 Miroslav Grepl 2011-03-07 09:12:35 UTC
(In reply to comment #8)
> Are these other test packages than I tried yesterday? I don't see the segfault
> happening anymore :)

So it works.

Comment 10 Eamon Walsh 2011-03-09 18:41:50 UTC
Pushed to libselinux 2.0.100.

Comment 11 Eamon Walsh 2011-03-09 18:54:51 UTC
However I would note that pthread_key_delete does not call the key destructors to clean up the data.  This job is left to the caller, and I have no idea how to find all of the threads and clean up their data from the library destructor.  Some advice on how to go about doing this would be beneficial.

Comment 12 Miroslav Grepl 2011-03-10 10:14:19 UTC
The patch added to libselinux-2.0.94-4.el6

Comment 14 errata-xmlrpc 2011-03-11 14:47:16 UTC
Bug report changed from ON_QA to ASSIGNED status by the Errata System: 
Advisory RHBA-2011:10756-01: 
http://errata.devel.redhat.com/errata/stateview/10756

# rpm -qa | grep -e pam- -e libselinux | sort
libselinux-2.0.94-4.el6.x86_64
libselinux-debuginfo-2.0.94-4.el6.x86_64
libselinux-devel-2.0.94-4.el6.x86_64
libselinux-python-2.0.94-4.el6.x86_64
libselinux-ruby-2.0.94-4.el6.x86_64
libselinux-static-2.0.94-4.el6.x86_64
libselinux-utils-2.0.94-4.el6.x86_64
pam-1.1.1-8.el6.x86_64
pam-devel-1.1.1-8.el6.x86_64
# useradd pamtest
# g++ -pthread -lpam MTPamTest.cpp -o MTPamTest
# ./MTPamTest pamtest test

Changing password from main thread
pam_start SUCCESSFUL
pam_chauthtok SUCCESSFUL
pam_end SUCCESSFUL

Changing password from child thread
pthread_create SUCCESSFUL
pam_start SUCCESSFUL
pam_chauthtok SUMTPamTest[3073]: segfault at 19 ip 00007fdafd191266 sp 00007fdafc281de0 error 4CCESSFUL
 in libdl-2.12.so[7fdafd190000+2000]
Segmentation fault (core dumped)
# echo $?
139

Comment 15 Milos Malik 2011-03-11 14:59:42 UTC
(gdb) thread apply all bt

Thread 2 (Thread 0x7ffff5b4a700 (LWP 3213)):
#0  0x00007ffff6a59266 in _dlerror_run () from /lib64/libdl.so.2
#1  0x00007ffff6a5900f in dlclose () from /lib64/libdl.so.2
#2  0x00007ffff7bd6797 in _pam_free_handlers (pamh=0x7ffff00008c0)
    at pam_handlers.c:949
#3  0x00007ffff7bd5165 in pam_end (pamh=0x7ffff00008c0, pam_status=0)
    at pam_end.c:35
#4  0x0000000000400f3a in (anonymous namespace)::changePassword ()
    at MTPamTest.cpp:102
#5  0x00007ffff721c7e1 in start_thread () from /lib64/libpthread.so.0
#6  0x00007ffff6f58d2d in clone () from /lib64/libc.so.6

Thread 1 (Thread 0x7ffff7fe7720 (LWP 3206)):
#0  0x00007ffff721d03d in pthread_join () from /lib64/libpthread.so.0
#1  0x000000000040114a in main (argc=3, argv=0x7fffffffe9f8)
    at MTPamTest.cpp:138
(gdb)

Comment 16 Milos Malik 2011-03-11 15:01:14 UTC
(gdb) run
Starting program: /mnt/testarea/tests/pam/Regression/bz469857-pam-chauthtok-works-in-main-but-not-child-threads/MTPamTest pamtest test
[Thread debugging using libthread_db enabled]

Changing password from main thread
pam_start SUCCESSFUL
Detaching after fork from child process 3209.
Detaching after fork from child process 3210.
Detaching after fork from child process 3212.
pam_chauthtok SUCCESSFUL
pam_end SUCCESSFUL

Changing password from child thread
[New Thread 0x7ffff5b4a700 (LWP 3213)]
pthread_create SUCCESSFUL
pam_start SUCCESSFUL
Detaching after fork from child process 3214.
Detaching after fork from child process 3215.
Detaching after fork from child process 3216.
pam_chauthtok SUCCESSFUL

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7ffff5b4a700 (LWP 3213)]
0x00007ffff6a59266 in _dlerror_run () from /lib64/libdl.so.2

Comment 17 Miroslav Grepl 2011-03-15 13:12:03 UTC
Mirek,
do you have the same issue?

Comment 18 Miroslav Grepl 2011-03-28 13:08:49 UTC
Any idea with this?

Comment 19 Miroslav Vadkerti 2011-03-28 13:39:10 UTC
Hm, I can see the segfault also with libselinux-2.0.94-4.el6 :( Looks like the testing I made in comment #8 was invalid :(

# ./MTPamTest pamtest test

Changing password from main thread
pam_start SUCCESSFUL
pam_chauthtok SUCCESSFUL
pam_end SUCCESSFUL

Changing password from child thread
pthread_create SUCCESSFUL
pam_start SUCCESSFUL
pam_chauthtok SUCCESSFUL
Segmentation fault (core dumped)

Comment 22 Laura Bailey 2011-05-17 03:42:32 UTC
    Technical note added. If any revisions are required, please edit the "Technical Notes" field
    accordingly. All revisions will be proofread by the Engineering Content Services team.
    
    New Contents:
An update to libselinux caused a segmentation fault to appear in the multi-threaded pam_chauthtok() test program. If a shared library attempted to call pthread_key_create, the associated destructors were registered with that library. The segmentation fault occurred when pthread_key_delete() was called, if that library was dereferenced with dlclose() before the destructors were removed with pthread_key_delete(). This issue has now been corrected. Note that this issue was discovered and corrected during development, and was not seen in production systems in the field.

Comment 23 errata-xmlrpc 2011-05-19 14:18:43 UTC
An advisory has been issued which should help the problem
described in this bug report. This report is therefore being
closed with a resolution of ERRATA. For more information
on therefore solution and/or where to find the updated files,
please follow the link below. You may reopen this bug report
if the solution does not work for you.

http://rhn.redhat.com/errata/RHBA-2011-0751.html


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