glibc/include
Florian Weimer 27a0c6b490 elf: Avoid re-initializing already allocated TLS in dlopen (bug 31717)
The old code used l_init_called as an indicator for whether TLS
initialization was complete.  However, it is possible that
TLS for an object is initialized, written to, and then dlopen
for this object is called again, and l_init_called is not true at
this point.  Previously, this resulted in TLS being initialized
twice, discarding any interim writes (technically introducing a
use-after-free bug even).

This commit introduces an explicit per-object flag, l_tls_in_slotinfo.
It indicates whether _dl_add_to_slotinfo has been called for this
object.  This flag is used to avoid double-initialization of TLS.
In update_tls_slotinfo, the first_static_tls micro-optimization
is removed because preserving the initalization flag for subsequent
use by the second loop for static TLS is a bit complicated, and
another per-object flag does not seem to be worth it.  Furthermore,
the l_init_called flag is dropped from the second loop (for static
TLS initialization) because l_need_tls_init on its own prevents
double-initialization.

The remaining l_init_called usage in resize_scopes and update_scopes
is just an optimization due to the use of scope_has_map, so it is
not changed in this commit.

The isupper check ensures that libc.so.6 is TLS is not reverted.
Such a revert happens if l_need_tls_init is not cleared in
_dl_allocate_tls_init for the main_thread case, now that
l_init_called is not checked anymore in update_tls_slotinfo
in elf/dl-open.c.

Reported-by: Jonathon Anderson <janderson@rice.edu>
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
(cherry picked from commit 5097cd344f)
2024-09-09 21:31:28 +02:00
..
arpa Fix all the remaining misspellings -- BZ 25337 2023-06-02 01:39:48 +00:00
bits Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
gnu Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
net
netinet
programs Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
protocols
rpc
rpcsvc
sys Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
aio.h
aliases.h Move 'aliases' routines from 'inet' into 'nss' 2023-10-24 12:30:59 +02:00
alloc_buffer.h Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
alloca.h
allocate_once.h Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
ar.h
argp-fmtstream.h
argp.h
argz.h
array_length.h Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
assert.h assert: Do not use stderr in libc-internal assert 2022-08-03 11:43:04 +02:00
atomic_wide_counter.h Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
atomic.h Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
byteswap.h
clone_internal.h posix: Add pidfd_spawn and pidfd_spawnp (BZ 30349) 2023-09-05 13:08:59 -03:00
complex.h
cpio.h
ctype.h
des.h
dirent.h
dlfcn.h elf: Remove LD_PROFILE for static binaries 2023-11-21 16:15:42 -03:00
dso_handle.h
elf.h
endian.h
envz.h
err.h
errno.h
error.h Mark various cold functions as __COLD 2023-05-01 19:33:21 +02:00
execinfo.h
fcntl.h
features-time64.h
features.h version.h, include/features.h: Bump version to 2.39 2024-01-31 01:29:11 +01:00
fenv.h
file_change_detection.h Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
filename.h Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
float.h
fmtmsg.h
fnmatch.h
fpu_control.h
fstab.h
fts.h
ftw.h
gconv.h
getopt_int.h
getopt.h
glob.h
gmp.h Apply asm redirection in gmp.h before first use 2022-11-07 10:40:21 -03:00
gnu-versions.h Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
grp-merge.h Remove 'grp' and merge into 'nss' and 'posix' 2023-10-24 12:30:59 +02:00
grp.h Remove 'grp' and merge into 'nss' and 'posix' 2023-10-24 12:30:59 +02:00
gshadow.h Remove 'gshadow' and merge into 'nss' 2023-10-24 12:30:59 +02:00
iconv.h
idx.h Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
ifaddrs.h nscd: Do not rebuild getaddrinfo (bug 30709) 2023-08-11 10:10:16 +02:00
ifreq.h
ifunc-impl-list.h Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
inline-hashtab.h Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
intprops.h Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
inttypes.h
langinfo.h
lastlog.h
libc-diag.h Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
libc-internal.h Define __libc_initial for the static libc 2024-08-19 16:11:14 +02:00
libc-pointer-arith.h Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
libc-symbols.h Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
libgen.h
libintl.h
limits.h Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
link.h elf: Avoid re-initializing already allocated TLS in dlopen (bug 31717) 2024-09-09 21:31:28 +02:00
list_t.h Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
list.h Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
locale.h
loop_unroll.h Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
malloc.h Simplify __malloc_initialized 2021-07-22 18:38:04 +05:30
math-narrow-eval.h Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
math.h Redirect fma calls to __fma in libm 2021-09-15 22:57:35 +00:00
mcheck.h mcheck: Wean away from malloc hooks [BZ #23489] 2021-07-22 18:38:02 +05:30
memory.h
mntent.h
monetary.h
mqueue.h
netdb.h Move 'netgroup' routines from 'inet' into 'nss' 2023-10-24 12:30:59 +02:00
netgroup.h Move 'netgroup' routines from 'inet' into 'nss' 2023-10-24 12:30:59 +02:00
nl_types.h
nss_dns.h Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
nss_files.h Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
nss.h
nsswitch.h
obstack.h
plural-exp.h
poll.h
printf_buffer.h Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
printf.h stdio-common: Convert vfprintf and related functions to buffers 2022-12-19 18:56:54 +01:00
pthread.h
pty.h
pwd.h Remove 'pwd' and merge into 'nss' 2023-10-24 12:30:59 +02:00
random-bits.h Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
re_comp.h
regex.h Fix regex type usage 2023-05-01 09:08:59 -04:00
regexp.h
register-atfork.h Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
resolv.h resolv: Add internal __res_binary_hnok function 2022-08-30 10:02:49 +02:00
rounding-mode.h Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
rtld-malloc.h Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
sched.h
scratch_buffer.h Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
search.h
set-freeres.h Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
setjmp.h chk: Add and fix hidden builtin definitions for *_chk 2023-08-03 22:46:48 +02:00
sgtty.h
shadow.h Remove 'shadow' and merge into 'nss' 2023-10-24 12:30:59 +02:00
shlib-compat.h Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
shm-directory.h Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
signal.h stdio: Remove the usage of $(fno-unit-at-a-time) for siglist.c 2022-05-13 10:54:41 -03:00
spawn.h
stab.h
stackinfo.h Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
stap-probe.h Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
stdbit.h Implement C23 <stdbit.h> 2024-01-03 12:07:14 +00:00
stdc-predef.h Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
stdint.h
stdio_ext.h
stdio.h stdio: Remove __libc_message alloca usage 2023-09-11 16:16:49 +00:00
stdlib.h stdlib: Remove use of mergesort on qsort (BZ 21719) 2023-10-31 14:18:05 -03:00
string.h chk: Add and fix hidden builtin definitions for *_chk 2023-08-03 22:46:48 +02:00
strings.h
struct___timeb64.h
struct___timespec64.h
struct___timeval64.h
stubs-prologue.h
syscall.h
sysexits.h
syslog.h
tar.h
termios.h
tgmath.h
time.h Define in_int32_t_range to check if the 64 bit time_t syscall should be used 2022-11-17 14:35:13 -03:00
ttyent.h
uchar.h
ucontext.h
ulimit.h
unistd_ext.h Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
unistd.h unistd: Avoid PLT entries with _FORTIFY_SOURCE 2023-07-05 16:59:48 +02:00
utime.h
utmp.h
values.h Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
verify.h
wait.h
wchar.h wchar: Avoid PLT entries with _FORTIFY_SOURCE 2023-07-05 16:59:48 +02:00
wctype.h
wordexp.h