diff options
Diffstat (limited to 'meta/recipes-core/glibc/glibc/0035-x86_64-Avoid-lazy-relocation-of-tlsdesc-BZ-27137.patch')
-rw-r--r-- | meta/recipes-core/glibc/glibc/0035-x86_64-Avoid-lazy-relocation-of-tlsdesc-BZ-27137.patch | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/meta/recipes-core/glibc/glibc/0035-x86_64-Avoid-lazy-relocation-of-tlsdesc-BZ-27137.patch b/meta/recipes-core/glibc/glibc/0035-x86_64-Avoid-lazy-relocation-of-tlsdesc-BZ-27137.patch new file mode 100644 index 0000000000..899111b118 --- /dev/null +++ b/meta/recipes-core/glibc/glibc/0035-x86_64-Avoid-lazy-relocation-of-tlsdesc-BZ-27137.patch | |||
@@ -0,0 +1,56 @@ | |||
1 | From 8f7e09f4dbdb5c815a18b8285fbc5d5d7bc17d86 Mon Sep 17 00:00:00 2001 | ||
2 | From: Szabolcs Nagy <szabolcs.nagy@arm.com> | ||
3 | Date: Thu, 11 Feb 2021 11:29:23 +0000 | ||
4 | Subject: [PATCH] x86_64: Avoid lazy relocation of tlsdesc [BZ #27137] | ||
5 | |||
6 | Lazy tlsdesc relocation is racy because the static tls optimization and | ||
7 | tlsdesc management operations are done without holding the dlopen lock. | ||
8 | |||
9 | This similar to the commit b7cf203b5c17dd6d9878537d41e0c7cc3d270a67 | ||
10 | for aarch64, but it fixes a different race: bug 27137. | ||
11 | |||
12 | Another issue is that ld auditing ignores DT_BIND_NOW and thus tries to | ||
13 | relocate tlsdesc lazily, but that does not work in a BIND_NOW module | ||
14 | due to missing DT_TLSDESC_PLT. Unconditionally relocating tlsdesc at | ||
15 | load time fixes this bug 27721 too. | ||
16 | --- | ||
17 | sysdeps/x86_64/dl-machine.h | 19 ++++++++++++++----- | ||
18 | 1 file changed, 14 insertions(+), 5 deletions(-) | ||
19 | --- | ||
20 | Upstream-Status: Backport [https://sourceware.org/git/?p=glibc.git;a=patch;h=8f7e09f4dbdb5c815a18b8285fbc5d5d7bc17d86] | ||
21 | Signed-off-by: Akash Hadke <akash.hadke@kpit.com> | ||
22 | Signed-off-by: Akash Hadke <hadkeakash4@gmail.com> | ||
23 | --- | ||
24 | diff --git a/sysdeps/x86_64/dl-machine.h b/sysdeps/x86_64/dl-machine.h | ||
25 | index 103eee6c3f..9a876a371e 100644 | ||
26 | --- a/sysdeps/x86_64/dl-machine.h | ||
27 | +++ b/sysdeps/x86_64/dl-machine.h | ||
28 | @@ -570,12 +570,21 @@ elf_machine_lazy_rel (struct link_map *map, | ||
29 | } | ||
30 | else if (__glibc_likely (r_type == R_X86_64_TLSDESC)) | ||
31 | { | ||
32 | - struct tlsdesc volatile * __attribute__((__unused__)) td = | ||
33 | - (struct tlsdesc volatile *)reloc_addr; | ||
34 | + const Elf_Symndx symndx = ELFW (R_SYM) (reloc->r_info); | ||
35 | + const ElfW (Sym) *symtab = (const void *)D_PTR (map, l_info[DT_SYMTAB]); | ||
36 | + const ElfW (Sym) *sym = &symtab[symndx]; | ||
37 | + const struct r_found_version *version = NULL; | ||
38 | |||
39 | - td->arg = (void*)reloc; | ||
40 | - td->entry = (void*)(D_PTR (map, l_info[ADDRIDX (DT_TLSDESC_PLT)]) | ||
41 | - + map->l_addr); | ||
42 | + if (map->l_info[VERSYMIDX (DT_VERSYM)] != NULL) | ||
43 | + { | ||
44 | + const ElfW (Half) *vernum = | ||
45 | + (const void *)D_PTR (map, l_info[VERSYMIDX (DT_VERSYM)]); | ||
46 | + version = &map->l_versions[vernum[symndx] & 0x7fff]; | ||
47 | + } | ||
48 | + | ||
49 | + /* Always initialize TLS descriptors completely at load time, in | ||
50 | + case static TLS is allocated for it that requires locking. */ | ||
51 | + elf_machine_rela (map, reloc, sym, version, reloc_addr, skip_ifunc); | ||
52 | } | ||
53 | else if (__glibc_unlikely (r_type == R_X86_64_IRELATIVE)) | ||
54 | { | ||
55 | -- | ||
56 | 2.27.0 | ||