]> git.ipfire.org Git - ipfire-2.x.git/blame - src/patches/glibc-2.38/0034-elf-Fix-TLS-modid-reuse-generation-assignment-BZ-290.patch
glibc: Import latest patches from upstream
[ipfire-2.x.git] / src / patches / glibc-2.38 / 0034-elf-Fix-TLS-modid-reuse-generation-assignment-BZ-290.patch
CommitLineData
a61a21ef
MT
1From ccdc4cba07684fe1397e1f5f134a0a827af98c04 Mon Sep 17 00:00:00 2001
2From: Hector Martin <marcan@marcan.st>
3Date: Tue, 28 Nov 2023 15:23:07 +0900
4Subject: [PATCH 34/44] elf: Fix TLS modid reuse generation assignment (BZ
5 29039)
6
7_dl_assign_tls_modid() assigns a slotinfo entry for a new module, but
8does *not* do anything to the generation counter. The first time this
9happens, the generation is zero and map_generation() returns the current
10generation to be used during relocation processing. However, if
11a slotinfo entry is later reused, it will already have a generation
12assigned. If this generation has fallen behind the current global max
13generation, then this causes an obsolete generation to be assigned
14during relocation processing, as map_generation() returns this
15generation if nonzero. _dl_add_to_slotinfo() eventually resets the
16generation, but by then it is too late. This causes DTV updates to be
17skipped, leading to NULL or broken TLS slot pointers and segfaults.
18
19Fix this by resetting the generation to zero in _dl_assign_tls_modid(),
20so it behaves the same as the first time a slot is assigned.
21_dl_add_to_slotinfo() will still assign the correct static generation
22later during module load, but relocation processing will no longer use
23an obsolete generation.
24
25Note that slotinfo entry (aka modid) reuse typically happens after a
26dlclose and only TLS access via dynamic tlsdesc is affected. Because
27tlsdesc is optimized to use the optional part of static TLS, dynamic
28tlsdesc can be avoided by increasing the glibc.rtld.optional_static_tls
29tunable to a large enough value, or by LD_PRELOAD-ing the affected
30modules.
31
32Fixes bug 29039.
33
34Reviewed-by: Szabolcs Nagy <szabolcs.nagy@arm.com>
35(cherry picked from commit 3921c5b40f293c57cb326f58713c924b0662ef59)
36---
37 elf/dl-tls.c | 1 +
38 1 file changed, 1 insertion(+)
39
40diff --git a/elf/dl-tls.c b/elf/dl-tls.c
41index 99b83ca696..1f6f820819 100644
42--- a/elf/dl-tls.c
43+++ b/elf/dl-tls.c
44@@ -154,6 +154,7 @@ _dl_assign_tls_modid (struct link_map *l)
45 {
46 /* Mark the entry as used, so any dependency see it. */
47 atomic_store_relaxed (&runp->slotinfo[result - disp].map, l);
48+ atomic_store_relaxed (&runp->slotinfo[result - disp].gen, 0);
49 break;
50 }
51
52--
532.39.2
54