glibc/sysdeps/generic
Szabolcs Nagy 83b5323261 elf: Avoid deadlock between pthread_create and ctors [BZ #28357]
The fix for bug 19329 caused a regression such that pthread_create can
deadlock when concurrent ctors from dlopen are waiting for it to finish.
Use a new GL(dl_load_tls_lock) in pthread_create that is not taken
around ctors in dlopen.

The new lock is also used in __tls_get_addr instead of GL(dl_load_lock).

The new lock is held in _dl_open_worker and _dl_close_worker around
most of the logic before/after the init/fini routines.  When init/fini
routines are running then TLS is in a consistent, usable state.
In _dl_open_worker the new lock requires catching and reraising dlopen
failures that happen in the critical section.

The new lock is reinitialized in a fork child, to keep the existing
behaviour and it is kept recursive in case malloc interposition or TLS
access from signal handlers can retake it.  It is not obvious if this
is necessary or helps, but avoids changing the preexisting behaviour.

The new lock may be more appropriate for dl_iterate_phdr too than
GL(dl_load_write_lock), since TLS state of an incompletely loaded
module may be accessed.  If the new lock can replace the old one,
that can be a separate change.

Fixes bug 28357.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2021-10-04 15:07:05 +01:00
..
net
netinet
nfs
sys
Makefile
_G_config.h
_itoa.h
a.out.h
abort-instr.h
adaptive_spin_count.h
aio_misc.h
allocalim.h
arch-fd_to_filename.h
asm-syntax.h
atomic-machine.h
c++-types.data
confstr.h
crti.S
crtn.S
device-nrs.h
dirstream.h
dl-auxv.h
dl-cache.h
dl-dtprocnum.h
dl-dtv.h
dl-fcntl.h
dl-fileid.h
dl-fptr.h
dl-hash.h
dl-hwcap-check.h
dl-irel.h
dl-isa-level.h
dl-librecon.h
dl-lookupcfg.h
dl-machine.h
dl-mman.h
dl-osinfo.h
dl-procinfo.c
dl-procinfo.h
dl-procruntime.c
dl-prop.h
dl-relocate-ld.h
dl-sysdep.h
dl-tls.h
dl-unistd.h
dl-vdso-setup.c
dl-vdso-setup.h
dl-vdso.h
dwarf2.h
elf-initfini.h
elf-read-prop.h
elf_machine_sym_no_match.h
elide.h
eloop-threshold.h
entry.h
errqueue.h
fd_to_filename.h
features-time64.h
fenv_private.h
fips-private.h
fix-fp-int-compare-invalid.h
fix-fp-int-convert-overflow.h
fix-int-fp-convert-zero.h
float128-abi.h
fork.h
fpu_control.h
framestate.c
gcc-compat.h
gccframe.h
get-rounding-mode.h
gmp-mparam.h
hp-timing-common.h
hp-timing.h
ifreq.h
ifunc-init.h
ifunc-sel.h
internal-signals.h
intr-msg.h
ld.abilist
ldbl-classify-compat.h
ldconfig.h
ldsodefs.h
libBrokenLocale.abilist
libanl.abilist
libc-lock.h
libc-mmap.h
libc-mtag.h
libc-start.h
libc-symver.h
libc-tsd.h
libc.abilist
libc_malloc_debug.abilist
libc_start_call_main.h
libcrypt.abilist
libdl.abilist
libm-alias-double.h
libm-alias-float.h
libm-alias-float128.h
libm-alias-ldouble.h
libm-test-ulps
libm-test-ulps-name
libm.abilist
libnsl.abilist
libnss_compat.abilist
libnss_db.abilist
libnss_dns.abilist
libnss_files.abilist
libnss_hesiod.abilist
libnss_nis.abilist
libnss_nisplus.abilist
libpthread.abilist
libresolv.abilist
librt.abilist
libutil.abilist
link_map.h
linkmap.h
local-setxid.h
localplt.data
machine-gmon.h
machine-lock.h
machine-sp.h
malloc-alignment.h
malloc-machine.h
malloc-size.h
malloc-sysdep.h
math-barriers.h
math-nan-payload-double.h
math-nan-payload-float.h
math-narrow-alias-float128.h
math-narrow-alias.h
math-tests-arch.h
math-tests-exceptions.h
math-tests-rounding.h
math-tests-snan-cast.h
math-tests-snan-payload.h
math-tests-snan.h
math-tests-trap-force.h
math-tests-trap.h
math-tests.h
math-type-macros-double.h
math-type-macros-float.h
math-type-macros-float128.h
math-type-macros-ldouble.h
math-type-macros.h
math-use-builtins-ceil.h
math-use-builtins-copysign.h
math-use-builtins-floor.h
math-use-builtins-fma.h
math-use-builtins-nearbyint.h
math-use-builtins-rint.h
math-use-builtins-round.h
math-use-builtins-roundeven.h
math-use-builtins-sqrt.h
math-use-builtins-trunc.h
math-use-builtins.h
math_ldbl.h
math_ldbl_opt.h
math_private.h
math_private_calls.h
memcopy.h
memusage.h
mmap_info.h
nan-high-order-bit.h
not-cancel.h
not-errno.h
nscd-types.h
pagecopy.h
paths.h
profil-counter.h
pty-private.h
register-dump.h
rtld-lowlevel.h
rtld_static_init.h
safe-fatal.h
setjmpP.h
sigcontextinfo.h
siglist-compat.c
siglist-compat.h
siglist.h
sigset-cvt-mask.h
sigsetops.h
single-thread.h
spawn_int_def.h
stackguard-macros.h
stackinfo.h
stap-probe-machine.h
startup.h
stdio-lock.h
string_private.h
struct_stat_time64.h
symbol-hacks.h
sysdep-cancel.h
sysdep.h
thread_state.h
time-clockid.h
time64-compat.h
tininess.h
tls-internal-struct.h
tls-internal.c
tls-internal.h
tls-setup.h
tls.h
tst-audit.h
tst-stack-align.h
unsecvars.h
unwind-arch.h
unwind-dw2-fde-glibc.c
unwind-dw2-fde.c
unwind-dw2-fde.h
unwind-dw2.c
unwind-link.h
unwind-pe.c
unwind-pe.h
unwind-resume.c
unwind-resume.h
unwind.h
utmp-equal.h
xstatver.h