Bug 1366730

Summary: dyninst: TLS access crashes if process is single-threaded
Product: [Fedora] Fedora Reporter: Florian Weimer <fweimer>
Component: dyninstAssignee: Stan Cox <scox>
Status: CLOSED EOL QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 24CC: fche, lberk, mbenitez, orion, wcohen
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2017-08-08 16:31:57 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
dyninst-single-thread.cpp none

Description Florian Weimer 2016-08-12 16:09:36 UTC
Created attachment 1190498 [details]
dyninst-single-thread.cpp

Description of problem:

If the target process is single-threaded, trying to read one of its TLS variables (particularly those defined in DSOs) crashes in Dyninst.

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

dyninst-9.1.0-5.fc24.x86_64

How reproducible:

Always.

Steps to Reproduce:
1. Compile the attached program and link it against Dyninst.
2. Run it as ./dyninst-single-thread $$ ($$ refers to the bash PID, which single-threaded).
3. Observe the crash

Actual results:

Segmentation fault

Expected results:

Value of the TLS variable is printed.

Additional info:

The TCB pointer does not look right, as the printf immediately before the crash shows:

[New Thread 0x7ffff4c77700 (LWP 27270)]
[New Thread 0x7ffff4476700 (LWP 27271)]
[New Thread 0x7ffff3a6d700 (LWP 27272)]
Library: /usr/bin/bash
Library: /lib64/libtinfo.so.6
Library: /lib64/libdl.so.2
Library: /lib64/libc.so.6
  TLS variable offset: 40
Thread ffffffffffffffff: 0

Thread 1 "dyninst-single-" received signal SIGSEGV, Segmentation fault.
td_thr_tls_get_addr (th=0x0, map_address=0x7fea1ea8b000, offset=0, address=0x7fffffffd840) at td_thr_tls_get_addr.c:31
31        err = DB_GET_FIELD (modid, th->th_ta_p, map_address, link_map,
Missing separate debuginfos, use: dnf debuginfo-install boost-atomic-1.60.0-7.fc24.x86_64 boost-chrono-1.60.0-7.fc24.x86_64 boost-date-time-1.60.0-7.fc24.x86_64 boost-system-1.60.0-7.fc24.x86_64 boost-thread-1.60.0-7.fc24.x86_64 dyninst-9.1.0-5.fc24.x86_64 libdwarf-20160507-1.fc24.x86_64 libgcc-6.1.1-3.fc24.x86_64 libstdc++-6.1.1-3.fc24.x86_64
(gdb) bt
#0  td_thr_tls_get_addr (th=0x0, map_address=0x7fea1ea8b000, offset=0, address=0x7fffffffd840) at td_thr_tls_get_addr.c:31
#1  0x00007ffff7b3144b in thread_db_process::plat_calcTLSAddress(int_thread*, int_library*, unsigned long, unsigned long&, std::set<boost::shared_ptr<response>, std::less<boost::shared_ptr<response> >, std::allocator<boost::shared_ptr<response> > >&) () from /usr/lib64/dyninst/libpcontrol.so.9.1
#2  0x00007ffff7ab5731 in Dyninst::ProcControlAPI::Thread::readThreadLocalMemory(void*, boost::shared_ptr<Dyninst::ProcControlAPI::Library const>, unsigned long, unsigned long) const () from /usr/lib64/dyninst/libpcontrol.so.9.1
#3  0x0000000000401c8d in main (argc=<optimized out>, argv=0x7fffffffdc08) at dyninst-single-thread.cpp:63
(gdb)

Comment 1 Fedora Admin XMLRPC Client 2016-08-15 17:46:23 UTC
This package has changed ownership in the Fedora Package Database.  Reassigning to the new owner of this component.

Comment 2 Josh Stone 2016-08-16 00:55:17 UTC
FWIW, this also happens with dyninst-9.2.0-1.fc25.  I'll try again with a build from dyninst master, then probably file a bug upstream.

Comment 3 Josh Stone 2016-08-16 01:19:12 UTC
Hmm, GDB can't figure this out either:

bash-4.3$ gdb bash $$
[...]
0x00007fe65b01059a in __GI___waitpid (pid=pid@entry=-1, stat_loc=stat_loc@entry=0x7fff6b6b85d0, 
    options=options@entry=10) at ../sysdeps/unix/sysv/linux/waitpid.c:29
29        return SYSCALL_CANCEL (wait4, pid, stat_loc, options, NULL);
(gdb) p thread_arena
Cannot find thread-local storage for process 10616, shared library /lib64/libc.so.6:
Cannot find thread-local variables on this target
(gdb) 

Any idea why that would be?

Comment 4 Florian Weimer 2016-08-16 07:31:01 UTC
(In reply to Josh Stone from comment #3)
> Hmm, GDB can't figure this out either:
> 
> bash-4.3$ gdb bash $$
> [...]
> 0x00007fe65b01059a in __GI___waitpid (pid=pid@entry=-1,
> stat_loc=stat_loc@entry=0x7fff6b6b85d0, 
>     options=options@entry=10) at ../sysdeps/unix/sysv/linux/waitpid.c:29
> 29        return SYSCALL_CANCEL (wait4, pid, stat_loc, options, NULL);
> (gdb) p thread_arena
> Cannot find thread-local storage for process 10616, shared library
> /lib64/libc.so.6:
> Cannot find thread-local variables on this target
> (gdb) 
> 
> Any idea why that would be?

Maybe this works only if libpthread is linked in?  It seems to start working once I preload it.

Comment 5 Fedora Admin XMLRPC Client 2017-05-15 19:58:33 UTC
This package has changed ownership in the Fedora Package Database.  Reassigning to the new owner of this component.

Comment 6 Fedora End Of Life 2017-07-25 22:24:51 UTC
This message is a reminder that Fedora 24 is nearing its end of life.
Approximately 2 (two) weeks from now Fedora will stop maintaining
and issuing updates for Fedora 24. It is Fedora's policy to close all
bug reports from releases that are no longer maintained. At that time
this bug will be closed as EOL if it remains open with a Fedora  'version'
of '24'.

Package Maintainer: If you wish for this bug to remain open because you
plan to fix it in a currently maintained version, simply change the 'version'
to a later Fedora version.

Thank you for reporting this issue and we are sorry that we were not
able to fix it before Fedora 24 is end of life. If you would still like
to see this bug fixed and are able to reproduce it against a later version
of Fedora, you are encouraged  change the 'version' to a later Fedora
version prior this bug is closed as described in the policy above.

Although we aim to fix as many bugs as possible during every release's
lifetime, sometimes those efforts are overtaken by events. Often a
more recent Fedora release includes newer upstream software that fixes
bugs or makes them obsolete.

Comment 7 Fedora End Of Life 2017-08-08 16:31:57 UTC
Fedora 24 changed to end-of-life (EOL) status on 2017-08-08. Fedora 24 is
no longer maintained, which means that it will not receive any further
security or bug fix updates. As a result we are closing this bug.

If you can reproduce this bug against a currently maintained version of
Fedora please feel free to reopen this bug against that version. If you
are unable to reopen this bug, please file a new report against the
current release. If you experience problems, please add a comment to this
bug.

Thank you for reporting this bug and we are sorry it could not be fixed.