Bug 22635 - pthread_self returns NULL before libpthread is loaded
Summary: pthread_self returns NULL before libpthread is loaded
Status: RESOLVED FIXED
Alias: None
Product: glibc
Classification: Unclassified
Component: nptl (show other bugs)
Version: 2.26
: P2 normal
Target Milestone: 2.27
Assignee: Florian Weimer
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-12-20 10:39 UTC by Florian Weimer
Modified: 2017-12-20 10:57 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:
fweimer: security-


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Florian Weimer 2017-12-20 10:39:50 UTC
The pthread_self fallback implementation in libc.so returns NULL before libpthread is loaded.  It should return the POSIX thread ID of the main thread instead.
Comment 1 Sourceware Commits 2017-12-20 10:55:21 UTC
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU C Library master sources".

The branch, master has been updated
       via  8a26ad2ab7396bc94fd3cd7b25cba433908d30e1 (commit)
      from  5069ff32842c60c55f8b573ee66fe43f9ec364af (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=8a26ad2ab7396bc94fd3cd7b25cba433908d30e1

commit 8a26ad2ab7396bc94fd3cd7b25cba433908d30e1
Author: Florian Weimer <fweimer@redhat.com>
Date:   Wed Dec 20 11:40:36 2017 +0100

    nptl: Implement pthread_self in libc.so [BZ #22635]
    
    All binaries use TLS and thus need a properly set up TCB, so we can
    simply return its address directly, instead of forwarding to the
    libpthread implementation from libc.
    
    For versioned symbols, the dynamic linker checks that the soname matches
    the name supplied by the link editor, so a compatibility symbol in
    libpthread is needed.
    
    To avoid linking against the libpthread function in all cases, we would
    have to bump the symbol version of libpthread in libc.so and supply a
    compat symbol.  This commit does not do that because the function
    implementation is so small, so the overhead by two active copies of the
    same function might well be smaller than the increase in symbol table
    size.

-----------------------------------------------------------------------

Summary of changes:
 ChangeLog                                          |   15 +++++++++++++++
 nptl/Makefile                                      |    4 ++--
 .../compat-pthread_self.c                          |   20 ++++++++------------
 nptl/forward.c                                     |    4 ----
 nptl/nptl-init.c                                   |    1 -
 nptl/pthread_self.c                                |    4 +---
 sysdeps/nptl/pthread-functions.h                   |    1 -
 7 files changed, 26 insertions(+), 23 deletions(-)
 copy sysdeps/powerpc/powerpc64/fpu/multiarch/s_llroundf-ppc64.S => nptl/compat-pthread_self.c (71%)
Comment 2 Florian Weimer 2017-12-20 10:57:53 UTC
Fixed in 2.27.