glibc/sysdeps
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
..
aarch64 elf: Only process multiple tunable once (BZ 31686) 2024-05-07 14:06:56 -03:00
alpha
arc login: Check default sizes of structs utmp, utmpx, lastlog 2024-05-02 13:20:27 +02:00
arm login: structs utmp, utmpx, lastlog _TIME_BITS independence (bug 30701) 2024-05-02 13:20:27 +02:00
csky login: structs utmp, utmpx, lastlog _TIME_BITS independence (bug 30701) 2024-05-02 13:20:27 +02:00
generic elf: Avoid re-initializing already allocated TLS in dlopen (bug 31717) 2024-09-09 21:31:28 +02:00
gnu
hppa login: Check default sizes of structs utmp, utmpx, lastlog 2024-05-02 13:20:27 +02:00
htl
hurd
i386 math: Fix i386 and m68k exp10 on static build (BZ 31775) 2024-07-02 14:25:56 +02:00
ieee754 math: Provide missing math symbols on libc.a (BZ 31781) 2024-07-02 14:37:44 +02:00
loongarch LoongArch: Fix undefined __memset_aligned reference in ld.so linking. 2024-05-15 09:08:10 +08:00
m68k math: Fix i386 and m68k exp10 on static build (BZ 31775) 2024-07-02 14:25:56 +02:00
mach socket: Use may_alias on sockaddr structs (bug 19622) 2024-05-27 17:25:13 +02:00
microblaze login: structs utmp, utmpx, lastlog _TIME_BITS independence (bug 30701) 2024-05-02 13:20:27 +02:00
mips login: structs utmp, utmpx, lastlog _TIME_BITS independence (bug 30701) 2024-05-02 13:20:27 +02:00
nios2 login: structs utmp, utmpx, lastlog _TIME_BITS independence (bug 30701) 2024-05-02 13:20:27 +02:00
nptl Linux: Make __rseq_size useful for feature detection (bug 31965) 2024-07-16 16:35:29 +02:00
or1k login: Check default sizes of structs utmp, utmpx, lastlog 2024-05-02 13:20:27 +02:00
posix
powerpc login: structs utmp, utmpx, lastlog _TIME_BITS independence (bug 30701) 2024-05-02 13:20:27 +02:00
pthread nptl: Use <support/check.h> facilities in tst-setuid3 2024-08-30 15:28:22 -04:00
riscv login: Check default sizes of structs utmp, utmpx, lastlog 2024-05-02 13:20:27 +02:00
s390 s390x: Fix segfault in wcsncmp [BZ #31934] 2024-07-16 10:25:35 +02:00
sh login: structs utmp, utmpx, lastlog _TIME_BITS independence (bug 30701) 2024-05-02 13:20:27 +02:00
sparc elf: Only process multiple tunable once (BZ 31686) 2024-05-07 14:06:56 -03:00
unix x32/cet: Support shadow stack during startup for Linux 6.10 2024-08-12 10:54:17 -07:00
wordsize-32
wordsize-64
x86 x86: Properly set x86 minimum ISA level [BZ #31883] 2024-06-15 11:13:10 +01:00
x86_64 elf: Support recursive use of dynamic TLS in interposed malloc 2024-09-09 21:15:23 +02:00